Page MenuHomePhorge

No OneTemporary

Size
5 KB
Referenced Files
None
Subscribers
None
diff --git a/test/bbcode/parser_test.exs b/test/bbcode/parser_test.exs
index 5f33838..fbc3f3d 100644
--- a/test/bbcode/parser_test.exs
+++ b/test/bbcode/parser_test.exs
@@ -1,154 +1,160 @@
# SPDX-FileCopyrightText: 2019-2022 Pleroma Authors
# SPDX-License-Identifier: LGPL-3.0-only
defmodule BBCode.Parser.Test do
use ExUnit.Case
alias BBCode.Parser
describe "simple tags" do
test "it parses [b] tags correctly" do
assert {:ok, [b: "testing"]} = Parser.parse("[b]testing[/b]")
end
test "it parses [i] tags correctly" do
assert {:ok, [i: "testing"]} = Parser.parse("[i]testing[/i]")
end
test "it parses [u] tags correctly" do
assert {:ok, [u: "testing"]} = Parser.parse("[u]testing[/u]")
end
test "it parses [s] tags correctly" do
assert {:ok, [s: "testing"]} = Parser.parse("[s]testing[/s]")
end
test "it parses [code] tags correctly" do
assert {:ok, [code: "testing"]} = Parser.parse("[code]testing[/code]")
end
test "it parses [quote] tags correctly" do
assert {:ok, [quote: "testing"]} = Parser.parse("[quote]testing[/quote]")
end
test "it parses [img] tags correctly" do
assert {:ok, [img: "https://example.com"]} = Parser.parse("[img]https://example.com[/img]")
assert {:ok, [{:img, 64, 64, "https://example.com"}]} =
Parser.parse("[img=64x64]https://example.com[/img]")
end
test "it parses [url] tags correctly" do
assert {:ok, [url: "https://example.com"]} = Parser.parse("[url]https://example.com[/url]")
assert {:ok, [{:url, "https://example.com", {:b, "Example.com"}}]} =
Parser.parse("[url=https://example.com][b]Example.com[/b][/url]")
end
end
describe "nested tags" do
test "it parses [ul] lists correctly" do
assert {:ok, [{:ul, [{:li, "a"}, {:li, "b"}]}]} =
Parser.parse("[ul][li]a[/li][li]b[/li][/ul]")
end
test "it parses [ol] lists correctly" do
assert {:ok, [{:ol, [{:li, "a"}, {:li, "b"}]}]} =
Parser.parse("[ol][li]a[/li][li]b[/li][/ol]")
end
end
describe "multiline" do
test "it parses a multiline [li] list" do
data = """
[ul]
[li]a[/li]
[li]b[/li]
[/ul]
"""
assert {:ok, [{:ul, [{:li, "a"}, {:li, "b"}]}]} = Parser.parse(data)
end
test "it parses a multiline [*] list" do
data = """
[ul]
[*]a
[*]b
[/ul]
"""
assert {:ok, [{:ul, [{:li, ["a"]}, {:li, ["b"]}]}]} = Parser.parse(data)
end
test "it parses a multiline [*] list with children" do
data = """
[ul]
[*][url=http://example.com]Example[/url]
[/ul]
"""
assert {:ok, [{:ul, {:li, [{:url, "http://example.com", "Example"}]}}]} = Parser.parse(data)
end
end
describe "property tags" do
test "it parses [url=] tags correctly" do
assert {:ok, [{:url, "http://example.com", "Example"}]} =
Parser.parse("[url=http://example.com]Example[/url]")
end
end
describe "non-tags" do
test "it properly handles bracket text" do
data = "oh no! [swearing intensifies]"
assert {:ok, ["oh no! ", "[swearing intensifies]"]} = Parser.parse(data)
end
test "it continues when unknown tag is encountered" do
assert {:ok, ["[asdf]", " valid text input and ", {:b, "bold"}, " text"]} =
Parser.parse("[asdf] valid text input and [b]bold[/b] text")
end
test "it continues when unknown closing tag is encountered" do
assert {:ok, ["[/asdf]"]} = Parser.parse("[/asdf]")
assert {:ok, ["[/asdf]", " text"]} = Parser.parse("[/asdf] text")
assert {:ok, [b: ["[/asdf]", " text"]]} = Parser.parse("[b][/asdf] text[/b]")
end
+ test "it continues when known closing-only tag is encountered" do
+ assert {:ok, ["[/url]"]} = Parser.parse("[/url]")
+ assert {:ok, ["[/url]", " text"]} = Parser.parse("[/url] text")
+ assert {:ok, ["text ", "[/url]"]} = Parser.parse("text [/url]")
+ end
+
test "it continues when opening and closing tag is encountered" do
assert {:ok, ["asdf ", "[asdf]", "#cofe and #hambaga", "[/asdf]", " rest of text"]} =
Parser.parse("asdf [asdf]#cofe and #hambaga[/asdf] rest of text")
end
test "it works with nested tags" do
assert {:ok,
[
code: [
"[lain@navi ~/.local/src/git/bbcode]",
"$ hacking on the ",
{:b, "BBCode"},
" parser using ",
"[asdf]",
"as the version manager",
"[/asdf]"
]
]} =
Parser.parse(
"[code][lain@navi ~/.local/src/git/bbcode]$ hacking on the [b]BBCode[/b] parser using [asdf]as the version manager[/asdf][/code]"
)
end
test "it continues when stray brackets are encountered" do
assert {:ok,
[
{:code, [" a", "[ b]", " ", "[ ]", " ", "[] ", "valid input"]},
" and ",
{:b, "bold"},
" text ",
"]"
]} =
Parser.parse("[code] a[ b] [ ] [] valid input[/code] and [b]bold[/b] text ]")
end
end
end

File Metadata

Mime Type
text/x-diff
Expires
Sat, Aug 8, 1:08 PM (1 d, 15 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1721762
Default Alt Text
(5 KB)

Event Timeline