Open History to see the last commit
1import { expect, it } from "vite-plus/test";
2
3import {
4 CODE_BLOCK_LANGUAGES,
5 codeLanguageEntry,
6 filterCodeLanguages,
7 languageOfInfoString,
8} from "./composer-code-languages";
9
10it("recognizes plain-text fence info strings without treating metadata as the language", () => {
11 const entries = ["Text", "TEXT", "plaintext", "txt"].map((language) =>
12 codeLanguageEntry(languageOfInfoString(` ${language} title=notes.txt`)),
13 );
14
15 expect(entries).toEqual(Array.from({ length: 4 }, () => ({ id: "", label: "Plain text" })));
16});
17
18it("resolves hardware description language fences to their picker entries", () => {
19 expect(
20 ["verilog", "sv", "System-Verilog", "vhdl"].map((language) => codeLanguageEntry(language)?.id),
21 ).toEqual(["verilog", "systemverilog", "systemverilog", "vhdl"]);
22});
23
24it("ranks the language an alias names first when filtering the picker", () => {
25 const firstIds = ["ts", "yml", "TXT"].map(
26 (query) => filterCodeLanguages(CODE_BLOCK_LANGUAGES, query)[0]?.id,
27 );
28
29 expect(firstIds).toEqual(["typescript", "yaml", ""]);
30});
31
32it("does not treat Object.prototype keys as language aliases", () => {
33 expect(codeLanguageEntry("constructor")).toBeNull();
34 expect(filterCodeLanguages(CODE_BLOCK_LANGUAGES, "__proto__")).toEqual([]);
35});