Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-mcp

Model Context Protocol server for Pudu language documentation and compiler tools

0.1.1Apache-2.01

InstallClose

EntryTest.pudu

Pudu54 lines3.6 KB

GitHub ↗
1/** @Test.Domain.Reference.EntryTest.Suite — declaration listing and name search */2module PuduLangMcp.Domain.Reference.EntryTest34import Std.Io as Io5import Std.List as List6import Std.Test as Test7import PuduLangMcp.Domain.Reference.Entry as Entry89/// A declaration for tests.10fn entry(moduleName: Str, kind: Str, name: Str, signature: Str, doc: Str) -> Entry.Entry {11  Entry.Entry{moduleName: moduleName, kind: kind, name: name, signature: signature, doc: doc}12}1314/// The qualified names of the best matches.15fn found(entries: &Array[Entry.Entry], query: Str, limit: Int) -> Array[Str] {16  Entry.search(entries, query, limit).map(|held: Entry.Found| held.entry.moduleName + "." + held.entry.name)17}1819/// Runs the suite.20fn main() -> Int {21  let entries = [22    entry("Std.Result", "fn", "unwrapOr", "Result[T, E] -> T -> T", "The value, or a fallback."),23    entry("Std.Option", "fn", "unwrapOr", "Option[T] -> T -> T", "The value, or a fallback."),24    entry("Std.Option", "fn", "unwrapOrElse", "Option[T] -> fn() -> T -> T", ""),25    entry("Std.Option", "type", "Option", "", "A value that may be absent."),26    entry("Std.Text", "fn", "trimEnd", "Str -> Str", "Text without trailing whitespace."),27    entry("Std.Json", "fn (Json)", "show", "&Json -> Str", "")28  ]29  let checks = Test.suite("Domain.Reference.Entry", &[30      Test.equals("an exact name ranks first, in catalogue order", &found(&entries, "unwrapOr", 2), &["Std.Result.unwrapOr", "Std.Option.unwrapOr"]),31      Test.equals("a qualified name is exact", &found(&entries, "Std.Option.unwrapOr", 1), &["Std.Option.unwrapOr"]),32      Test.equals("a prefix outranks a description", &List.first(&found(&entries, "unwrapOrE", 5)), &Some("Std.Option.unwrapOrElse")),33      Test.equals("search is case-insensitive", &found(&entries, "TRIMEND", 1), &["Std.Text.trimEnd"]),34      Test.equals("a description match is found", &found(&entries, "trailing whitespace", 5), &["Std.Text.trimEnd"]),35      Test.equals("a signature match is found", &found(&entries, "fn() -> T", 5), &["Std.Option.unwrapOrElse"]),36      Test.equals("an empty query finds nothing", &found(&entries, "  ", 5), &[]),37      Test.equals("a zero limit finds nothing", &found(&entries, "unwrapOr", 0), &[]),38      Test.equals("a better match later in the catalogue ranks first", &found(&[entries[4], entries[0]], "unwrapOr", 2), &["Std.Result.unwrapOr"]),39      Test.equals("a stronger rule outranks catalogue order", &found(&[entry("A", "fn", "zzfoo", "", ""), entry("B", "fn", "foo", "", "")], "foo", 2), &["B.foo", "A.zzfoo"]),40      Test.equals("modules are listed once, sorted", &Entry.modules(&entries), &["Std.Json", "Std.Option", "Std.Result", "Std.Text"]),41      Test.equals("a module's entries keep catalogue order", &Entry.ofModule(&entries, "Std.Option").map(|held: Entry.Entry| held.name), &["unwrapOr", "unwrapOrElse", "Option"]),42      Test.equals("an unknown module renders nothing", &Entry.renderModule(&entries, "Std.Nope"), &""),43      Test.that("a module rendering counts its declarations", Entry.renderModule(&entries, "Std.Option").startsWith("module Std.Option — 3 public declarations")),44      Test.equals("a declaration renders its signature and documentation", &Entry.render(&entries[4]), &"fn Std.Text.trimEnd :: Str -> Str\n    Text without trailing whitespace."),45      Test.equals("a type without signature renders its name", &Entry.render(&entries[3]), &"type Std.Option.Option\n    A value that may be absent."),46      Test.that("a method of a type counts as a function", Entry.search(&entries, "show", 1)[0].score > 100)47    ])48  let ran = Test.run(&checks)49  for failure in Test.failuresOf(&ran) {50    let _reported = Io.writeErrorLine(failure)51  }52  Test.report(&ran)53}54