require 'minitest/autorun' require 'dtext/dtext' class DTextTest < Minitest::Test def assert_parse(expected, input) assert_equal(expected, DTextRagel.parse(input)) end def test_mentions assert_parse('
', "@bob") assert_parse('hi @bob
', "hi @bob") assert_parse('this is not @.@ @_@ @bob
', "this is not @.@ @_@ @bob") assert_parse('this is an email@address.com and should not trigger
', "this is an email@address.com and should not trigger") assert_parse('', "multiple @bob @anna") assert_equal('hi @bob
', DTextRagel.parse("hi @bob", :disable_mentions => true)) end def test_sanitize_heart assert_parse('<3
', "<3") end def test_sanitize_less_than assert_parse('<
', "<") end def test_sanitize_greater_than assert_parse('>
', ">") end def test_sanitize_ampersand assert_parse('&
', "&") end def test_wiki_links assert_parse("a b c
", "a [[b]] c") end def test_wiki_links_spoiler assert_parse("a spoiler c
", "a [[spoiler]] c") end def test_wiki_links_nested_b assert_parse("[[tag]]
", "[b][[[/b]tag[b]]][/b]") end def test_spoilers_inline assert_parse("this is an inline spoiler.
", "this is [spoiler]an inline spoiler[/spoiler].") end def test_spoilers_block assert_parse("this is
a block spoiler
.
", "this is\n\n[spoiler]\na block spoiler\n[/spoiler].") end def test_spoilers_with_no_closing_tag_1 assert_parse("this is a spoiler with no closing tag
new text
this is a spoiler with no closing tag
new text
this is a block spoiler with no closing tag
this is a nested spoiler
abc
", "abc") end def test_paragraphs_with_newlines_1 assert_parse("a
b
c
a
b
", "a\n\nb") end def test_headers assert_parse("h1#blah-"blah. header
", "h1#blah-\"blah. header") end def test_quote_blocks assert_parse('', "[quote]\ntest\n[/quote]") end def test_quote_blocks_with_list assert_parse("test
- hello
- there
abc
", "[quote]\n* hello\n* there\n[/quote]\nabc") assert_parse("
- hello
- there
abc
", "[quote]\n* hello\n* there\n\n[/quote]\nabc") end def test_quote_blocks_nested assert_parse("", "[quote]\na\n[quote]\nb\n[/quote]\nc\n[/quote]") end def test_quote_blocks_nested_spoiler assert_parse("a
b
c
", "[quote]\na\n[spoiler]blah[/spoiler]\nc[/quote]") assert_parse("a
blah
c
", "[quote]\na\n\n[spoiler]blah[/spoiler]\n\nc[/quote]") end def test_quote_blocks_nested_expand assert_parse("a
blah
c
", "[quote]\na\n[expand]\nb\n[/expand]\nc\n[/quote]") end def test_code assert_parse("a
c
for (i=0; i<5; ++i) {\n printf(1);\n}\n\nexit(1);", "[code]for (i=0; i<5; ++i) {\n printf(1);\n}\n\nexit(1);") end def test_urls assert_parse('
a http://test.com b
', 'a http://test.com b') end def test_urls_with_newline assert_parse('', "http://test.com\nb") end def test_urls_with_paths assert_parse('a http://test.com/~bob/image.jpg b
', 'a http://test.com/~bob/image.jpg b') end def test_urls_with_fragment assert_parse('a http://test.com/home.html#toc b
', 'a http://test.com/home.html#toc b') end def test_auto_urls assert_parse('a http://test.com. b
', 'a http://test.com. b') end def test_auto_urls_in_parentheses assert_parse('a (http://test.com) b
', 'a (http://test.com) b') end def test_old_style_links assert_parse('', '"test":http://test.com') end def test_old_style_links_with_inline_tags assert_parse('', '"[i]test[/i]":http://test.com') end def test_old_style_links_with_special_entities assert_parse('"1" 2 & 3
', '"1" "2 & 3":http://three.com') end def test_new_style_links assert_parse('', '"test":[http://test.com]') end def test_new_style_links_with_parentheses assert_parse('', '"test":[http://test.com/(parentheses)]') assert_parse('(test)
', '("test":[http://test.com/(parentheses)])') assert_parse('[test]
', '["test":[http://test.com/(parentheses)]]') end def test_lists_1 assert_parse('a
b
a
another one
', "a\n* b\nc\n* d\ne\n\nanother one") assert_parse('a
another one
', "a\n* b\nc\n** d\ne\n\nanother one") end def test_inline_tags assert_parse('', "{{tag}}") end def test_inline_tags_conjunction assert_parse('', "{{tag1 tag2}}") end def test_inline_tags_special_entities assert_parse('', "{{<3}}") end def test_extra_newlines assert_parse('a
b
', "a\n\n\n\n\n\n\nb\n\n\n\n") end def test_complex_links_1 assert_parse("", "[[1|2 3]] | [[4|5 6]]") end def test_complex_links_2 assert_parse("Tags (Tagging Guidelines | Tag Checklist | Tag Groups)
", "Tags [b]([[howto:tag|Tagging Guidelines]] | [[howto:tag_checklist|Tag Checklist]] | [[Tag Groups]])[/b]") end def test_table assert_parse("header |
---|
post #100 |
header |
---|
post #100 |
c
", "[expand]\n* a\n* b\n[/expand]\nc") end def test_inline_mode assert_equal("hello", DTextRagel.parse_inline("hello").strip) end def test_strip assert_equal("hellozworld", DTextRagel.parse_strip("h[b]e[/b]llo[quote]z[/quote]wo[expand]rld[/expand]")) end def test_old_asterisks assert_parse("hello *world* neutral
", "hello *world* neutral") end def test_utf8_mentions assert_parse('', "@葉月") assert_parse('', "Hello @葉月 and @Alice") assert_parse('Should not parse 葉月@葉月
', "Should not parse 葉月@葉月") end def test_utf8_links assert_parse('', '"7893":/posts?tags=approver:葉月') assert_parse('', '"7893":[/posts?tags=approver:葉月]') assert_parse('', 'http://danbooru.donmai.us/posts?tags=approver:葉月') end end