2013-03-06 17:57:12 +00:00
|
|
|
chai = require 'chai'
|
|
|
|
assert = chai.assert
|
|
|
|
expect = chai.expect
|
|
|
|
should = chai.should()
|
2013-04-18 05:05:15 +00:00
|
|
|
util = require 'util'
|
2013-03-06 17:57:12 +00:00
|
|
|
|
2013-04-17 17:10:06 +00:00
|
|
|
tumble = require('../lib/tumble').parse;
|
2013-03-06 17:57:12 +00:00
|
|
|
|
2013-03-06 18:56:04 +00:00
|
|
|
test_data = [
|
|
|
|
{
|
|
|
|
'input': '',
|
2013-03-31 03:30:58 +00:00
|
|
|
'output': '',
|
|
|
|
'description': "no input"
|
2013-03-06 18:56:04 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
'input': '<html>',
|
|
|
|
'output': '<html>',
|
2013-03-31 03:30:58 +00:00
|
|
|
'description': "just text"
|
2013-03-06 18:56:04 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
'input': '<h1>{name}</h1>'
|
|
|
|
'output': '<h1>Elf Sternberg</h1>'
|
2013-03-31 03:30:58 +00:00
|
|
|
'data': {'name': 'Elf Sternberg'},
|
|
|
|
'description': "a simple substitution"
|
2013-03-06 18:56:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
'input': '<h1>{title} {name}</h1>'
|
|
|
|
'output': '<h1>Mr. Elf Sternberg</h1>'
|
2013-03-31 03:30:58 +00:00
|
|
|
'data': {'name': 'Elf Sternberg', 'title': 'Mr.'},
|
|
|
|
'description': "two simple substitutions"
|
2013-03-06 18:56:04 +00:00
|
|
|
}
|
|
|
|
|
2013-04-17 17:10:06 +00:00
|
|
|
|
2013-03-06 18:56:04 +00:00
|
|
|
{
|
2013-04-17 17:10:06 +00:00
|
|
|
'input': '<ul>{if:title}{title}BBB{/if:title}</ul>'
|
2013-03-06 18:56:04 +00:00
|
|
|
'output': '<ul>AAABBB</ul>'
|
2013-04-17 17:10:06 +00:00
|
|
|
'data': {'title': 'AAA'}
|
2013-03-31 03:30:58 +00:00
|
|
|
'description': "a conditional block"
|
2013-04-17 17:10:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
'input': '<ul>{if:title}{title}BBB{/if:title}</ul>'
|
|
|
|
'output': '<ul></ul>'
|
|
|
|
'data': {'title': ''}
|
|
|
|
'description': "a conditional block with no input"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
'input': '<ul>{block:stories}{title}{/block:stories}</ul>'
|
|
|
|
'output': '<ul></ul>'
|
|
|
|
'data': {'stories': {'title': ''}}
|
|
|
|
'description': "a descendent block"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
'input': '<ul>{block:stories}{title}BBB{/block:stories}</ul>'
|
|
|
|
'output': '<ul>AAABBB</ul>'
|
|
|
|
'data': {'stories': {'title': 'AAA'}}
|
|
|
|
'description': "a descendent block 2"
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
'input': '<ul>{many:stories}{title}{/many:stories}</ul>'
|
|
|
|
'output': '<ul></ul>'
|
|
|
|
'data': {'stories': [{'title': ''}]}
|
|
|
|
'description': "an iterative block"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
'input': '<ul>{many:stories}{title}BBB{/many:stories}</ul>'
|
|
|
|
'output': '<ul>AAABBBCCCBBB</ul>'
|
|
|
|
'data': {'stories': [{'title': 'AAA'}, {'title': 'CCC'}]},
|
|
|
|
'description': "an iterative block 2"
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
'input': '<ul>{author}{many:stories}{title}BBB{author}{/many:stories}</ul>'
|
|
|
|
'output': '<ul>DDDAAABBBDDDCCCBBBDDD</ul>'
|
|
|
|
'data': {'author': 'DDD', 'stories': [{'title': 'AAA'}, {'title': 'CCC'}]},
|
|
|
|
'description': "an iterative block with ascent"
|
|
|
|
}
|
|
|
|
|
2013-04-18 05:37:49 +00:00
|
|
|
{
|
|
|
|
'input': "{template:a}{name}{/template:a}F{render:a}"
|
|
|
|
'output': "FG"
|
|
|
|
'data': {'name': 'G'}
|
|
|
|
'description': "A templatized block"
|
|
|
|
}
|
2013-04-17 17:10:06 +00:00
|
|
|
]
|
2013-03-06 18:56:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
describe "Basic Functionality", ->
|
|
|
|
for data in test_data
|
2013-03-31 03:30:58 +00:00
|
|
|
do (data) ->
|
|
|
|
it "should work with #{data.description}", ->
|
2013-04-18 05:05:15 +00:00
|
|
|
r = tumble(data.input)
|
|
|
|
r = r(data.data)
|
2013-03-31 03:30:58 +00:00
|
|
|
r.should.equal data.output
|
2013-04-18 05:05:15 +00:00
|
|
|
|
|
|
|
describe "Check for recursion", ->
|
|
|
|
data = {
|
|
|
|
'input': '{block:a}{block:a}{block:a}{block:a}{block:a}{block:a}{block:a}{block:a}{block:a}{block:a}{block:a}{a}{/block:a}{/block:a}{/block:a}{/block:a}{/block:a}{/block:a}{/block:a}{/block:a}{/block:a}{/block:a}{/block:a}',
|
|
|
|
'output': '',
|
|
|
|
'data': {'a': {'a': {'a': {'a': {'a': {'a': {'a': {'a': {'a': {'a': {'a': {'a': 'b'}}}}}}}}}}}},
|
|
|
|
'description': "descent error"
|
|
|
|
}
|
|
|
|
do (data) ->
|
|
|
|
it "should catch an exception", ->
|
|
|
|
try
|
|
|
|
r = tumble(data.input)(data.data)
|
|
|
|
assert.ok false, "It did not throw the exception"
|
|
|
|
catch err
|
|
|
|
assert.ok true, "Recursion depth exeception thrown."
|