class TestWabisabiToWiki

Public Instance Methods

ok(w, e) click to toggle source

In this situation, I use reverse order argument for covinience.

# File vendor/qwik/lib/qwik/wabisabi-to-wiki.rb, line 328
def ok(w, e)
  ok_eq(e, Qwik::WabisabiToWiki.translate(w))
end
test_from_parser() click to toggle source
# File vendor/qwik/lib/qwik/wabisabi-to-wiki.rb, line 332
    def test_from_parser
      # test none
      ok([], '')
      #ok([["\n"]], "#t")

      # test p
      ok([[:p, 't']], "t\n")
      ok([[:p, 's', "\n", 't']], "s\nt\n")
      ok([[:p, 's'], ["\n"], [:p, 't']], "s\n\nt\n")
      ok([[:p, 's', [:br], 't']], "s{{br}}\nt\n")

      ok([[:dl, [:dt, 'dt1'], [:dd, 'dd1']], [:p, 'p1'],
           [:dl, [:dd, 'dd2']]], ":dt1:dd1\np1\n\n::dd2\n")

      # test header
      ok([[:h2, 't']], "* t\n")
      ok([[:h2, 't'], [:p, 't']], "* t\nt\n")
      ok([[:h3, 't']], "** t\n")
      ok([[:h4, 't']], "*** t\n")
      ok([[:h5, 't']], "**** t\n")
      ok([[:h6, 't']], "***** t\n")
      ok([[:h6, '*t']], "***** *t\n")
      ok([[:h6, '**t']], "***** **t\n")

      # test_ignore_space
      ok([[:h2, 't']], "* t\n")
      ok([[:h2, 't']], "* t\n")
      ok([[:h2, 't']], "* t\n")
      ok([[:h3, 't']], "** t\n")
      ok([[:h3, 't']], "** t\n")
      ok([[:h3, 't']], "** t\n")

      # test listing
      ok([[:ul, [:li, 't']]], "-t\n")
      ok([[:ul, [:ul, [:li, 't']]]], "--t\n")
      ok([[:ul, [:ul, [:ul, [:li, 't']]]]], "---t\n")
      ok([[:ul, [:li, 't']], [:p, 't']], "-t\nt\n")
      ok([[:ul, [:li, 't'], [:li, 't']]], "-t\n-t\n")
      ok([[:ul, [:li, 't'], [:ul, [:li, 't']]]], "-t\n--t\n")
      ok([[:ul, [:ul, [:li, 't']], [:li, 't']]], "--t\n-t\n")
      ok([[:ul, [:ul, [:li, 't']], [:li, 't'], [:ul, [:li, 't']]]],
             "--t\n-t\n--t\n")
      ok([[:ol, [:li, 't']]], "+t\n")
      ok([[:ul, [:li, 't']], [:ol, [:li, 't']]], "-t\n+t\n")
      ok([[:ul, [:li, 't1']], ["\n"], [:ul, [:li, 't2']]], "-t1\n-t2\n")
      ok([["\n"], [:ul, [:li, 't1'], [:li, 't2']]], "-t1\n-t2\n")

      # test blockquote
      ok([[:blockquote, [:p, 't']]], "> t\n")
      ok([[:blockquote, [:p, 's', "\n", 't']]], "> s\n> t\n")
      ok([[:blockquote, [:ul, [:li, 's'], [:li, 't']]]], "> -s\n> -t\n")

      # test dl
      ok([[:dl, [:dt, 'dt'],[:dd, 'dd']]], ":dt:dd\n")
      ok([[:dl, [:dt, 'dt']]], ':dt')
      ok([[:dl]], '')
      ok([[:dl]], '')
      ok([[:dl, [:dd, 'dd']]], "::dd\n")
      ok([[:dl, [:dt, 'dt'], [:dd, 'dd'], [:dt, 'dt2'], [:dd, 'dd2']]],
             ":dt:dd\n:dt2:dd2\n")
      ok([[:dl, [:dt, 'dt'], [:dd, 'dd'], [:dd, 'dd2']]], ":dt:dd\n::dd2\n")

      # test pre
      ok([[:pre, 't']], " t\n")
      ok([[:pre, "s\nt"]], " s\n t\n")
      ok([[:pre, "s\n"]], " s\n")
      ok([[:pre, "s\nt\n"]], " s\n t\n")
      ok([[:pre, 't1'], ["\n"], [:pre, 't2']], " t1\n t2\n")

      # test_table
      ok([[:table, [:tr, [:td, 't']]]], "|t\n")
      ok([[:table, [:tr, [:td, 't1'], [:td, 't2']]]], "|t1|t2\n")
      ok([[:table, [:tr, [:td, ''], [:td, 't2']]]], "||t2\n")
      ok([[:table, [:tr, [:td, 's']], [:tr, [:td, 't']]]], "|s\n|t\n")
      ok([[:table, [:tr, [:td, 's1'], [:td, 's2']],
                 [:tr, [:td, 't1'], [:td, 't2']]]], "|s1|s2\n|t1|t2\n")

      # test plugin
      ok([[:plugin, {:method=>'t', :param=>''}]], "{{t}}\n")
      ok([[:plugin, {:method=>'t', :param=>'a'}]], "{{t(a)}}\n")
      ok([[:plugin, {:method=>'t', :param=>''}, "s\n"]], "{{t\ns\n}}\n")
      ok([[:plugin, {:method=>'t', :param=>''}, "s1\ns2\n"]],
             "{{t\ns1\ns2\n}}\n")

      # test_multiline
      ok([[:p, 's', "\n", 't']], "s\nt\n")
      ok([[:p, 's', [:br], 't']], "s{{br}}\nt\n")
      ok([[:p, 's'], ["\n"], [:p, 't']], "s\n\nt\n")
      ok([[:p, 's', [:br], [:br], 't']], "s{{br}}\n{{br}}\nt\n")

      str0 = "
p1~
~
> b1~
> b2~
> ~
> > bb1~
> > bb2~
> ~
> b3~
> b4~
~
p2~
"

      str = "p1

> b1{{br}}
> b2
> > bb1{{br}}
> > bb2
> b3{{br}}
> b4
p2
"
      ok([[:p, 'p1'],
               [:blockquote,  [:p, 'b1', [:br], 'b2'],
                 [:blockquote, [:p, 'bb1', [:br], 'bb2']],
                 [:p, 'b3', [:br], 'b4']],
               [:p, 'p2']],
         str)

      # test_html
      ok([[:html, "t\n"]], "t\n")
      ok([[:div, {:class=>'error'}, 'can not use [script]']],
             'can not use [script]')

      # test_ref
      ok([[:ul, [:li, [:a, {:href=>'http://e.com/'}, 't']]]],
             "-[[t|http://e.com/]]\n")

      # test_hr
      ok([[:hr]], "====\n")

      # test_bug
      ok_eq("\226]", '望')
      ok([[:p, [:a, {:href=>"\226].html"}, "\226]"]]], '[[望]]'+"\n")
    end