
LanguagesTest.pudu
Pudu28 lines2.3 KB
1/** @Docgen.Languages.Tests — language and emoji tables answer published identities */2module PuduLangDocgen.LanguagesTest34import Std.Io as Io5import Std.Test as Test6import PuduLangDocgen.Markdown.Emoji as Emoji7import PuduLangDocgen.Markdown.Highlight as Highlight8import PuduLangDocgen.Markdown.Languages as Languages91011fn main() -> Int {12 let checks = Test.suite("Languages", &[13 Test.equals("aliases identify languages", &["js", "JavaScript", "py", "sh", "C++", "pudu", "unknown-lang"].map(|name: Str| Languages.identify(name)), &["javascript", "javascript", "python", "shell", "c++", "pudu", "unknown-lang"]),14 Test.equals("extensions identify files", &["src/a.pudu", "a.RS", "b.tsx", "c.yml", "no-extension", "x.unknownext"].map(|path: Str| Languages.ofPath(path)), &["pudu", "rust", "tsx", "yaml", "", ""]),15 Test.equals("exact file names win", &[Languages.ofPath("deploy/Dockerfile"), Languages.ofPath("Makefile")], &["dockerfile", "makefile"]),16 Test.equals("display names", &[Languages.title("javascript"), Languages.title("pudu"), Languages.title("c++"), Languages.title("none")], &["JavaScript", "Pudu", "C++", "none"]),17 Test.equals("shared profiles highlight", &Highlight.lines("tsx", "const a"), &["<span class=\"hl-k\">const</span> a"]),18 Test.equals("unknown language escapes only", &Highlight.lines("brainfreeze", "<a>\nb"), &["<a>", "b"]),19 Test.equals("block comment spans lines", &Highlight.lines("c", "/* a\nb */ x"), &["<span class=\"hl-c\">/* a</span>", "<span class=\"hl-c\">b */</span> x"]),20 Test.equals("hash comment needs a word boundary", &Highlight.lines("shell", "echo a#b # c"), &["<span class=\"hl-k\">echo</span> a#b <span class=\"hl-c\"># c</span>"]),21 Test.equals("strings and literals", &Highlight.lines("json", "\{\"a\": true\}"), &["\{<span class=\"hl-s\">"a"</span>: <span class=\"hl-l\">true</span>\}"]),22 Test.equals("emoji names and aliases", &[Emoji.lookup("grinning_face"), Emoji.lookup("smile"), Emoji.lookup("flag_united_states"), Emoji.lookup("nope")], &[Some("😀"), Some("😄"), Some("🇺🇸"), None])23 ])24 let ran = Test.run(&checks)25 for failure in Test.failuresOf(&ran) { let _printed = Io.writeErrorLine(failure) }26 Test.report(&ran)27}28