require "test/unit" rootdir = "#{File::dirname(__FILE__)}/.." require "#{rootdir}/lib/hikidoc" class HikiDocTestCase < Test::Unit::TestCase def test_plugin assert_convert("
{{hoge}}
\n", "{{hoge}}") assert_convert("

a{{hoge}}b

\n", "a{{hoge}}b") assert_convert("

\\{{hoge}}

\n", "\\{{hoge}}") assert_convert("

a{{hoge

\n", "a{{hoge") assert_convert("

hoge}}b

\n", "hoge}}b") assert_convert("

{{hoge}}\na

\n", "{{hoge}}\na") assert_convert("
{{hoge}}
\n

a

\n", "{{hoge}}\n\na") end def test_plugin_with_quotes assert_convert("
{{hoge(\"}}\")}}
\n", '{{hoge("}}")}}') assert_convert("
{{hoge(\'}}\')}}
\n", "{{hoge('}}')}}") assert_convert("
{{hoge(\'\n}}\n\')}}
\n", "{{hoge('\n}}\n')}}") end def test_plugin_with_meta_char assert_convert("
{{hoge(\"a\\\"b\")}}
\n", '{{hoge("a\\"b")}}') assert_convert("
{{hoge(\"<a>\")}}
\n", '{{hoge("")}}') assert_convert("

a{{hoge(\"<a>\")}}

\n", 'a{{hoge("
")}}') end def test_plugin_with_default_syntax # test HikiDoc#valid_plugin_syntax? # default syntax checking pairs of quote like "..." or '...' assert_convert(%q!

{{'}}

! + "\n", %q!{{'}}!) assert_convert(%q!
{{''}}
! + "\n", %q!{{''}}!) assert_convert(%q!

{{'"}}

! + "\n", %q!{{'"}}!) assert_convert(%q!
{{'\''}}
! + "\n", %q!{{'\''}}!) assert_convert(%q!
{{'abc\\\\'}}
! + "\n", %q!{{'abc\\\\'}}!) assert_convert(%q!
{{\"""}}
! + "\n", %q!{{\"""}}!) assert_convert(%q!
{{"ab\c"}}
! + "\n", %q!{{"ab\c"}}!) end def test_plugin_with_custom_syntax assert_convert("

{{<<\"End\"\nfoo's bar\nEnd\n}}

\n", "{{<<\"End\"\nfoo's bar\nEnd\n}}") options = {plugin_syntax: method(:custom_valid_plugin_syntax?)} assert_convert(%Q|
{{<<"End"\nfoo's bar\nEnd\n}}
\n|, %Q!{{<<"End"\nfoo's bar\nEnd\n}}!, options) assert_convert(%Q|
{{<<"End"\nfoo\nEnd}}
\n|, %Q!{{<<"End"\nfoo\nEnd}}!, options) end def test_multi_line_plugin assert_convert(<<-END_OF_EXPECTED, <<-END_OF_INPUT)
{{<<TEST2 test2 TEST2}}
END_OF_EXPECTED {{<{{<<TEST <<< here is not pre but plugin. >>> TEST}} END_OF_EXPECTED {{<>> TEST}} END_OF_INPUT end def test_blockquote assert_convert("

hoge

\n
\n", %Q|""hoge\n|) assert_convert("

hoge\nfuga

\n
\n", %Q|""hoge\n""fuga\n|) assert_convert("

hoge

\n

fuga

\n
\n
\n", %Q|""hoge\n"" ""fuga\n|) assert_convert("

hoge

\n
\n", %Q|"" ! hoge\n|) assert_convert("

foo\nbar

\n

foo

\n
\n", %Q|""foo\n""bar\n""\n""foo|) assert_convert("

foo\nbar

\n

foo

\n
\n", %Q|""foo\n""bar\n""!foo|) assert_convert("

foo\nbar

\n
baz
\n
\n", %Q|""foo\n"" bar\n"" baz|) assert_convert("

foo\nbar

\n
baz
\n
\n", %Q|""foo\n""\tbar\n""\t\tbaz|) end def test_header assert_convert("

hoge

\n", "!hoge") assert_convert("

hoge

\n", "!! hoge") assert_convert("

hoge

\n", "!!!hoge") assert_convert("

hoge

\n", "!!!! hoge") assert_convert("
hoge
\n", "!!!!!hoge") assert_convert("
hoge
\n", "!!!!!! hoge") assert_convert("
! hoge
\n", "!!!!!!! hoge") assert_convert("

foo

\n

bar

\n", "!foo\n!!bar") end def test_list assert_convert("
    \n
  • foo
  • \n
\n", "* foo") assert_convert("
    \n
  • foo
  • \n
  • bar
  • \n
\n", "* foo\n* bar") assert_convert("
    \n
  • foo
      \n
    • bar
    • \n
  • \n
\n", "* foo\n** bar") assert_convert("
    \n
  • foo
      \n
    • foo
    • \n
  • \n
  • bar
  • \n
\n", "* foo\n** foo\n* bar") assert_convert("
    \n
  • foo
      \n
    1. foo
    2. \n
  • \n
  • bar
  • \n
\n", "* foo\n## foo\n* bar") assert_convert("
    \n
  • foo
  • \n
    \n
  1. bar
  2. \n
\n", "* foo\n# bar") end def test_list_skip assert_convert("
    \n
  • foo
      \n
      • \n
      • foo
      • \n
    • \n
  • \n
  • bar
  • \n
\n", "* foo\n*** foo\n* bar") assert_convert("
    \n
  1. foo
      \n
      1. \n
      2. bar
      3. \n
      4. baz
      5. \n
    1. \n
  2. \n
\n", "# foo\n### bar\n###baz") end def test_hrules assert_convert("
\n", "----") assert_convert("

----a

\n", "----a") end def test_pre assert_convert("
foo
\n", " foo") assert_convert("
\\:
\n", ' \:') assert_convert("
foo
\n", "\tfoo") assert_convert("
foo\nbar
\n", " foo\n bar") assert_convert("
foo\nbar
\n", " foo\n bar\n") assert_convert("
<foo>
\n", " ") assert_convert("
{{_:a/a}}
\n", " {{_:a/a}}") assert_convert("
[[_:a/a]]
\n", " [[_:a/a]]") end def test_multi_pre assert_convert("
foo
\n", "<<<\nfoo\n>>>") assert_convert("
foo\n bar
\n", "<<<\nfoo\n bar\n>>>") assert_convert("
foo
\n
bar
\n", "<<<\nfoo\n>>>\n<<<\nbar\n>>>") assert_convert("
<foo>
\n", "<<<\n\n>>>") end def test_multi_pre_with_plugin assert_convert("
{{{}}}
\n" + "
{{'test'}}
\n", "<<<\n{{{}}}\n>>>\n{{'test'}}") end def test_comment assert_convert("", "// foo") assert_convert("", "// foo\n") end def test_paragraph assert_convert("

foo

\n", "foo") assert_convert("

foo

\n

bar

\n", "foo\n\nbar") assert_convert("

foo

\n

bar

\n", "foo\r\n\r\nbar") assert_convert("

foo

\n

b a r

\n", "foo \n\nb a r ") end def test_escape assert_convert(%Q|

\\"\\"foo

\n|, %q|\"\"foo|) end def test_link assert_convert(%Q|

http://hikiwiki.org/

\n|, "http://hikiwiki.org/") assert_convert(%Q|

http://hikiwiki.org/

\n|, "[[http://hikiwiki.org/]]") assert_convert(%Q|

Hiki

\n|, "[[Hiki|http://hikiwiki.org/]]") assert_convert(%Q|

Hiki

\n|, "[[Hiki|http:/hikiwiki.html]]") assert_convert(%Q|

Hiki

\n|, "[[Hiki|http:hikiwiki.html]]") assert_convert(%Q|

img.png

\n|, "http://hikiwiki.org/img.png") assert_convert(%Q|

img.png

\n|, "http://hikiwiki.org:80/img.png") assert_convert(%Q|

| + %Q|http://hikiwiki.org/ja/?c=edit;p=Test

\n|, "http://hikiwiki.org/ja/?c=edit;p=Test") assert_convert(%Q|

| + %Q|http://hikiwiki.org/ja/?c=edit&p=Test

\n|, "http://hikiwiki.org/ja/?c=edit&p=Test") assert_convert(%Q|

img.png

\n|, "http:/img.png") assert_convert(%Q|

img.png

\n|, "http:img.png") assert_convert(%Q|

Tuna

\n|, "[[Tuna|%CB%EE]]") assert_convert(%Q|

""

\n|, '[[""]]') assert_convert(%Q|

%22

\n|, "[[%22]]") assert_convert(%Q|

&

\n|, "[[&]]") assert_convert(%Q|

aabbcc

\n|, "[[aa]]bb[[cc]]") assert_convert(%Q!

a|a

\n!, "[[a|a|aa]]") end def test_inter_wiki_name assert_convert("

scheme:keyword

\n", "[[scheme:keyword]]") assert_convert("

label

\n", "[[label|scheme:keyword]]") end def test_wiki_name assert_convert("

WikiName

\n", "WikiName") assert_convert("

HogeRule1

\n", "HogeRule1") assert_convert("

WikiName1WikiName2

\n", "WikiName1WikiName2") assert_convert("

WikiName1 " + "WikiName2

\n", "WikiName1 WikiName2") assert_convert("

NOTWIKINAME

\n", "NOTWIKINAME") assert_convert("

NOT_WIKI_NAME

\n", "NOT_WIKI_NAME") assert_convert("

WikiNAME

\n", "WikiNAME") assert_convert("

fooWikiNAME

\n", "fooWikiNAME") assert_convert("

RSSPage

\n", "RSSPage") assert_convert("

RSSPageName

\n", "RSSPageName") end def test_not_wiki_name assert_convert("

WikiName

\n", "^WikiName") assert_convert("

^WikiName

\n", "^WikiName", use_not_wiki_name: false) assert_convert("

^WikiName

\n", "^WikiName", use_wiki_name: false) assert_convert("

^WikiName

\n", "^WikiName", use_wiki_name: false, use_not_wiki_name: false) assert_convert("

foo WikiName bar

\n", "foo ^WikiName bar") end def test_use_wiki_name_option assert_convert("

WikiName

\n", "WikiName") assert_convert("

WikiName

\n", "WikiName", use_wiki_name: false) end def test_image_link assert_convert(%Q|

img.png

\n|, "[[http://hikiwiki.org/img.png]]") assert_convert(%Q|

http://hikiwiki.org/img.png

\n|, "[[http://hikiwiki.org/img.png]]", allow_bracket_inline_image: false) assert_convert(%Q|

img

\n|, "[[img|http://hikiwiki.org/img.png]]") assert_convert(%Q|

img

\n|, "[[img|http://hikiwiki.org/img.png]]", allow_bracket_inline_image: false) end def test_definition assert_convert("
\n
a
\n
b
\n
\n", ":a:b") assert_convert("
\n
a
\n
b\n
\n
c
\n
\n", ":a:b\n::c") assert_convert("
\n
a\\
\n
b:c
\n
\n", ':a\:b:c') assert_convert("
\n
a
\n
b\\:c
\n
\n", ':a:b\:c') assert_convert("
\n
a
\n
b:c
\n
\n", ":a:b:c") end def test_definition_title_only assert_convert("
\n
a
\n
\n", ":a:") end def test_definition_description_only assert_convert("
\n
b
\n
\n", "::b") end def test_definition_with_link assert_convert("
\n
Hiki
\n" + "
Website
\n
\n", ":[[Hiki|http://hikiwiki.org/]]:Website") assert_convert("
\n
a
\n" + "
Hiki
\n" + "
\n", ":a:[[Hiki|http://hikiwiki.org/]]") end def test_definition_with_modifier assert_convert("
\n
foo
\n" + "
bar
\n
\n", ":'''foo''':bar") assert_convert("
\n
foo
\n" + "
bar
\n
\n", ":foo:'''bar'''") assert_convert("
\n
foo
\n" + "
bar
\n
\n", ":foo:``bar``") end def test_definition_with_modifier_link assert_convert("
\n
" + "Hiki" + "
\n
Website
\n
\n", ":'''[[Hiki|http://hikiwiki.org/]]''':Website") assert_convert("
\n
Website
\n
" + "Hiki" + "
\n
\n", ":Website:'''[[Hiki|http://hikiwiki.org/]]'''") assert_convert("
\n
Website
\n
" + "Hiki" + "
\n
\n", ":Website:``[[Hiki|http://hikiwiki.org/]]``") end def test_table assert_convert(%Q|\n\n
ab
\n|, "||a||b") assert_convert(%Q|\n\n
ab
\n|, "||a||b||") assert_convert(%Q|\n\n
ab
\n|, "||a||b||") assert_convert(%Q|\n\n
ab
\n|, "||a||b|| ") assert_convert(%Q|\n\n
ab
\n|, "||!a||b||") assert_convert(%Q|\n\n\n\n
12\n
34\n
5
\n|, "||>1||^2\n||^3||4\n||>5") assert_convert(%Q|\n\n\n\n
abc
def
\n|, "||a||b||c||\n||||||||\n||d||e||f||") end def test_table_with_modifier assert_convert("\n\n
''''''bar
\n", "||'''||'''||bar") assert_convert("\n\n
'''\\'''bar
\n", "||'''\\||'''||bar") end def test_modifier assert_convert("

foo

\n", "'''foo'''") assert_convert("

foo

\n", "''foo''") assert_convert("

foo

\n", "==foo==") assert_convert("

foo==barbaz==

\n", "''foo==bar''baz==") assert_convert("

foo and bar

\n", "'''foo''' and '''bar'''") assert_convert("

foo and bar

\n", "''foo'' and ''bar''") assert_convert("

foo

\n", "``foo``") assert_convert("

foo==barbaz==

\n", "``foo==bar``baz==") end def test_nested_modifier assert_convert("

foo

\n", "''==foo==''") assert_convert("

foo

\n", "==''foo''==") end def test_modifier_and_link assert_convert("

Hiki

\n", "[['''Hiki'''|http://hikiwiki.org/]]") assert_convert("

Hiki

\n", "'''[[Hiki|http://hikiwiki.org/]]'''") assert_convert("

Hiki

\n", "``[[Hiki|http://hikiwiki.org/]]``") end def test_pre_and_plugin assert_convert(%Q|
{{hoge}}
\n|, " {{hoge}}") assert_convert(%Q|
{{hoge}}
\n|, "<<<\n{{hoge}}\n>>>") assert_convert("
{{foo\n 1}}
\n", "{{foo\n 1}}") end def test_plugin_in_modifier assert_convert("

{{foo}}

\n", "'''{{foo}}'''") assert_convert("

{{foo}}

\n", "``{{foo}}``") end def test_syntax_ruby if Object.const_defined?(:Syntax) assert_convert("
class A\n  def foo(bar)\n  end\nend
\n", "<<< ruby\nclass A\n def foo(bar)\n end\nend\n>>>") assert_convert("
class A\n  def foo(bar)\n  end\nend
\n", "<<< Ruby\nclass A\n def foo(bar)\n end\nend\n>>>") assert_convert("
'a<">b'
\n", "<<< ruby\n'a<\">b'\n>>>") # redefine method for below tests class << Syntax::Convertors::HTML def for_syntax(syntax) raise end end end # use google-code-prettify assert_convert("
class A\n  def foo(bar)\n  end\nend
\n", "<<< ruby\nclass A\n def foo(bar)\n end\nend\n>>>") assert_convert("
class A\n  def foo(bar)\n  end\nend
\n", "<<< Ruby\nclass A\n def foo(bar)\n end\nend\n>>>") assert_convert("
'a<\">b'
\n", "<<< ruby\n'a<\">b'\n>>>") end def test_plugin_in_pre_with_header assert_convert("

Title

\n
{{_/a:a}}
\n", "! Title\n {{_/a:a}}") assert_convert("

Title

\n
{{_/a:a}}\n{{_/a:a}}
\n", "! Title\n {{_/a:a}}\n {{_/a:a}}") end private def assert_convert(expected, markup, options={}, message=nil) assert_equal(expected, HikiDoc.to_xhtml(markup, options), message) end def custom_valid_plugin_syntax?(code) eval("BEGIN {return true}\n#{code}", nil, "(plugin)", 0) rescue SyntaxError false end end