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].")) assert_equal("

[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("

[spoiler]this is a spoiler with no closing tag
new text

", p("[spoiler]this is a spoiler with no closing tag\nnew text")) assert_equal("

this is [spoiler]a nested 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

", 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_code assert_equal("
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')) assert_equal('

http://test.com
b

', p("http://test.com\nb")) 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_old_syle_links assert_equal('

test

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

a

b

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

2 3 | 5 6

", 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