Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

composer-code-languages.test.ts

55 lines1.5 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import {
4 CODE_BLOCK_LANGUAGES,
5 codeLanguageLabel,
6 languageOfInfoString,
7 withInfoStringLanguage,
8} from "./composer-code-languages";
9​
10describe("languageOfInfoString", () => {
11 it.each([
12 ["", ""],
13 ["ts", "ts"],
14 [" ts ", "ts"],
15 ["js title=example", "js"],
16 ["typescript ", "typescript"],
17 ])("reads %j as %j", (info, language) => {
18 expect(languageOfInfoString(info)).toBe(language);
19 });
20});
21​
22describe("withInfoStringLanguage", () => {
23 it.each([
24 ["", "ts", "ts"],
25 ["js", "python", "python"],
26 ["js title=example", "ts", "ts title=example"],
27 ["js {1,3}", "ts", "ts {1,3}"],
28 ["js", "", ""],
29 ["js title=example", "", "text title=example"],
30 [" js title=x", "python", " python title=x"],
31 [" js title=x", "", " text title=x"],
32 [" js", "go", " go"],
33 [" ", "go", " go"],
34 ])("sets %j to %j as %j", (info, language, expected) => {
35 expect(withInfoStringLanguage(info, language)).toBe(expected);
36 });
37});
38​
39describe("codeLanguageLabel", () => {
40 it.each([
41 ["", "Plain text"],
42 ["text", "Plain text"],
43 ["cpp", "C++"],
44 ["ts", "TypeScript"],
45 ["arduino", "arduino"],
46 ])("labels %j as %j", (language, label) => {
47 expect(codeLanguageLabel(language)).toBe(label);
48 });
49​
50 it("lists every language once, plain text first", () => {
51 const ids = CODE_BLOCK_LANGUAGES.map((language) => language.id);
52 expect(ids[0]).toBe("");
53 expect(new Set(ids).size).toBe(ids.length);
54 });
55});