diff options
Diffstat (limited to 'spec/test_frontmatter.lua')
| -rw-r--r-- | spec/test_frontmatter.lua | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/spec/test_frontmatter.lua b/spec/test_frontmatter.lua index 3f0c4c5..f729254 100644 --- a/spec/test_frontmatter.lua +++ b/spec/test_frontmatter.lua @@ -2,18 +2,18 @@ -- -- The body is the part a broken header must never cost the user, so every -- degraded case is checked for "body preserved verbatim" as well as for the --- warning. Cases that actually parse YAML need lyaml and skip without it. +-- warning. Cases that actually parse YAML need tinyyaml and skip without it. local frontmatter = require("subagents.frontmatter") -local function lyaml_or_skip() - return pcall(require, "lyaml") +local function yaml_or_skip() + return pcall(require, "tinyyaml") end return { { "fenced header parses and keeps the body verbatim", function() - if not lyaml_or_skip() then - return "skip", "lyaml is not installed" + if not yaml_or_skip() then + return "skip", "tinyyaml is not installed" end local body = "You are a reviewer.\n\n indented line \n" local data, parsed_body, warning = frontmatter.parse( @@ -27,8 +27,8 @@ return { end }, { "CRLF fences are tolerated", function() - if not lyaml_or_skip() then - return "skip", "lyaml is not installed" + if not yaml_or_skip() then + return "skip", "tinyyaml is not installed" end local data, body, warning = frontmatter.parse("---\r\nname: crlf\r\n---\r\nbody\r\n") assert(warning == nil, tostring(warning)) @@ -59,26 +59,32 @@ return { assert(warning == nil, tostring(warning)) end }, - { "broken YAML warns and keeps the body", function() - if not lyaml_or_skip() then - return "skip", "lyaml is not installed" + { "a header the parser rejects warns and keeps the body", function() + if not yaml_or_skip() then + return "skip", "tinyyaml is not installed" end - local data, body, warning = frontmatter.parse("---\na: [unclosed\n---\nbody\n") - assert(data == nil, "a broken header must not produce metadata") + local data, body, warning = frontmatter.parse("---\njust a string\n---\nbody\n") + assert(data == nil, "a rejected header must not produce metadata") assert(body == "body\n", string.format("%q", body)) assert(type(warning) == "string" and warning:find("did not parse", 1, true), "expected a parse warning, got " .. tostring(warning)) end }, - { "a non-mapping document warns and keeps the body", function() - if not lyaml_or_skip() then - return "skip", "lyaml is not installed" + { "an unresolved alias is dropped rather than read literally", function() + if not yaml_or_skip() then + return "skip", "tinyyaml is not installed" end - local data, body, warning = frontmatter.parse("---\njust a string\n---\nbody\n") - assert(data == nil, "a scalar header must not produce metadata") + -- tinyyaml does not resolve aliases: without the guard in parse(), the + -- `*d` token would arrive as the literal string "*d" and become this + -- profile's name. + local data, body, warning = frontmatter.parse( + "---\ndefs: &d my-agent\nname: *d\n---\nbody\n") + assert(type(data) == "table", "the mapping itself should survive") + assert(data.name == nil, "an alias must not become a value, got " .. tostring(data.name)) + assert(data.defs == nil, "an anchor must not become a value, got " .. tostring(data.defs)) assert(body == "body\n", string.format("%q", body)) - assert(type(warning) == "string" and warning:find("not a mapping", 1, true), - "expected a mapping warning, got " .. tostring(warning)) + assert(type(warning) == "string" and warning:find("anchors/aliases", 1, true), + "expected an alias warning, got " .. tostring(warning)) end }, { "empty input is empty output", function() |
