2024-05-21 16:52:37 +00:00
|
|
|
defmodule JOL.Blog.ParserTest do
|
2024-05-21 16:43:36 +00:00
|
|
|
use ExUnit.Case, async: true
|
2024-05-21 16:52:37 +00:00
|
|
|
alias JOL.Blog.Parser
|
2024-05-21 16:43:36 +00:00
|
|
|
|
2024-05-21 16:46:48 +00:00
|
|
|
setup do
|
2024-05-21 16:43:36 +00:00
|
|
|
content = """
|
|
|
|
+++
|
|
|
|
title = "test post"
|
|
|
|
draft = false
|
|
|
|
date = 2024-01-02 14:00:00-05:00
|
|
|
|
|
|
|
|
[taxonomies]
|
|
|
|
tags = ["howto", "hardware"]
|
|
|
|
+++
|
|
|
|
|
|
|
|
Body!
|
|
|
|
"""
|
|
|
|
|
2024-05-23 20:46:03 +00:00
|
|
|
{attrs, body} = Parser.parse("/filename/doesnt/matter", content)
|
|
|
|
|
|
|
|
{:ok, content: content, attrs: attrs, body: body}
|
2024-05-21 16:46:48 +00:00
|
|
|
end
|
|
|
|
|
2024-05-23 19:26:58 +00:00
|
|
|
test "parses the body from zola-style posts", post do
|
2024-05-23 20:46:03 +00:00
|
|
|
assert post.body == "Body!"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "parses the title from zola-style posts", post do
|
|
|
|
assert post.attrs.title == "test post"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "parses the tags from zola-style posts", post do
|
|
|
|
assert post.attrs.tags == ["howto", "hardware"]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "parses the draft status from zola-style posts", post do
|
|
|
|
assert post.attrs.draft == false
|
2024-05-21 16:43:36 +00:00
|
|
|
end
|
2024-05-23 20:01:11 +00:00
|
|
|
|
2024-05-23 20:48:53 +00:00
|
|
|
test "parses the publish date from zola-style posts", post do
|
|
|
|
{:ok, known_date, _} = DateTime.from_iso8601("2024-01-02 14:00:00-05:00")
|
|
|
|
assert Date.compare(known_date, post.attrs.date) == :eq
|
2024-05-23 20:01:11 +00:00
|
|
|
end
|
2024-05-21 16:43:36 +00:00
|
|
|
end
|