test/parser_test.rb in trac-wiki-0.3.10 vs test/parser_test.rb in trac-wiki-0.3.12

- old
+ new

@@ -10,10 +10,17 @@ options[:template_handler] = self.method(:template_handler) parser = TracWiki.parser(options) parser.to_html(wiki).should.equal html end + def env(wiki, var, val,options = {}) + options[:macro_commands] = { '!print' => proc { |env| env.arg(0) + '! ' }, } + options[:template_handler] = self.method(:template_handler) + parser = TracWiki.parser(options) + parser.to_html(wiki) + parser.env.at(var).should.equal val + end def template_handler(tname, env) case tname when 'ifeqtest' "{{!ifeq {{$1}}|{{$2}}|TRUE|FALSE}}" @@ -21,12 +28,16 @@ "{{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 'varnula' + "nula:{{$0}},a:{{$a}}" + when 'varnulanula' + "nulanula:{{$00}},a:{{$a}}" when 'vartest' - "jedna:{{$1}},dve:{{$2}},p:{{$p}},arg:{{$arg}}" + "jedna:{{$1}},dve:{{$2}},p:{{$p}},arg:{{$00}}" when 'test' "{{west}}" when 'west' "WEST" when 'deep' @@ -37,10 +48,14 @@ "* line one\n* line two\n" when 'maclentest' "maclen:{{$maclen}}" when 'wide' "0123456789{{wide}}" * 10 + when 'testoff' + "off:{{$offset}}" + when '/slash' + "slash/slash" else nil #"UNK_TEMPL(#{tname})" end end @@ -1055,11 +1070,15 @@ tc "<table><tr><td style=\"text-align:center\">4</td>\n</tr>\n</table>\n", "|| {{$offset}} ||" tc "<p><blockquote>2</blockquote></p>\n", "> {{$offset}}" tc "<p><blockquote>2<blockquote>6</blockquote></blockquote></p>\n", "> {{$offset}}\n> > {{$offset}}" tc "<p>test:5,17</p>\n", "test:{{$offset}},{{$offset}}" tc "<p>test:5,17,<strong>31</strong></p>\n", "test:{{$offset}},{{$offset}},**{{$offset}}**" + tc "<p>off:0</p>\n", "{{testoff}}" + tc "<p>A:off:2</p>\n", "A:{{testoff}}" + tc "<p>A:off:2</p>\n", "A:{{#echo {{testoff}}}}" end + it 'should parse offset and template' do tc "<p>ahoj ahoj,19</p>\n" , "ahoj {{$mac|ahoj}},{{$offset}}" tc "<p>ahoj line one line two ,12</p>\n" , "ahoj {{nl}},{{$offset}}" tc "<ul><li>line one</li>\n<li>line two,8</li>\n</ul>\n" , "{{nl2}},{{$offset}}" tc "<ul><li>line one</li>\n<li>line two 8</li>\n</ul>\n" , "{{nl2}} {{$offset}}" @@ -1079,10 +1098,13 @@ tc "<p>37</p>\n" , "{{$maclen|{{$maclen}}{{!echo ahoj}}}}" tc "<p><strong>37</strong></p>\n" , "**{{$maclen|{{$maclen}}{{!echo ahoj}}}}**" tc "<p>28</p>\n" , "{{$maclen|a=e|b=c|d={{$e}}}}" tc "<p>maclen:14</p>\n" , "{{maclentest}}" end + it 'should parse macro slash' do + tc "<p>slash/slash</p>\n" , "{{/slash}}" + end it 'should parse lineno' do tc "<p>1</p>\n" , "{{$lineno}}" tc "<p>3</p>\n" , "\n\n{{$lineno}}" tc "<p><strong>ahoj</strong></p>\n<p>4</p>\n" , "**ahoj**\n\n\n{{$lineno}}" tc "<pre>ahoj</pre><p>4</p>\n" , "{{{\nahoj\n}}}\n{{$lineno}}" @@ -1095,8 +1117,24 @@ tc "<ul><li>line one</li>\n<li>line twoline one line two 3</li>\n</ul>\n" , "\n{{nl2}}{{nl}}\n{{$lineno}}" tc "<h2>ahoj</h2><p>2</p>\n<h2>ahoj</h2><p>5</p>\n", "==ahoj==\n{{$lineno}}\n\n==ahoj==\n{{$lineno}}" tc "<table><tr><td>This is <strong>bold</strong></td>\n</tr>\n</table>\n<p>2</p>\n", "||This is **bold**||\n{{$lineno}}" tc "<ul><li>[[ahoj|bhoj]]</li>\n</ul>\n<p>3</p>\n", "* [[ahoj|bhoj]]\n\n{{$lineno}}", :no_link => true tc "<ul><li>[[ahoj|bhoj]] 2</li>\n</ul>\n", "* [[ahoj|bhoj]]\n{{$lineno}}", :no_link => true + end + it 'should parse nula' do + tc "<p>nula:TEXT,a:</p>\n" , "{{varnula TEXT}}" + tc "<p>nula:TEXT,a:AHOJ</p>\n" , "{{varnula a=AHOJ|TEXT}}" + tc "<p>nula:TEXT,a:AHOJ</p>\n" , "{{varnula TEXT|a=AHOJ}}" + tc "<p>nula:TEXT,a:</p>\n" , "{{varnula TEXT|b=AHOJ}}" + tc "<p>nula:TE|XT,a:AHOJ</p>\n" , "{{varnula TE|XT|a=AHOJ}}" + tc "<p>nula:TE|XT,a:AHOJ</p>\n" , "{{varnula TE|a=AHOJ|XT}}" + tc "<p>nula:TE|XT,a:AHOJ</p>\n" , "{{varnula TE|a=AHOJ|XT}}" + tc "<p>nulanula:TE|a=AHOJ|XT,a:AHOJ</p>\n" , "{{varnulanula TE|a=AHOJ|XT}}" + end + it 'should parse env' do + env '{{!set b|ahoj}}', 'b', 'ahoj' +# env '{{!set *|ahoj}}', '*', 'ahoj' +# env '{{!set *|{}|}}', '*', '{}' +# tc "<p>a</p>\n" , "{{!set qq|a}}{{$qq}}" end end # vim: tw=0