gemini-ex/test/gemini_test.exs

58 lines
1.7 KiB
Elixir

defmodule GeminiTest do
use ExUnit.Case
doctest Gemini
test "parse text lines" do
assert Gemini.parse("test") == [{:text, "test"}]
end
test "parse link lines" do
assert Gemini.parse("=>gemini://example.com") == [
{:link, URI.parse("gemini://example.com"), nil}
]
assert Gemini.parse("=> \t gemini://example.com") == [
{:link, URI.parse("gemini://example.com"), nil}
]
assert Gemini.parse("=>gemini://example.com some text") == [
{:link, URI.parse("gemini://example.com"), "some text"}
]
assert Gemini.parse("=> \t gemini://example.com \t\t\tother text") == [
{:link, URI.parse("gemini://example.com"), "other text"}
]
end
test "parse preformatted block" do
assert Gemini.parse("```foo\nbar\n```") == [
{:preformatting_start, "foo"},
{:preformatted, "bar"},
:preformatting_end
]
assert Gemini.parse("```foo\nbar\n```baz") == [
{:preformatting_start, "foo"},
{:preformatted, "bar"},
:preformatting_end
]
end
test "parse headings" do
assert Gemini.parse("#one") == [{:heading, "one", 1}]
assert Gemini.parse("# one") == [{:heading, "one", 1}]
assert Gemini.parse("## two") == [{:heading, "two", 2}]
assert Gemini.parse("### three") == [{:heading, "three", 3}]
end
test "parse list items" do
assert Gemini.parse("* one") == [{:list_item, "one"}]
assert Gemini.parse("*one") == [{:text, "*one"}]
end
test "parse block quotes" do
assert Gemini.parse(">quoted") == [{:quoted, "quoted"}]
assert Gemini.parse("> \t quoted") == [{:quoted, "quoted"}]
end
end