
SourceFileTest.pudu
Pudu35 lines2.4 KB
1/** @Test.Domain.Code.SourceFileTest.Suite — module names and their paths */2module PuduLangMcp.Domain.Code.SourceFileTest34import Std.Io as Io5import Std.Test as Test6import PuduLangMcp.Domain.Code.SourceFile as SourceFile789fn main() -> Int {10 let checks = Test.suite("Domain.Code.SourceFile", &[11 Test.equals("a module declaration is read", &SourceFile.moduleNameOf("module App.Greeting\n\nfn f() -> Int { 1 }"), &Some("App.Greeting")),12 Test.equals("comments before the declaration are skipped", &SourceFile.moduleNameOf("// note\n/** @A.B.C — header */\n\nmodule Main"), &Some("Main")),13 Test.equals("code before any declaration means none", &SourceFile.moduleNameOf("fn main() -> Int { 0 }\nmodule Main"), &None),14 Test.equals("empty source declares nothing", &SourceFile.moduleNameOf(""), &None),15 Test.equals("an invalid name is not a declaration", &SourceFile.moduleNameOf("module ../../etc"), &None),16 Test.equals("a module's file follows its dots", &SourceFile.fileOf("App.Greeting"), &"App/Greeting.pudu"),17 Test.equals("a file's module follows its slashes", &SourceFile.moduleOfFile("Std/Http/Server.pudu"), &Some("Std.Http.Server")),18 Test.equals("a non-Pudu file is no module", &SourceFile.moduleOfFile("README.md"), &None),19 Test.equals("a path with a dot segment is no module", &SourceFile.moduleOfFile("../Std/Io.pudu"), &None),20 Test.that("underscores and digits are allowed after the first letter", SourceFile.isModuleName("Http2.Server_v1")),21 Test.not("a segment may not start with a digit", SourceFile.isModuleName("2fa.Codes")),22 Test.not("an empty segment is refused", SourceFile.isModuleName("A..B")),23 Test.not("an empty name is refused", SourceFile.isModuleName("")),24 Test.equals("an unterminated block comment is not a comment", &SourceFile.moduleNameOf("/* note\nmodule Main"), &None),25 Test.that("the letters and digits at each end of their ranges are accepted", SourceFile.isModuleName("Az.Za.a09.z9_")),26 Test.all("the characters beside those ranges are refused", &["A@", "A[", "A`", "A\{", "A/", "A:", "@A", "[A", "`A", "\{A"], |name: Str| !SourceFile.isModuleName(name)),27 Test.all("a segment may not start with any digit", &["0a", "9a"], |name: Str| !SourceFile.isModuleName(name))28 ])29 let ran = Test.run(&checks)30 for failure in Test.failuresOf(&ran) {31 let _reported = Io.writeErrorLine(failure)32 }33 Test.report(&ran)34}35