chai = require 'chai'
assert = chai.assert
expect = chai.expect
should = chai.should()
tumble = require('../lib/tumble').parse;
test_data = [
{
'input': '',
'output': '',
'description': "no input"
}
{
'input': '',
'output': '',
'description': "just text"
}
{
'input': '
{name}
'
'output': 'Elf Sternberg
'
'data': {'name': 'Elf Sternberg'},
'description': "a simple substitution"
}
{
'input': '{title} {name}
'
'output': 'Mr. Elf Sternberg
'
'data': {'name': 'Elf Sternberg', 'title': 'Mr.'},
'description': "two simple substitutions"
}
{
'input': '{if:title}{title}BBB{/if:title}
'
'output': ''
'data': {'title': 'AAA'}
'description': "a conditional block"
}
{
'input': '{if:title}{title}BBB{/if:title}
'
'output': ''
'data': {'title': ''}
'description': "a conditional block with no input"
}
{
'input': '{block:stories}{title}{/block:stories}
'
'output': ''
'data': {'stories': {'title': ''}}
'description': "a descendent block"
}
{
'input': '{block:stories}{title}BBB{/block:stories}
'
'output': ''
'data': {'stories': {'title': 'AAA'}}
'description': "a descendent block 2"
}
{
'input': '{many:stories}{title}{/many:stories}
'
'output': ''
'data': {'stories': [{'title': ''}]}
'description': "an iterative block"
}
{
'input': '{many:stories}{title}BBB{/many:stories}
'
'output': ''
'data': {'stories': [{'title': 'AAA'}, {'title': 'CCC'}]},
'description': "an iterative block 2"
}
{
'input': '{author}{many:stories}{title}BBB{author}{/many:stories}
'
'output': ''
'data': {'author': 'DDD', 'stories': [{'title': 'AAA'}, {'title': 'CCC'}]},
'description': "an iterative block with ascent"
}
]
describe "Basic Functionality", ->
for data in test_data
do (data) ->
it "should work with #{data.description}", ->
r = tumble(data.input)(data.data)
r.should.equal data.output