Sync local packages into the registry repo and update index.json and README.md to include all 9 packages.
91 lines
3.9 KiB
Plaintext
91 lines
3.9 KiB
Plaintext
import lib
|
|
|
|
fn test_basic_parsing(): Unit with {Test} = {
|
|
let doc = lib.parse("---\ntitle: Hello World\ndate: 2025-01-29\n---\nBody here.")
|
|
Test.assertEqualMsg("Hello World", lib.title(doc), "basic title")
|
|
Test.assertEqualMsg("2025-01-29", lib.date(doc), "basic date")
|
|
Test.assert(String.startsWith(lib.body(doc), "Body here."), "body starts with expected")
|
|
}
|
|
|
|
fn test_quoted_values(): Unit with {Test} = {
|
|
let doc = lib.parse("---\ntitle: \"Quoted Title\"\n---\nBody")
|
|
Test.assertEqualMsg("Quoted Title", lib.title(doc), "double-quoted values")
|
|
let doc2 = lib.parse("---\ntitle: 'Single Quoted'\n---\nBody")
|
|
Test.assertEqualMsg("Single Quoted", lib.title(doc2), "single-quoted values")
|
|
}
|
|
|
|
fn test_tags(): Unit with {Test} = {
|
|
let doc = lib.parse("---\ntags: web blog lux\n---\nBody")
|
|
let tagList = lib.tags(doc)
|
|
Test.assertEqualMsg(3, List.length(tagList), "tag count")
|
|
let doc2 = lib.parse("---\ntitle: No Tags\n---\nBody")
|
|
Test.assertEqualMsg(0, List.length(lib.tags(doc2)), "empty tags")
|
|
let singleTags = lib.parseTags("solo")
|
|
Test.assertEqualMsg(1, List.length(singleTags), "parseTags single")
|
|
let noTags = lib.parseTags("")
|
|
Test.assertEqualMsg(0, List.length(noTags), "parseTags empty")
|
|
}
|
|
|
|
fn test_description(): Unit with {Test} = {
|
|
let doc = lib.parse("---\ndescription: A great post about things\n---\nBody")
|
|
Test.assertEqualMsg("A great post about things", lib.description(doc), "description field")
|
|
}
|
|
|
|
fn test_no_frontmatter(): Unit with {Test} = {
|
|
let doc = lib.parse("Just some text\nwith no frontmatter")
|
|
Test.assertEqualMsg(false, lib.hasFrontmatter(doc), "no frontmatter flag")
|
|
Test.assertEqualMsg("", lib.title(doc), "no frontmatter title")
|
|
}
|
|
|
|
fn test_get(): Unit with {Test} = {
|
|
let doc = lib.parse("---\nauthor: Brandon\nlicense: MIT\n---\nBody")
|
|
Test.assertEqualMsg("Brandon", lib.getOrDefault(doc, "author", ""), "get author")
|
|
Test.assertEqualMsg("MIT", lib.getOrDefault(doc, "license", ""), "get license")
|
|
Test.assert(match lib.get(doc, "missing") { Some(_) => false, None => true }, "get missing returns None")
|
|
}
|
|
|
|
fn test_get_or_default(): Unit with {Test} = {
|
|
let doc = lib.parse("---\ntitle: Present\n---\nBody")
|
|
Test.assertEqualMsg("Present", lib.getOrDefault(doc, "title", "default"), "getOrDefault present")
|
|
Test.assertEqualMsg("fallback", lib.getOrDefault(doc, "missing", "fallback"), "getOrDefault missing")
|
|
}
|
|
|
|
fn test_multiline_body(): Unit with {Test} = {
|
|
let doc = lib.parse("---\ntitle: Post\n---\nLine 1\nLine 2\nLine 3")
|
|
Test.assert(String.startsWith(lib.body(doc), "Line 1\n"), "multiline body starts correctly")
|
|
}
|
|
|
|
fn test_empty_value(): Unit with {Test} = {
|
|
let doc = lib.parse("---\ntitle:\n---\nBody")
|
|
Test.assertEqualMsg("", lib.title(doc), "empty value key")
|
|
}
|
|
|
|
fn test_entries(): Unit with {Test} = {
|
|
let doc = lib.parse("---\ntitle: T\ndate: D\ndescription: Desc\ntags: a b\n---\nBody")
|
|
Test.assertEqualMsg(4, List.length(lib.entries(doc)), "four entries")
|
|
}
|
|
|
|
fn test_entry_accessors(): Unit with {Test} = {
|
|
let doc = lib.parse("---\nfoo: bar\n---\nBody")
|
|
let es = lib.entries(doc)
|
|
match List.head(es) {
|
|
Some(e) => {
|
|
Test.assertEqualMsg("foo", lib.entryKey(e), "entry key")
|
|
Test.assertEqualMsg("bar", lib.entryValue(e), "entry value")
|
|
},
|
|
None => Test.assert(false, "should have entry"),
|
|
}
|
|
}
|
|
|
|
fn test_has_frontmatter(): Unit with {Test} = {
|
|
let docWith = lib.parse("---\ntitle: Yes\n---\nBody")
|
|
let docWithout = lib.parse("No frontmatter here")
|
|
Test.assertEqualMsg(true, lib.hasFrontmatter(docWith), "has frontmatter true")
|
|
Test.assertEqualMsg(false, lib.hasFrontmatter(docWithout), "has frontmatter false")
|
|
}
|
|
|
|
fn test_value_with_colon(): Unit with {Test} = {
|
|
let doc = lib.parse("---\ntitle: Hello: World\n---\nBody")
|
|
Test.assertEqualMsg("Hello: World", lib.title(doc), "value with colon")
|
|
}
|