Close TD-16 frontmatter robustness
This commit is contained in:
30
test/bds/frontmatter_test.exs
Normal file
30
test/bds/frontmatter_test.exs
Normal file
@@ -0,0 +1,30 @@
|
||||
defmodule BDS.FrontmatterTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
test "parse_document accepts CRLF frontmatter documents" do
|
||||
contents = "---\r\ntitle: Hello\r\ntags:\r\n - elixir\r\n---\r\nBody\r\n"
|
||||
|
||||
assert {:ok, %{fields: fields, body: body}} = BDS.Frontmatter.parse_document(contents)
|
||||
assert fields["title"] == "Hello"
|
||||
assert fields["tags"] == ["elixir"]
|
||||
assert body == "Body"
|
||||
end
|
||||
|
||||
test "serialize_document roundtrips quoted strings with embedded quotes and escapes" do
|
||||
fields = [
|
||||
{"title", "He said \"hi\" \\\\ there"},
|
||||
{"summary", "Ends with a quote\""},
|
||||
{"excerpt", "first line\nsecond line"}
|
||||
]
|
||||
|
||||
contents = BDS.Frontmatter.serialize_document(fields, "Body")
|
||||
|
||||
assert {:ok, %{fields: parsed_fields, body: body}} =
|
||||
BDS.Frontmatter.parse_document(contents)
|
||||
|
||||
assert parsed_fields["title"] == "He said \"hi\" \\\\ there"
|
||||
assert parsed_fields["summary"] == "Ends with a quote\""
|
||||
assert parsed_fields["excerpt"] == "first line\nsecond line"
|
||||
assert body == "Body"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user