class TestInlineParser

Public Instance Methods

ok(e, str) click to toggle source
# File vendor/qwik/lib/qwik/parser-inline.rb, line 111
def ok(e, str)
  tokens = Qwik::InlineTokenizer.tokenize(str)
  tree = Qwik::InlineParser.make_tree(tokens)
  ok_eq(e, tree)
end
test_all() click to toggle source
# File vendor/qwik/lib/qwik/parser-inline.rb, line 117
def test_all
  ok([], '')
  ok(['t'], 't')

  # test em, strong and del
  ok([[:em, 't']], "''t''")
  ok([[:strong, 't']], "'''t'''")
  ok([[:strong, 't', [:em, '']]], "'''t''")
  ok(["'"], "'")
  ok(["'", 't'], "'t")
  ok([[:del, 't']], '==t==')
  ok(['='], '=')
  ok(['=', 't'], '=t')
  ok(['a ',[:em,'b ',[:strong,'c'],' d'],' e'], "a ''b '''c''' d'' e")
  # FIXME: Take care of incomplete patterns.
  ok([[:em, 'a', [:strong, 'b', [:del, 'c']]]], "''a'''b==c")
  ok([[:strong, '']], "''''''")
  ok(['a', [:em, 'b', [:strong, 'c'], 'd'], 'e'], "a''b'''c''d'''e")
  ok(['a', [:del, 'b', [:em, 'c'], 'd'], 'e'], "a==b''c==d''e")

  # test_ref
  ok([[:a, {:href=>'t.html'}, 't']], '[[t]]')
  ok([[:a, {:href=>'t.html'}, 's']], '[[s|t]]')
  ok([[:a, {:href=>'http://e.com/'}, 'e']], '[[e|http://e.com/]]')
  ok([[:plugin, {:method=>'interwiki', :param=>'w:p'}, 'w:p']],
     '[[w:p]]')
  ok([']'], ']')
  ok(['[', 't', ']'], '[t]')
  ok([[:a, {:href=>'http://e.com/'}, 't']], '[http://e.com/ t]')

  ok([[:a, {:href=>'C++.html'}, 'C++']], '[[C++]]')

  # test_plugin
  ok([[:plugin, {:method=>'t', :param=>''}, '']], '{{t}}')
  ok([[:plugin, {:method=>'t', :param=>'a'}, '']], '{{t(a)}}')
  ok(['{', 't', '}'], '{t}')
  #ok(['{', '{', '}}'], '{{}}')     # regexp version.
  ok(['{{}}'], '{{}}')              # strscan version.
  ok([[:br]], '{{br}}') # shotcut

  # test_url
  ok([[:a, {:href=>'http://e.com/'}, 'http://e.com/']], 'http://e.com/')
  ok([[:a, {:href=>'https://e.com/'}, 'https://e.com/']],
     'https://e.com/')
  ok(['t ', [:a, {:href=>'http://e.com/'}, 'http://e.com/'], ' a'],
     't http://e.com/ a')

  # test etc. at a time
  ok(['a ', [:em, 'b'], ' ', [:strong, 'c'], ' ', [:del, 'd'], ' ',
       [:a, {:href=>'e.html'}, 'e'], ' ',
       [:plugin, {:method=>'f', :param=>''}, ''], ' ',
       [:a, {:href=>'http://e.com/'}, 'http://e.com/'], ' g'],
     "a ''b'' '''c''' ==d== [[e]] {{f}} http://e.com/ g")

  # test_img
  ok([[:img, {:alt=>'http://e.com/t.jpg', :src=>'http://e.com/t.jpg'}]],
     '[[http://e.com/t.jpg]]')
  ok([[:img, {:alt=>'m', :src=>'http://e.com/t.jpg'}]],
     '[[m|http://e.com/t.jpg]]')

  # test_security
  ok([[:a, {:href=>'t.html'}, 't']], '[[t]]')
  ok([[:a, {:href=>'http://e.com/'}, 'http://e.com/']],
     '[[http://e.com/]]')
  ok([[:plugin, {:param=>'javascript:t', :method=>'interwiki'},
         'javascript:t']],
     '[[javascript:t]]') # Treated as InterWiki
  ok([[:a, {:href=>"&{alert('hello');};.html"}, "&{alert('hello');};"]],
     "[[&{alert('hello');};]]")

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