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("
\n

this is a spoiler with no closing tag

\n

new text

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

this is a spoiler with no closing tag
new text

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

this is a block spoiler with no closing tag

", p("[spoiler]\nthis is a block spoiler with no closing tag")) end def test_spoilers_nested assert_equal("
\n

this is

\n

a nested

\n

spoiler

\n
", p("[spoiler]this is [spoiler]a nested[/spoiler] spoiler[/spoiler]")) end def test_paragraphs assert_equal("

abc

", p("abc")) end def test_paragraphs_with_newlines_1 assert_equal("

a
b
c

", p("a\nb\nc")) end def test_paragraphs_with_newlines_2 assert_equal("

a

b

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

header

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

test

', p("[quote]\ntest\n[/quote]")) end def test_quote_blocks_nested 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')) end def test_urls_with_newline assert_equal('

http://test.com
b

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

test

', 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_lists_1 assert_equal('', p('* a')) end def test_lists_2 assert_equal('', p("* a\n* b").gsub(/\n/, "")) end def test_lists_nested assert_equal('', p("* a\n** b").gsub(/\n/, "")) end def test_lists_inline assert_equal('', p("* post #1").gsub(/\n/, "")) end def test_lists_not_preceded_by_newline assert_equal('

ab

', p("a\nb\n* c\n* d").gsub(/\n/, "")) end def test_lists_with_multiline_items assert_equal('

a

', p("a\n* b\nc\n* d\ne").gsub(/\n/, "")) end def test_inline_tags assert_equal('

tag

', p("{{tag}}")) end def test_inline_tags_conjunction assert_equal('

tag1 tag2

', p("{{tag1 tag2}}")) end def test_inline_tags_special_entities 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_1 assert_equal("

2 3 | 5 6

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