Put tests into a different file.

This commit is contained in:
Elf M. Sternberg 2013-04-30 22:08:58 -07:00
parent 033c3f196d
commit fac48b727a
2 changed files with 122 additions and 87 deletions

View File

@ -3,99 +3,16 @@ assert = chai.assert
expect = chai.expect expect = chai.expect
should = chai.should() should = chai.should()
util = require 'util' util = require 'util'
fs = require 'fs'
path = require 'path'
tumble = require('../lib/tumble').parse; tumble = require('../lib/tumble').parse;
parse = require('../lib/parser'); parse = require('../lib/parser');
test_data = [ test_data = JSON.parse(fs.readFileSync(path.join(__dirname, 'data.json'), 'utf-8'))
{
'input': '',
'output': '',
'description': "no input"
}
{
'input': '<html>',
'output': '<html>',
'description': "just text"
}
{
'input': '<h1>{name}</h1>'
'output': '<h1>Elf Sternberg</h1>'
'data': {'name': 'Elf Sternberg'},
'description': "a simple substitution"
}
{
'input': '<h1>{title} {name}</h1>'
'output': '<h1>Mr. Elf Sternberg</h1>'
'data': {'name': 'Elf Sternberg', 'title': 'Mr.'},
'description': "two simple substitutions"
}
{
'input': '<ul>{if:title}{title}BBB{/if:title}</ul>'
'output': '<ul>AAABBB</ul>'
'data': {'title': 'AAA'}
'description': "a conditional block"
}
{
'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"
}
{
'input': "{template:a}{name}{/template:a}F{render:a}"
'output': "FG"
'data': {'name': 'G'}
'description': "A templatized block"
}
]
describe "Basic Functionality", -> describe "Basic Functionality", ->
for data in test_data for data in test_data.data
do (data) -> do (data) ->
it "should work with #{data.description}", -> it "should work with #{data.description}", ->
r = parse(tumble(data.input), data.data) r = parse(tumble(data.input), data.data)

118
test/data.json Normal file
View File

@ -0,0 +1,118 @@
{
"data": [
{
"input": "",
"output": "",
"description": "no input"
},
{
"input": "<html>",
"output": "<html>",
"description": "just text"
},
{
"input": "<h1>{name}</h1>",
"output": "<h1>Elf Sternberg</h1>",
"data": {
"name": "Elf Sternberg"
},
"description": "a simple substitution"
},
{
"input": "<h1>{title} {name}</h1>",
"output": "<h1>Mr. Elf Sternberg</h1>",
"data": {
"name": "Elf Sternberg",
"title": "Mr."
},
"description": "two simple substitutions"
},
{
"input": "<ul>{if:title}{title}BBB{/if:title}</ul>",
"output": "<ul>AAABBB</ul>",
"data": {
"title": "AAA"
},
"description": "a conditional block"
},
{
"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"
},
{
"input": "{template:a}{name}{/template:a}F{render:a}",
"output": "FG",
"data": {
"name": "G"
},
"description": "A templatized block"
}
]
}