feat: initial release of volumen — a file-based Markdown blog engine
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "test_helper"
|
||||
|
||||
class FrontmatterTest < Minitest::Test
|
||||
def test_parse_extracts_metadata_and_body
|
||||
content = <<~POST
|
||||
+++
|
||||
title = "Hello"
|
||||
tags = ["a", "b"]
|
||||
+++
|
||||
|
||||
Body text.
|
||||
POST
|
||||
metadata, body = Volumen::Frontmatter.parse(content)
|
||||
assert_equal "Hello", metadata["title"]
|
||||
assert_equal %w[a b], metadata["tags"]
|
||||
assert_equal "Body text.\n", body
|
||||
end
|
||||
|
||||
def test_parse_without_frontmatter
|
||||
metadata, body = Volumen::Frontmatter.parse("# Just markdown\n")
|
||||
assert_empty metadata
|
||||
assert_equal "# Just markdown\n", body
|
||||
end
|
||||
|
||||
def test_parse_without_closing_delimiter
|
||||
content = "+++\ntitle = \"x\"\n\nbody"
|
||||
metadata, body = Volumen::Frontmatter.parse(content)
|
||||
assert_empty metadata
|
||||
assert_equal content, body
|
||||
end
|
||||
|
||||
def test_round_trip
|
||||
metadata = { "title" => "Hello", "tags" => ["intro"], "draft" => false }
|
||||
dumped = Volumen::Frontmatter.dump(metadata, "Hello **world**.")
|
||||
parsed_meta, parsed_body = Volumen::Frontmatter.parse(dumped)
|
||||
assert_equal metadata, parsed_meta
|
||||
assert_equal "Hello **world**.", parsed_body.strip
|
||||
end
|
||||
|
||||
def test_parse_normalises_crlf
|
||||
metadata, body = Volumen::Frontmatter.parse("+++\r\ntitle = \"x\"\r\n+++\r\n\r\nBody\r\n")
|
||||
assert_equal "x", metadata["title"]
|
||||
assert_equal "Body\n", body
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user