Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-mcp

Model Context Protocol server for Pudu language documentation and compiler tools

0.1.2Apache-2.01

InstallClose

DerivesTest.pudu

Pudu30 lines2.3 KB

GitHub ↗
1/** @Test.Domain.Reference.DerivesTest.Suite — derive strategies read from source */2module PuduLangMcp.Domain.Reference.DerivesTest34import Std.Io as Io5import Std.Test as Test6import PuduLangMcp.Domain.Reference.Derives as Derives7import PuduLangMcp.Domain.Reference.Entry as Entry89/// A module publishing two strategies, one private one, and a commented-out one.10const SOURCE: Str = "module Std.Show\n\n/// A type that renders itself.\nexport trait Show \{\n  fn show(self: &Self) -> Str\n\}\n\n/// A record rendered as its name\n/// and its fields.\nexport derive Show for T: Record \{\n  fn show(self: &T) -> Str \{ \"\" \}\n\}\n\nexport derive Show for T: Sum \{\n  fn show(self: &T) -> Str \{ \"\" \}\n\}\n\n/// Not published.\nderive Hidden for T: Record \{\n\}\n\n// export derive Gone for T: Record \{\n/// Kept apart.\n\nexport derive Ord for T: Record\n"1112/// Runs the suite.13fn main() -> Int {14  let found = Derives.strategiesOf("Std.Show", SOURCE)15  let checks = Test.suite("Domain.Reference.Derives", &[16      Test.equals("every published strategy is found, in order", &found.map(|held: Entry.Entry| held.signature), &["derive Show for T: Record", "derive Show for T: Sum", "derive Ord for T: Record"]),17      Test.equals("a strategy is listed by its trait and module", &found.map(|held: Entry.Entry| held.moduleName + " " + held.kind + " " + held.name), &["Std.Show derive Show", "Std.Show derive Show", "Std.Show derive Ord"]),18      Test.equals("the doc comment directly above is kept", &found.map(|held: Entry.Entry| held.doc), &["A record rendered as its name\nand its fields.", "", ""]),19      Test.equals("a doc comment separated by other lines is not taken", &Derives.strategiesOf("M", "/// Stale.\nexport fn f() -> Int \{ 1 \}\nexport derive Eq for T: Record \{\n\}").map(|held: Entry.Entry| held.doc), &[""]),20      Test.equals("a doc comment line without a space keeps its text", &Derives.strategiesOf("M", "///Tight.\nexport derive Eq for T: Record \{\n\}").map(|held: Entry.Entry| held.doc), &["Tight."]),21      Test.equals("an indented derive line is not a published strategy", &Derives.strategiesOf("M", "  export derive Eq for T: Record \{").length(), &0),22      Test.equals("a module without strategies has none", &Derives.strategiesOf("M", "module M\n").length(), &0)23    ])24  let ran = Test.run(&checks)25  for failure in Test.failuresOf(&ran) {26    let _reported = Io.writeErrorLine(failure)27  }28  Test.report(&ran)29}30