test/parser_test.rb in trac-wiki-0.2.16 vs test/parser_test.rb in trac-wiki-0.2.20
- old
+ new
@@ -3,25 +3,40 @@
require 'pp'
class Bacon::Context
def tc(html, wiki, options = {})
- #options[:template_handler] = proc {|tname,env| template_handler(tname, env) }
+ options[:plugins] = { '!print' => proc { |env| env.arg(0) + '! ' },
+ }
options[:template_handler] = self.method(:template_handler)
- TracWiki.render(wiki, options).should.equal html
+
+ parser = TracWiki.parser(wiki, options)
+ parser.to_html.should.equal html
end
def template_handler(tname, env)
case tname
+ when 'ifeqtest'
+ "{{!ifeq {{$1}}|{{$2}}|TRUE|FALSE}}"
+ when 'vartest2'
+ "{{vartest {{$1}}|{{$dva}}|p={{$p}}|{{$3 |tridef}}}}"
+ when 'ytest'
+ "{{$y.ahoj}},{{$y.bhoj.1}}"
+ when 'ytest2'
+ "{{!set i|ahoj}}{{$y.$i}},{{$y.bhoj.1}}"
+ when 'vartest'
+ "jedna:{{$1}},dve:{{$2}},p:{{$p}},arg:{{$arg}}"
when 'test'
"{{west}}"
when 'west'
"WEST"
when 'deep'
"{{deep}}"
when 'wide'
"0123456789{{wide}}" * 10
+ when 'fortest'
+ "{{$y.data.a}},({{!for i|y.data|AHOJ({{$i}})\n{{$y.data.$i}};\n}}),{{$y.data.a}}"
else
nil
#"UNK_TEMPL(#{tname})"
end
end
@@ -572,10 +587,12 @@
tc "<p>-- --</p>\n", "--\t-- "
end
it 'should parse table' do
tc "<table><tr><td>Hello</td><td>World!</td></tr></table>", "||Hello||World!||"
+ tc "<table><tr><td>Hello</td><td>World!</td></tr><tr><td>Hello</td><td>World!</td></tr></table>", "||Hello||World!||\n||Hello||World!||\n\n"
+ tc "<table><tr><td>Hello</td><td>World!</td></tr><tr><td>Hello</td><td>World!</td></tr></table>", "||Hello||World!||\r\n||Hello||World!||\r\n\n"
tc "<table><tr><td>Hello</td><td>World!</td></tr></table>", "||Hello||\\\n||World!||"
tc "<table><tr><td>He</td><td>llo</td><td>World!</td></tr></table>", "||He||llo||\\\n||World!||"
tc "<table><tr><td>Hello</td><td colspan=\"2\">World!</td></tr></table>", "||Hello||||World!||"
tc "<table><tr><td>Hello</td><td colspan=\"2\">kuk</td><td>World!</td></tr></table>", "||Hello||||kuk||\\\n||World!||"
tc "<table><tr><td>1</td><td>2</td><td>3</td></tr><tr><td colspan=\"2\">1-2</td><td>3</td></tr><tr><td>1</td><td colspan=\"2\">2-3</td></tr><tr><td colspan=\"3\">1-2-3</td></tr></table>", "|| 1 || 2 || 3 ||\n|||| 1-2 || 3 ||\n|| 1 |||| 2-3 ||\n|||||| 1-2-3 ||\n"
@@ -891,40 +908,101 @@
tc "<h1>h1</h1>" , "{{# comment }}\n\n\n= h1 =\n"
tc "<h1>h1</h1>" , "{{# comment }}\n\n\n= h1 =\n{{# Comment2}}\n"
tc "<h1>h1</h1>" , "{{# co{{HUU}}mment }}\n\n\n= h1 =\n{{# Comment2}}\n"
- tc "<p>UMACRO(macr ahoj )</p>\n" , "{{macr\nahoj\n}}"
- tc "<p>ahoj UMACRO(macrUMACRO(o))</p>\n" , "ahoj {{macr{{o}}}}"
- tc "<p>ahoj UMACRO(macro)</p>\n" , "ahoj {{macro}}"
- tc "<p>ahoj {{%macrUMACRO(o)}}</p>\n" , "ahoj {{%macr{{o}}}}"
- tc "<p>ahoj UMACRO(macrUMACRO(mac <strong>o</strong>))</p>\n" , "ahoj {{macr{{mac **o**}}}}"
- tc "<p>ahoj VAR($mac)</p>\n" , "ahoj {{$mac|ahoj}}"
+ tc "<p>UMACRO(macr|ahoj )</p>\n" , "{{macr\nahoj\n}}"
+ tc "<p>ahoj UMACRO(macr|UMACRO(o|))</p>\n" , "ahoj {{macr{{o}}}}"
+ tc "<p>ahoj UMACRO(macro|)</p>\n" , "ahoj {{macro}}"
+ tc "<p>ahoj {{%macrUMACRO(o|)}}</p>\n" , "ahoj {{%macr{{o}}}}"
+ tc "<p>ahoj UMACRO(macr|UMACRO(mac|<strong>o</strong>))</p>\n" , "ahoj {{macr{{mac **o**}}}}"
+ tc "<p>ahoj ahoj</p>\n" , "ahoj {{$mac|ahoj}}"
end
it 'should do temlate' do
tc "<p>1WEST</p>\n", "1{{west}}"
tc "<p>2WEST</p>\n", "2{{test}}"
# macro errors:
tc "<p>TOO_DEEP_RECURSION(<tt>{{deep}}</tt>) 3</p>\n", "{{deep}}3"
tc "<p>TOO_LONG_EXPANSION_OF_MACRO(wide)QUIT</p>\n", "{{wide}}3"
- tc "<p>UMACRO(unknown)3</p>\n", "{{unknown}}3"
+ tc "<p>UMACRO(unknown|)3</p>\n", "{{unknown}}3"
end
+ it 'should do temlate with args' do
+ tc "<p>jedna:VARTESTPARAM,dve:,p:DVE,arg:VARTESTPARAM|p=DVE</p>\n", "{{vartest VARTESTPARAM|p=DVE}}"
+ tc "<p>jedna:VARTESTPARAM,dve:TRI,p:DVE,arg:VARTESTPARAM|p=DVE|TRI</p>\n", "{{vartest VARTESTPARAM|p=DVE|TRI}}"
+ tc "<p>jedna:VARTESTPARAM,dve:TRI,p:DVE,arg:VARTESTPARAM|TRI|p=DVE|tridef</p>\n", "{{vartest2 VARTESTPARAM|p=DVE|dva=TRI}}"
+ tc "<p>ahoj |</p>\n", "ahoj {{!}}"
+ #FIXME: should be: '... jedna:be||no to be,dve: ..'
+ tc "<p>jedna:be,dve:,p:,arg:be||not to be</p>\n", "{{vartest be{{!}}{{!}}not to be}}"
+ end
it 'should support options' do
tc "<h3>h1<a class=\"editheading\" href=\"?edit=1\">edit</a></h3>", "=== h1 ==", edit_heading: true
end
it 'should not html' do
- tc "<p>{{{! <a></a> }}}</p>\n", "{{{!\n<a></a>\n}}}\n"
+ #tc "<p>{{{! <a></a> }}}</p>\n", "{{{!\n<a></a>\n}}}\n"
tc '<a></a>', "{{{!\n<a></a>\n}}}\n", raw_html: true
tc '<a></a>', "{{{!\n<a></a>\n}}}\n", raw_html: true
tc "<form meth=\"POST\" action=\"http://www.example.com\"><input type=\"hidden\" value=\"VAL\"></form>",
"{{{!\n<form meth=\"POST\" action=\"http://www.example.com\"><input type=\"hidden\" value=\"VAL\"/></form>\n}}}\n", raw_html: true
tc 'alert(444);', "{{{!\n<script>alert(444);</script>\n}}}\n", raw_html: true
end
- it 'should not entity' do
+ it 'should entity' do
tc "<p>\u00a0</p>\n", " "
tc "<p>„text“</p>\n", "„text“"
end
+ it 'should plugin' do
+ tc "<p>AHOJTE!</p>\n", "{{!print AHOJTE}}"
+ tc "<p>test:AHOJTE! AHOJTE! </p>\n", "test:{{!print AHOJTE}}{{!print AHOJTE}}"
+ tc "<p>FALSE</p>\n", "{{ifeqtest JEDNA|DVE}}"
+ tc "<p>TRUE</p>\n", "{{ifeqtest JEDNA|JEDNA}}"
+ tc "<p>AHOJ</p>\n", "{{!set ahoj|AHOJ}}{{$ahoj}}"
+ tc "<p>BHOJ</p>\n", "{{!ifeq a|b|{{!set ahoj|AHOJ}}|{{!set ahoj|BHOJ}}}}{{$ahoj}}"
+ tc "<p>AHOJ</p>\n", "{{!ifeq a|a|{{!set ahoj|AHOJ}}|{{!set ahoj|BHOJ}}}}{{$ahoj}}"
+ tc "<p>TRUE</p>\n", "{{!set a|a}}{{!ifeq {{$a}}|a|TRUE|FALSE}}"
+ tc "<p>FALSE</p>\n", "{{!set a|a}}{{!ifeq {{$a}}|b|TRUE|FALSE}}"
+ tc "<p>,AHOJ! ,FALSE</p>\n", "{{!set a|a}},{{!print AHOJ}},{{!ifeq {{$a}}|b|TRUE|FALSE}}"
+ tc "", "{{!ifeq a|b|TRUE}}"
+ tc "<p>AHOJ,dve</p>\n", "{{ytest \nahoj: AHOJ\nbhoj: [ jedna, dve ]\n}}"
+ tc "<p>,malo</p>\n", "{{!yset ahoj|data: [1,2]\ndesc: malo}},{{$ahoj.desc}}"
+ tc "<p>,BETA</p>\n", "{{!yset ahoj|data: [ALFA,BETA]\ndesc: malo}},{{$ahoj.data.1}}"
+ tc "<p>,GAMA</p>\n", "{{!yset ahoj|data: [ALFA,BETA]\ndesc: malo}},{{!set ahoj.data.3|GAMA}}{{$ahoj.data.3}}"
+ tc "<p>,2</p>\n", "{{!yset ahoj|data: [1,2]\ndesc: malo}},{{$ahoj.data.1}}"
+ tc "<p>AHOJ,dve</p>\n", "{{ytest2 \nahoj: AHOJ\nbhoj: [ jedna, dve ]\n}}"
+ tc "<p>,,BHOJ</p>\n", "{{!set ahoj|AHOJ}},{{!set AHOJ|BHOJ}},{{$$ahoj}}"
+ tc "<p>(0),(1),(2),</p>\n", "{{!for i|3|({{$i}}),}}", raw_html: true
+ tc "<p>(0),(1),(2),(3),</p>\n", "{{!for i|4|({{$i}}),}}", raw_html: true
+ tc "<p>,(ALFA),(BETA),</p>\n", "{{!yset data|[ALFA,BETA]}},{{!for i|data|({{$data.$i}}),}}"
+ tc "<p>,(1),(2),</p>\n", "{{!yset data|[1,2]}},{{!for i|data|({{$data.$i}}),}}"
+ tc "<p>,(alfa:ALFA),(beta:BETA),</p>\n", "{{!yset data|beta: BETA\nalfa: ALFA\n}},{{!for i|data|({{$i}}:{{$data.$i}}),}}"
+
+ tc "<p>,FALSE</p>\n", "{{!yset data|[1,2]}},{{!ifdef data.55|TRUE|FALSE}}"
+ tc "<p>,TRUE</p>\n", "{{!yset data|[1,2]}},{{!ifdef data.1|TRUE|FALSE}}"
+ tc "<p>,TRUE</p>\n", "{{!yset data|{a: 1, b: 2} }},{{!ifdef data.a|TRUE|FALSE}}"
+ tc "<p>,FALSE</p>\n", "{{!yset data|{a: 1, b: 2} }},{{!ifdef data.q|TRUE|FALSE}}"
+ tc "<p>,1,(1;2;),1</p>\n", "{{!yset data|{a: 1, b: 2} }},{{$data.a}},({{!for i|data|{{$data.$i}};}}),{{$data.a}}"
+ tc "<p>1,(AHOJ(a) 1; AHOJ(b) 2; ),1</p>\n", "{{fortest data:\n a: 1\n b: 2 }}"
+ end
+
+ it 'should {{!sub}}' do
+ tc "<p>ahoj_you_one</p>\n", "{{!sub ahoj you one| |_}}"
+ tc "<p>-h-j --- -n-</p>\n", "{{!sub ahoj you one|/[aeiouy]/|-}}"
+ tc "<p>ahoj MATCH(you) one</p>\n", "{{!sub ahoj you one|/(y.u)/|MATCH(\\1)}}"
+ end
+
+ it 'should {{!html}}' do
+ tc "alert(666)", "{{!html <script>alert(666)</script>}}", raw_html: true
+ tc "<p><b>T</b>E</p>", "{{!html <p><b>T</b>E</p>}}\n", raw_html: true
+ tc "<span>Span</span>", "{{!html <span>Span</span>}}\n", raw_html: true
+ #tc "<span>Span</span>", "**{{!html <span>Span</span>}}**\n", raw_html: true
+ tc "<div class=\"ahoj\">Div</div>", "{{!html <div class=\"ahoj\">Div</div>}}\n", raw_html: true
+ tc "<span>Span</span><span>Span</span>", "{{!html <span>Span</span>}}{{!html <span>Span</span>}}\n", raw_html: true
+ tc "<p>ahoj <span class=\"spanclass\">span</span> bhoj dhoj choj</p>\n", "ahoj {{{!<span class=\"spanclass\">span</span> bhoj}}} dhoj \nchoj\n", raw_html: true
+ tc "<p>ahoj Q<span class=\"spanclass\">span</span> bhojQ dhoj choj</p>\n", "ahoj Q{{{!<span class=\"spanclass\">span</span> bhoj}}}Q dhoj \nchoj\n", raw_html: true
+ end
+# it 'last test' do
+# #tc "<p>1,(AHOJ(a) 1; AHOJ(b) 2; ),1</p>\n", "{{fortest data:\n a: 1\n b: 2 }}"
+#
+# end
end
end
# vim: tw=0