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

.

", p("this is\n\n[spoiler]\na block spoiler\n[/spoiler].")) end def test_paragraphs assert_equal("

a

", p("a")) assert_equal("

abc

", p("abc")) assert_equal("

a
b
c

", p("a\nb\nc")) assert_equal("

a

b

", p("a\n\nb")) end def test_headers assert_equal("

header

", p("h1. header")) assert_equal("

header

paragraph

", p("h1.header\n\nparagraph")) end def test_quote_blocks assert_equal('

test

', p("[quote]\ntest\n[/quote]")) assert_equal("
\n

a

\n

b

\n

c

\n
", p("[quote]\na\n[quote]\nb\n[/quote]\nc\n[/quote]")) end def test_urls assert_equal('

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('

test

', 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_aliased_urls assert_equal('

a bob. b

', p('a [url=http://test.com]bob[/url]. b')) assert_equal('

bob

', p('[i][url=http://test.com]bob[/url][/i]')) end def test_lists assert_equal('', p('* a')) assert_equal('', p("* a\n* b").gsub(/\n/, "")) assert_equal('', p("* a\n** b").gsub(/\n/, "")) assert_equal('', p("* post #1").gsub(/\n/, "")) end def test_inline assert_equal('

tag

', p("{{tag}}")) assert_equal('

tag1 tag2

', p("{{tag1 tag2}}")) assert_equal('

<3

', p("{{<3}}")) end def test_missing_spoiler_tags assert_equal('

testing

', p('[spoiler]testing')) assert_equal('

testing

', p('[spoiler][spoiler]testing[/spoiler]')) end def test_extra_newlines assert_equal('

a

b

', p("a\n\n\n\n\n\n\nb\n\n\n\n")) end end