import lib // --- parse edge cases --- fn test_parse_empty_string(): Unit with {Test} = { let doc = lib.parse("") Test.assertEqualMsg(false, lib.hasFrontmatter(doc), "empty string has no frontmatter") Test.assertEqualMsg("", lib.body(doc), "empty string has empty body") } fn test_parse_only_body(): Unit with {Test} = { let doc = lib.parse("Just text\nwith lines") Test.assertEqualMsg(false, lib.hasFrontmatter(doc), "plain text has no frontmatter") } fn test_parse_only_frontmatter(): Unit with {Test} = { let doc = lib.parse("---\ntitle: Hello\n---") Test.assertEqualMsg(true, lib.hasFrontmatter(doc), "has frontmatter") Test.assertEqualMsg("Hello", lib.title(doc), "title extracted") Test.assertEqualMsg("", lib.body(doc), "no body") } fn test_parse_empty_frontmatter(): Unit with {Test} = { let doc = lib.parse("---\n---\nBody here") Test.assertEqualMsg(false, lib.hasFrontmatter(doc), "empty frontmatter has no entries") Test.assert(String.startsWith(lib.body(doc), "Body here"), "body after empty frontmatter") } fn test_parse_unclosed_frontmatter(): Unit with {Test} = { // Parser treats opening --- as starting frontmatter; entries are parsed even without closing --- let doc = lib.parse("---\ntitle: Test\nNo closing marker") Test.assertEqualMsg(true, lib.hasFrontmatter(doc), "unclosed frontmatter still parses entries") Test.assertEqualMsg("Test", lib.title(doc), "unclosed frontmatter title still extracted") } // --- value formats --- fn test_parse_double_quoted(): Unit with {Test} = { let doc = lib.parse("---\ntitle: \"Hello World\"\n---\n") Test.assertEqualMsg("Hello World", lib.title(doc), "double-quoted value") } fn test_parse_single_quoted(): Unit with {Test} = { let doc = lib.parse("---\ntitle: 'Hello World'\n---\n") Test.assertEqualMsg("Hello World", lib.title(doc), "single-quoted value") } fn test_parse_value_with_colon(): Unit with {Test} = { let doc = lib.parse("---\ntitle: Hello: World: Again\n---\n") Test.assertEqualMsg("Hello: World: Again", lib.title(doc), "value with multiple colons") } fn test_parse_value_empty(): Unit with {Test} = { let doc = lib.parse("---\ntitle:\n---\n") Test.assertEqualMsg("", lib.title(doc), "empty value after colon") } fn test_parse_value_with_special_chars(): Unit with {Test} = { let doc = lib.parse("---\ntitle: Hello & \"friends\"\n---\n") Test.assertEqualMsg("Hello & \"friends\"", lib.title(doc), "value with HTML special chars") } // --- get / getOrDefault edge cases --- fn test_get_missing_key(): Unit with {Test} = { let doc = lib.parse("---\ntitle: Hello\n---\n") Test.assert(match lib.get(doc, "nonexistent") { Some(_) => false, None => true }, "missing key returns None") } fn test_get_first_match(): Unit with {Test} = { let doc = lib.parse("---\ntitle: First\ntitle: Second\n---\n") Test.assertEqualMsg("First", lib.getOrDefault(doc, "title", ""), "get returns first matching key") } fn test_get_or_default_present(): Unit with {Test} = { let doc = lib.parse("---\nkey: value\n---\n") Test.assertEqualMsg("value", lib.getOrDefault(doc, "key", "fallback"), "getOrDefault returns value when present") } fn test_get_or_default_missing(): Unit with {Test} = { let doc = lib.parse("---\nkey: value\n---\n") Test.assertEqualMsg("fallback", lib.getOrDefault(doc, "other", "fallback"), "getOrDefault returns default when missing") } // --- parseTags edge cases --- fn test_parse_tags_single(): Unit with {Test} = Test.assertEqualMsg(1, List.length(lib.parseTags("solo")), "single tag") fn test_parse_tags_multiple(): Unit with {Test} = Test.assertEqualMsg(3, List.length(lib.parseTags("a b c")), "three tags") fn test_parse_tags_empty(): Unit with {Test} = Test.assertEqualMsg(0, List.length(lib.parseTags("")), "empty tags") // --- entries / entryKey / entryValue --- fn test_entries_count(): Unit with {Test} = { let doc = lib.parse("---\na: 1\nb: 2\nc: 3\n---\n") Test.assertEqualMsg(3, List.length(lib.entries(doc)), "three entries") } fn test_entry_accessors(): Unit with {Test} = { let doc = lib.parse("---\nfoo: bar\n---\n") match List.head(lib.entries(doc)) { Some(e) => { Test.assertEqualMsg("foo", lib.entryKey(e), "entry key") Test.assertEqualMsg("bar", lib.entryValue(e), "entry value") }, None => Test.assert(false, "should have at least one entry"), } } // --- body edge cases --- fn test_body_multiline(): Unit with {Test} = { let doc = lib.parse("---\ntitle: T\n---\nLine 1\nLine 2\nLine 3") let b = lib.body(doc) Test.assert(String.startsWith(b, "Line 1\n"), "multiline body starts correctly") Test.assert(String.contains(b, "Line 2"), "multiline body contains middle line") } fn test_body_preserves_blank_lines(): Unit with {Test} = { let doc = lib.parse("---\ntitle: T\n---\nPara 1\n\nPara 2") Test.assert(String.contains(lib.body(doc), "\n\n"), "body preserves blank lines") }