require "test_helper" class DTextTest < ActiveSupport::TestCase def p(s) DText.parse(s) end def test_sanitize assert_equal('
<
', p("<")) assert_equal('>
', p(">")) assert_equal('&
', p("&")) end def test_wiki_links assert_equal("a b c
", p("a [[b]] c")) assert_equal("a spoiler c
", p("a [[spoiler]] c")) end def test_spoilers assert_equal("this is an inline spoiler.
", p("this is [spoiler]an inline spoiler[/spoiler].")) assert_equal("this is
a block spoiler
[/spoiler].
this is a spoiler with no closing tag
new text
", p("[spoiler]this is a spoiler with no closing tag\n\nnew text")) assert_equal("this is a spoiler with no closing tag
new text
this is a nested[/spoiler] spoiler[/spoiler]
", p("[spoiler]this is [spoiler]a nested[/spoiler] spoiler[/spoiler]")) end def test_paragraphs assert_equal("a
", p("a")) assert_equal("abc
", p("abc")) assert_equal("a
b
c
a
b
", p("a\n\nb")) end def test_headers assert_equal("paragraph
", p("h1.header\n\nparagraph")) end def test_quote_blocks assert_equal('', p("[quote]\ntest\n[/quote]")) assert_equal("test
\n", p("[quote]\na\n[quote]\nb\n[/quote]\nc\n[/quote]")) end def test_urls assert_equal('a
\n\nb
c
\n
a http://test.com b
', p('a http://test.com b')) assert_equal('a http://test.com/~bob/image.jpg b
', p('a http://test.com/~bob/image.jpg b')) assert_equal('a http://test.com/home.html#toc b
', p('a http://test.com/home.html#toc b')) assert_equal('a http://test.com. b
', p('a http://test.com. b')) assert_equal('a (http://test.com) b
', p('a (http://test.com) b')) end # def test_links # assert_equal('', p('[url=http://test.com]test[/url]')) # assert_equal('"1" 2
', p('"1" [url=http://two.com]2[/url]')) # assert_equal('"1" 2 & 3
', p('"1" [url=http://three.com]2 & 3[/url]')) # end def test_old_syle_links assert_equal('', p('"test":http://test.com')) assert_equal('"1" 2
', p('"1" "2":http://two.com')) assert_equal('"1" 2 & 3
', p('"1" "2 & 3":http://three.com')) end # def test_aliased_urls # assert_equal('a bob. b
', p('a [url=http://test.com]bob[/url]. b')) # assert_equal('', p('[i][url=http://test.com]bob[/url][/i]')) # end def test_lists assert_equal('a
b
', p("a\n\n\n\n\n\n\nb\n\n\n\n")) end def test_complex_links assert_equal("", p("[[1|2 3]] | [[4|5 6]]")) 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 end