require "test_helper" class DTextTest < ActiveSupport::TestCase def p(s) DText.parse(s) end def test_sanitize_heart assert_equal('
<3
', p("<3")) end def test_sanitize_less_than assert_equal('<
', p("<")) end def test_sanitize_greater_than assert_equal('>
', p(">")) end def test_sanitize_ampersand assert_equal('&
', p("&")) end def test_wiki_links assert_equal("a b c
", p("a [[b]] c")) end def test_wiki_links_spoiler assert_equal("a spoiler c
", p("a [[spoiler]] c")) end def test_spoilers_inline assert_equal("this is
an inline spoiler
.
", p("this is [spoiler]an inline spoiler[/spoiler].")) end def test_spoilers_block assert_equal("this is
a block spoiler
.
", p("this is\n\n[spoiler]\na block spoiler\n[/spoiler].")) end def test_spoilers_with_no_closing_tag_1 assert_equal("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
", p("abc")) end def test_paragraphs_with_newlines_1 assert_equal("a
b
c
a
b
", p("a\n\nb")) end def test_headers assert_equal("', p("[quote]\ntest\n[/quote]")) end def test_quote_blocks_nested assert_equal("test
", p("[quote]\na\n[quote]\nb\n[/quote]\nc\n[/quote]")) end def test_code assert_equal("a
b
c
for (i=0; i<5; ++i) {\n printf(1);\n}\n\nexit(1);\n\n", p("[code]for (i=0; i<5; ++i) {\n printf(1);\n}\n\nexit(1);"))
end
def test_urls
assert_equal('a http://test.com b
', p('a http://test.com b')) end def test_urls_with_newline assert_equal('', p("http://test.com\nb")) end def test_urls_with_paths assert_equal('a http://test.com/~bob/image.jpg b
', p('a http://test.com/~bob/image.jpg b')) end def test_urls_with_fragment assert_equal('a http://test.com/home.html#toc b
', p('a http://test.com/home.html#toc b')) end def test_auto_urls assert_equal('a http://test.com. b
', p('a http://test.com. b')) end def test_auto_urls_in_parentheses assert_equal('a (http://test.com) b
', p('a (http://test.com) b')) end def test_old_style_links assert_equal('', p('"test":http://test.com')) end def test_old_style_links_with_special_entities assert_equal('"1" 2 & 3
', p('"1" "2 & 3":http://three.com')) end def test_new_style_links assert_equal('', p('"test":[http://test.com]')) end def test_new_style_links_with_parentheses assert_equal('', p('"test":[http://test.com/(parentheses)]')) assert_equal('(test)
', p('("test":[http://test.com/(parentheses)])')) assert_equal('[test]
', p('["test":[http://test.com/(parentheses)]]')) end def test_lists_1 assert_equal('ab
a
a
b
', p("a\n\n\n\n\n\n\nb\n\n\n\n")) end def test_complex_links_1 assert_equal("", p("[[1|2 3]] | [[4|5 6]]")) end def test_complex_links_2 assert_equal("Tags (Tagging Guidelines | Tag Checklist | Tag Groups)
", p("Tags [b]([[howto:tag|Tagging Guidelines]] | [[howto:tag_checklist|Tag Checklist]] | [[Tag Groups]])[/b]")) end def test_table assert_equal("| header |
|---|
| post #100 |
| header |
|---|
| post #100 |