class TestParser

Public Instance Methods

ok(e, str) click to toggle source
# File vendor/qwik/lib/qwik/parser.rb, line 163
def ok(e, str)
  tokens = Qwik::TextTokenizer.tokenize(str)
  ok_eq(e, Qwik::TextParser.make_tree(tokens))
end
test_all() click to toggle source
# File vendor/qwik/lib/qwik/parser.rb, line 168
    def test_all
      # test none
      ok([], '')
      ok([["\n"]], "#t")

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

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

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

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

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

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

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

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

      ok([[:pre, "s\n"]], "{{{\ns\n}}}")
      ok([[:pre, "s\nt\n"]], "{{{\ns\nt\n}}}")
      ok([[:pre, "#s\n"]], "{{{\n#s\n}}}")

      ok([[:pre, 't1'], ["\n"], [:pre, 't2']], " t1\n\n t2")

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

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

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

      str = <<'EOT'
p1~
~
> b1~
> b2~
> ~
> > bb1~
> > bb2~
> ~
> b3~
> b4~
~
p2~
EOT
      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"]], "<html>\nt\n</html>")
      ok([[:div, {:class=>'error'}, "can not use [script]"]],
             "<html>\n<script>t</script>\n</html>")

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

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

      # test_bug
      ok_eq("\226]", '望')
      ok([[:p, [:a, {:href=>"\226].html"}, "\226]"]]], '[[望]]')
    end
test_format() click to toggle source
# File vendor/qwik/lib/qwik/parser.rb, line 313
def test_format
  # test_inline
  ok([[:p, [:em, 't']]], "''t''")
  ok([[:p, [:a, {:href=>'t.html'}, 't']]], "[[t]]")
  ok([[:p, [:a, {:href=>'1.html'}, '1']]], "[[1]]")
  ok([[:p, [:plugin, {:method=>'interwiki', :param=>'Test:t'}, 'Test:t']]],
     "[[Test:t]]")
  ok([[:plugin, {:method=>'t', :param=>''}]], "{{t}}")
  ok([[:p, 'a', [:plugin, {:method=>'t', :param=>''}, ''], 'b']], "a{{t}}b")
  ok([[:p, [:a, {:href=>'http://e.com/'}, 'http://e.com/']]],
     'http://e.com/')
  ok([[:p, 'a ', [:a, {:href=>'http://e.com/'}, 'http://e.com/'], ' b']],
     'a http://e.com/ b')

  # test_escape
  ok([[:h2, "'"]], "*'")
  ok([[:h2, "<"]], "*<")

  # test_sjis
  ok([[:h2, "\202\240"]], "* あ")
  ok([[:h3, "\202\240"]], "** あ")
  ok([[:h3, "\212\277\216\232"]], "** 漢字")
  ok([[:h3, "\221\322"]], "** 待")

  # test ?
  ok([[:h2, [:a, {:href=>'t.html'}, 't']]], "*[[t]]")
  ok([[:h2, [:a, {:href=>'t.html'}, 't']]], "* [[t]]")
  ok([[:h2, [:a, {:href=>'t.html'}, 't']]], "* [[t]] ")
  ok([[:h2, [:a, {:href=>'t.html'}, 't'], ' a']], "* [[t]] a")
  ok([[:h2, [:a, {:href=>'t.html'}, 't'], '  a']], "* [[t]]  a")

  # test_format
  ok([[:h2, "<"]], "*<")
  ok([[:p, [:strong, '']]], "''''''")
end
test_from_resolve() click to toggle source
# File vendor/qwik/lib/qwik/parser.rb, line 299
def test_from_resolve
  # test_lines
  ok([[:ul, [:li, 't1'], [:li, 't2']]], "- t1\n- t2")
  ok([[:p, 't1'], [:ul, [:li, 't2']]], "t1\n- t2")

  # test_qwik_text
  ok([[:ul, [:li, 't']]], '- t')
  ok([[:ul, [:li, 's'], [:ul, [:li, 't']]]], "- s\n-- t")
  ok([[:ol, [:li, 't']]], "+ t")

  # test_ul
  ok([[:ul, [:li, 't1']], ["\n"], [:ul, [:li, 't2']]], "- t1\n\n- t2")
end