test/parser_test.rb in trac-wiki-0.2.24 vs test/parser_test.rb in trac-wiki-0.3.10
- old
+ new
@@ -3,16 +3,16 @@
require 'pp'
class Bacon::Context
def tc(html, wiki, options = {})
- options[:plugins] = { '!print' => proc { |env| env.arg(0) + '! ' },
+ options[:macro_commands] = { '!print' => proc { |env| env.arg(0) + '! ' },
}
options[:template_handler] = self.method(:template_handler)
- parser = TracWiki.parser(wiki, options)
- parser.to_html.should.equal html
+ parser = TracWiki.parser(options)
+ parser.to_html(wiki).should.equal html
end
def template_handler(tname, env)
case tname
when 'ifeqtest'
@@ -29,20 +29,26 @@
"{{west}}"
when 'west'
"WEST"
when 'deep'
"{{deep}}"
+ when 'nl'
+ "line one\nline two\n"
+ when 'nl2'
+ "* line one\n* line two\n"
+ when 'maclentest'
+ "maclen:{{$maclen}}"
when 'wide'
"0123456789{{wide}}" * 10
else
nil
#"UNK_TEMPL(#{tname})"
end
end
def h(hash, wiki, opts = {})
- parser = TracWiki.parser(wiki, opts)
- parser.to_html
+ parser = TracWiki.parser(opts)
+ parser.to_html(wiki)
#pp parser.headers
parser.headings.should == hash
end
end
@@ -606,13 +612,13 @@
tc "<table><tr><td>table</td>\n<td style=\"text-align:right\">right</td>\n</tr>\n</table>\n", "||table|| right||"
tc "<table><tr><td>table</td>\n<td style=\"text-align:center\">center</td>\n<td style=\"text-align:right\">right</td>\n</tr>\n</table>\n", "||table|| center || right||"
tc "<table><tr><td>Hello, World!</td>\n</tr>\n</table>\n", "||Hello, World!||"
tc "<table><tr><td style=\"text-align:right\">Hello, Right World!</td>\n</tr>\n</table>\n", "|| Hello, Right World!||"
- tc "<table><tr><th style=\"text-align:right\">Hello, Right World!</th></tr>\n</table>\n", "||= Hello, Right World!=||"
+ tc "<table><tr><th style=\"text-align:right\">Hello, Right World!</th>\n</tr>\n</table>\n", "||= Hello, Right World!=||"
tc "<table><tr><td style=\"text-align:center\">Hello, Centered World!</td>\n</tr>\n</table>\n", "|| Hello, Centered World! ||"
- tc "<table><tr><th style=\"text-align:center\">Hello, Centered World!</th></tr>\n</table>\n", "||= Hello, Centered World! =||"
+ tc "<table><tr><th style=\"text-align:center\">Hello, Centered World!</th>\n</tr>\n</table>\n", "||= Hello, Centered World! =||"
# Multiple columns
tc "<table><tr><td>c1</td>\n<td>c2</td>\n<td>c3</td>\n</tr>\n</table>\n", "||c1||c2||c3||"
# Multiple rows
tc "<table><tr><td>c11</td>\n<td>c12</td>\n</tr>\n<tr><td>c21</td>\n<td>c22</td>\n</tr>\n</table>\n", "||c11||c12||\n||c21||c22||\n"
# End pipe is optional
@@ -624,11 +630,11 @@
# Escape in last cell + empty cell
tc "<table><tr><td>c1</td>\n<td>c2|</td>\n</tr>\n</table>\n", "||c1||c2!|"
tc "<table><tr><td>c1</td>\n<td>c2|</td>\n</tr>\n</table>\n", "||c1||c2!|"
tc "<table><tr><td>c1</td>\n<td>c2|</td>\n<td></td>\n</tr>\n</table>\n", "||c1||c2| || ||"
# Equal sign after pipe make a header
- tc "<table><tr><th>Header</th></tr>\n</table>\n", "||=Header=||"
+ tc "<table><tr><th>Header</th>\n</tr>\n</table>\n", "||=Header=||"
tc "<table><tr><td>c1</td>\n<td><a href=\"Link\">Link text</a></td>\n<td><img src=\"Image\"/></td>\n</tr>\n</table>\n", "||c1||[[Link|Link text]]||[[Image(Image)]]||"
tc "<table><tr><td>c1</td>\n<td><a href=\"Link\">Link text</a></td>\n<td><img src=\"Image\"/></td>\n</tr>\n</table>\n", "||c1||[Link|Link text]||[[Image(Image)]]||"
end
@@ -927,21 +933,20 @@
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_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"
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}}"
+ tc "<p>jedna:be||not to 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
@@ -971,53 +976,127 @@
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>(0),(1),(2),</p>\n", "{{!for i|3|({{$i}}),}}", allow_html: true
+ tc "<p>(0),(1),(2),(3),</p>\n", "{{!for i|4|({{$i}}),}}", allow_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>,(0:1),(1:2),</p>\n", "{{!yset data|[ 1,2 ]\n}},{{!for i|data|({{$i}}:{{$data.$i}}),}}"
+ tc "<p>,</p>\n", "{{!yset data|[ ]\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}}"
end
it 'should parse html' do
- tc "<p>alert(666)</p>\n", "<script>alert(666)</script>", raw_html: true
- tc "<p><b>T</b>E</p>\n", "<p><b>T</b>E</p>", raw_html: true
- tc "<p><span>Span</span></p>\n", "<span>Span</span>\n", raw_html: true
- tc "<p><strong><span>Span</span></strong></p>\n", "**<span>Span</span>**\n", raw_html: true
- tc "<div class=\"ahoj\">Div</div>\n", "<div class=\"ahoj\">Div</div>\n", raw_html: true
- tc "<p><strong>ahoj</strong></p>\n<div class=\"ahoj\">Div</div>\n", "**ahoj<div class=\"ahoj\">Div</div>\n", raw_html: true
- tc "<p><span>Span</span><span>Span</span></p>\n", "<span>Span</span><span>Span</span>\n", raw_html: true
- tc "<p><em><b>boldoitali</b></em>cE</p>\n", "<p>''<b>boldoitali''c</b>E</p>", raw_html: true
- tc "<p><b>blabla</b></p>\n<p>endE</p>\n", "<p><b>bla</html>bla</p>end</b>E</p>", raw_html: true
- tc "<p>baf</p>\n", "\n\n\nbaf\n\n\n", raw_html: true
- tc "<div class=\"ahoj\">Div</div>\n<p>baf</p>\n", "<div class=\"ahoj\">Div</div>\nbaf\n", raw_html: true
+ tc "<p>alert(666)</p>\n", "<script>alert(666)</script>", allow_html: true
+ tc "<p><b>T</b>E</p>\n", "<p><b>T</b>E</p>", allow_html: true
+ tc "<p><span>Span</span></p>\n", "<span>Span</span>\n", allow_html: true
+ tc "<p><strong><span>Span</span></strong></p>\n", "**<span>Span</span>**\n", allow_html: true
+ tc "<div class=\"ahoj\">Div</div>\n", "<div class=\"ahoj\">Div</div>\n", allow_html: true
+ tc "<p><strong>ahoj</strong></p>\n<div class=\"ahoj\">Div</div>\n", "**ahoj<div class=\"ahoj\">Div</div>\n", allow_html: true
+ tc "<p><span>Span</span><span>Span</span></p>\n", "<span>Span</span><span>Span</span>\n", allow_html: true
+ tc "<p><em><b>boldoitali</b></em>cE</p>\n", "<p>''<b>boldoitali''c</b>E</p>", allow_html: true
+ tc "<p><b>blabla</b></p>\n<p>endE</p>\n", "<p><b>bla</html>bla</p>end</b>E</p>", allow_html: true
+ tc "<p>baf</p>\n", "\n\n\nbaf\n\n\n", allow_html: true
+ tc "<div class=\"ahoj\">Div</div>\n<p>baf</p>\n", "<div class=\"ahoj\">Div</div>\nbaf\n", allow_html: true
- tc "<p><b>BOLD</b></p>\n", "<b>BOLD</b>\n", raw_html: true
- tc "<p><br/></p>\n", "<br/>\n", raw_html: true
- tc "<p><br/></p>\n", "<br></br>\n", raw_html: true
- tc "<p><b class=\"bclass\">BOLD</b></p>\n", "<b class=\"bclass\">BOLD</b>\n", raw_html: true
- tc "<p><b class=\"bclass\">BOLD</b></p>\n", "<b bad=\"bad\" class=\"bclass\">BOLD</b>\n", raw_html: true
- tc "<p><b class=\"bclass\">BOLD</b></p>\n", "<b bad=\"bad\" class=\"bclass\">BOLD</b>\n", raw_html: true
+ tc "<p><b>BOLD</b></p>\n", "<b>BOLD</b>\n", allow_html: true
+ tc "<p><br/></p>\n", "<br/>\n", allow_html: true
+ tc "<p><br/></p>\n", "<br></br>\n", allow_html: true
+ tc "<p><b class=\"bclass\">BOLD</b></p>\n", "<b class=\"bclass\">BOLD</b>\n", allow_html: true
+ tc "<p><b class=\"bclass\">BOLD</b></p>\n", "<b bad=\"bad\" class=\"bclass\">BOLD</b>\n", allow_html: true
+ tc "<p><b class=\"bclass\">BOLD</b></p>\n", "<b bad=\"bad\" class=\"bclass\">BOLD</b>\n", allow_html: true
end
it 'should parse link' do
tc "<p><a href=\"#here\">Here</a></p>\n", "[[#here|Here]]"
tc "<p><a href=\"#here+i+m\">Here</a></p>\n", "[[#here i m|Here]]"
tc "<p><a href=\"there#i+m\">There</a></p>\n", "[[there#i m|There]]"
tc "<p><a href=\"http://example.com/there#i+m\">There</a></p>\n", "[[there#i m|There]]", base: 'http://example.com/'
tc "<p><a href=\"#here+i+m\">Here</a></p>\n", "[[#here i m|Here]]", base: 'http://example.com/'
end
it 'should parse dnl inside macro' do
tc "<p>d<blockquote>e</blockquote></p>\n", "{{!ifeq a|b|c|d\n e}}"
- tc "<p>d e</p>\n", "{{!ifeq a|b|c|d\\\n e}}"
+ tc "<p>de</p>\n", "{{!ifeq a|b|c|d\\\n e}}"
tc "<p>d<strong>e</strong></p>\n", "{{!ifeq a|b|c|d**\\\ne**}}"
tc "<p>d<strong>e</strong></p>\n", "{{!ifeq a|b|c|d*\\\n*e**}}"
+ tc "<p>d<strong>e</strong></p>\n", "{{!ifeq a|b|c|d*\\\r\n*e**}}"
+ tc "<p>e</p>\n", "{{!ifeq a|b|c|\\\r\ne}}"
+ tc "<p>a0a1a2</p>\n", "{{!for i|3|a\\\n{{$i}}}}"
+ tc "<p>a0a1a2</p>\n", "{{!for i|3|a\\\n {{$i}}}}"
end
-
+ it 'should parse offset' do
+ tc "<p>0</p>\n", "{{$offset}}"
+ tc "<p>12345-6</p>\n", "12345-{{$offset}}"
+ tc "<p>žížala-7</p>\n", "žížala-{{$offset}}"
+ tc "<p><strong>B</strong>-6</p>\n", "**B**-{{$offset}}"
+ tc "<p><a href=\"L\">L</a>-6</p>\n", "[[L]]-{{$offset}}"
+ tc "<p><a href=\"L\">4</a></p>\n", "[[L|{{$offset}}]]"
+ tc "<p><a href=\"L\">3</a></p>\n", "[L|{{$offset}}]"
+ tc "<p><strong>B</strong><a href=\"L\">9</a></p>\n", "**B**[[L|{{$offset}}]]"
+ tc "<ul><li>2</li>\n</ul>\n", "* {{$offset}}"
+ tc "<h1>2</h1>", "= {{$offset}} ="
+ tc "<h1><strong>B</strong> 8</h1>", "= **B** {{$offset}} ="
+ tc "<p>bla</p>\n<h1><strong>B</strong> 8</h1>", "bla\n= **B** {{$offset}} ="
+ tc "<p><blockquote>2</blockquote></p>\n", " {{$offset}}"
+ tc "<table><tr><td>ahoj</td>\n<td>11</td>\n</tr>\n</table>\n", "|| ahoj || {{$offset}} ||"
+ tc "<table><tr><td>ahoj</td>\n<td>13</td>\n</tr>\n</table>\n", "|| ahoj || {{$offset}} ||"
+ tc "<table><tr><td>3</td>\n<td>20</td>\n</tr>\n</table>\n", "|| {{$offset}} || {{$offset}} ||"
+ tc "<table><tr><td>3</td>\n<td>20</td>\n</tr>\n<tr><td>3</td>\n<td>20</td>\n</tr>\n</table>\n",
+ "|| {{$offset}} || {{$offset}} ||\n|| {{$offset}} || {{$offset}} ||"
+ tc "<table><tr><td>3</td>\n</tr>\n</table>\n", "|| {{$offset}} ||"
+ tc "<table><tr><th>3</th>\n</tr>\n</table>\n", "||={{$offset}}=||"
+ tc "<table><tr><th>4</th>\n</tr>\n</table>\n", "||= {{$offset}} =||"
+ tc "<table><tr><td style=\"text-align:right\">3</td>\n</tr>\n</table>\n", "|| {{$offset}}||"
+ 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}}**"
+ 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}}"
+ # in the future:
+ #tc "<p>ble * line one</p>\n<ul><li>line two 8</li>\n</ul>\n" , "ble {{nl2}} {{$offset}}"
+ end
+ it 'should parse macro len' do
+ tc "<p>11</p>\n" , "{{$maclen}}"
+ tc "<p>17</p>\n" , "{{$maclen|12345}}"
+ tc "<p>18</p>\n" , "{{$maclen| 12345}}"
+ tc "<p>19</p>\n" , "{{$maclen | 12345}}"
+ tc "<p>18</p>\n" , "{{$maclen |12345}}"
+ tc "<p>18</p>\n" , "{{$maclen |12345}}"
+ tc "<p>15</p>\n" , "{{$maclen|kuk}}"
+ tc "<p>15</p>\n" , "{{$maclen|123}}"
+ tc "<p>18</p>\n" , "{{$maclen|žížala}}"
+ 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 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}}"
+ tc "<div class=\"math\">\nahoj\n</div>\n<p>4</p>\n" , "$$\nahoj\n$$\n{{$lineno}}", math: true
+ tc "<p>WEST WEST 3</p>\n" , "{{test}}\n{{test}}\n{{$lineno}}"
+ tc "<p>WEST 2</p>\n" , "{{test}}\n{{$lineno}}"
+ tc "<p>line one line two 1</p>\n" , "{{nl}} {{$lineno}}"
+ tc "<ul><li>line one</li>\n<li>line two 1</li>\n</ul>\n" , "{{nl2}} {{$lineno}}"
+ tc "<ul><li>line one</li>\n<li>line two 2</li>\n</ul>\n" , "{{nl2}}\n{{$lineno}}"
+ 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
end
# vim: tw=0