class TestTokenizer

Public Instance Methods

ok(e, str) click to toggle source
# File vendor/qwik/lib/qwik/tokenizer.rb, line 137
def ok(e, str)
  ok_eq(e, Qwik::TextTokenizer.tokenize(str))
end
test_all() click to toggle source
# File vendor/qwik/lib/qwik/tokenizer.rb, line 141
def test_all
  ok([], '')
  ok([[:empty]], '#t')
  ok([[:hr]], '====')
  ok([[:text, '===']], '===')

  # test_h
  ok([[:text, '*']], '*')
  ok([[:h2, 't']], '*t')
  ok([[:h2, 't']], '* t')
  ok([[:h2, 't']], '*t ')
  ok([[:h2, 's t']], '* s t')
  ok([[:text, '* ']], '* ')
  ok([[:text, '*']], '*')
  ok([[:h3, 't']], '**t')
  ok([[:h4, 't']], '***t')
  ok([[:h5, 't']], '****t')
  ok([[:h6, 't']], '*****t')

  # test_!
  ok([[:h2, 't']], '! t')

  ok([[:text, '-']], '-')
  ok([[:ul, 1, 't']], '-t')
  ok([[:ul, 1, 't']], '- t')
  ok([[:ul, 2, 't']], '--t')
  ok([[:ul, 3, 't']], '---t')
  ok([[:ul, 3, '-t']], '----t') # uum...
  ok([[:ul, 1, '-']], '--')
  ok([[:hr]], '-- ')
  ok([[:hr]], '----')
  ok([[:text, '+']], '+')
  ok([[:ol, 1, 't']], '+t')
  ok([[:blockquote, 't']], '>t')
  ok([[:blockquote, 't']], '> t')

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

  ok([[:pre, 't']], ' t')
  ok([[:pre, 't']], "\tt")

  # test_table
  ok([[:table, 't']], ',t')
  #ok([[:table, 't']], ', t')
  ok([[:table, ' t']], ', t')
  ok([[:table, 's', 't']], ',s,t')
  ok([[:table, '', 't']], ',,t')
  ok([[:table, 't']], '|t')
  ok([[:table, '$t']], ',$t')
  ok([[:table, '$1']], ',$1')

  ok([[:text, '{t}']], '{t}')
  ok([[:plugin, 't', '']], '{{t}}')
  ok([[:plugin, 't', 'a']], '{{t(a)}}')
  ok([[:plugin, 't', '', '']], '{{t')
  ok([[:plugin, 't', 'a', '']], '{{t(a)')
  ok([[:plugin, 't', '', "s\n"]], "{{t\ns\n}}")
  ok([[:plugin, 't', 'a', "s\n"]], "{{t(a)\ns\n}}")

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

  ok([[:empty]], "\n")
  ok([[:text, 't']], 't')
  ok([[:text, 's'], [:text, 't']], "s\nt")
  ok([[:text, 's'], [:empty], [:text, 't']], "s\n\nt")

  # test_html
  ok([[:text, '<t']], '<t')
  ok([[:html, '']], '<html>')
  ok([[:html, "t\n"]], "<html>\nt\n</html>")
  ok([[:html, "<p>\nt\n</p>\n"]], "<html>\n<p>\nt\n</p>\n</html>")

  # test_sjis_bug
  ok([[:table, '怖', '怖']], ',怖,怖')
  ok([[:table, 's', 't']], '|s|t')
  ok([[:table, '怖', '怖']], '|怖|怖')

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

  # test_ul
  ok([[:ul, 1, 't'], [:ul, 1, 't']], "-t\n-t")
  ok([[:ul, 1, 't'], [:empty], [:ul, 1, 't']], "-t\n\n-t")
  ok([[:empty], [:ul, 1, 't'], [:ul, 1, 't']], "\n-t\n-t")

  # test_multiline_pre
  ok([[:pre, 't']], ' t')
  ok([[:pre, 't1'], [:pre, 't2']], " t1\n t2")
  ok([[:pre, 't1'], [:empty], [:pre, 't2']], " t1\n\n t2")

  # test_ref
  # do not parse inline for this moment.
  ok([[:text, "[[t]]"]], "[[t]]")

  # test_super_pre
  ok([[:pre, "p\n"], [:text, 't']], "{{{\np\n}}}\nt\n")
  ok([[:pre, "#p\n"], [:text, 't']], "{{{\n#p\n}}}\nt\n")

  # test_in_bracket # bad hack
  ok([[:dl, 'dt', 'dd']], ':dt:dd')
  ok([[:dl, "dt(h:m)dt2", 'dd']], ":dt(h:m)dt2:dd")
  ok([[:dl, 'u', 'h://e.com/']], ':u:h://e.com/')
  ok([[:dl, "dt(h:m)", 'h://e.com/']], ":dt(h:m):h://e.com/")
  ok([[:dl, "dt(h:m)dt2", 'h://e.com/']], ":dt(h:m)dt2:h://e.com/")
end