diff --git a/test/01_basics_mocha.coffee b/test/01_basics_mocha.coffee index b42b476..b19f6b6 100644 --- a/test/01_basics_mocha.coffee +++ b/test/01_basics_mocha.coffee @@ -3,99 +3,16 @@ assert = chai.assert expect = chai.expect should = chai.should() util = require 'util' +fs = require 'fs' +path = require 'path' tumble = require('../lib/tumble').parse; parse = require('../lib/parser'); -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': '' - 'output': '' - 'data': {'title': 'AAA'} - 'description': "a conditional block" - } - - { - 'input': '' - 'output': '' - 'data': {'title': ''} - 'description': "a conditional block with no input" - } - - - { - 'input': '' - 'output': '' - 'data': {'stories': {'title': ''}} - 'description': "a descendent block" - } - - - { - 'input': '' - 'output': '' - 'data': {'stories': {'title': 'AAA'}} - 'description': "a descendent block 2" - } - - { - 'input': '' - 'output': '' - 'data': {'stories': [{'title': ''}]} - 'description': "an iterative block" - } - - - { - 'input': '' - 'output': '' - 'data': {'stories': [{'title': 'AAA'}, {'title': 'CCC'}]}, - 'description': "an iterative block 2" - } - - { - 'input': '' - 'output': '' - '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" - } -] - +test_data = JSON.parse(fs.readFileSync(path.join(__dirname, 'data.json'), 'utf-8')) describe "Basic Functionality", -> - for data in test_data + for data in test_data.data do (data) -> it "should work with #{data.description}", -> r = parse(tumble(data.input), data.data) diff --git a/test/data.json b/test/data.json new file mode 100644 index 0000000..80b39bd --- /dev/null +++ b/test/data.json @@ -0,0 +1,118 @@ +{ + "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": "", + "output": "", + "data": { + "title": "AAA" + }, + "description": "a conditional block" + }, + { + "input": "", + "output": "", + "data": { + "title": "" + }, + "description": "a conditional block with no input" + }, + { + "input": "", + "output": "", + "data": { + "stories": { + "title": "" + } + }, + "description": "a descendent block" + }, + { + "input": "", + "output": "", + "data": { + "stories": { + "title": "AAA" + } + }, + "description": "a descendent block 2" + }, + { + "input": "", + "output": "", + "data": { + "stories": [ + { + "title": "" + } + ] + }, + "description": "an iterative block" + }, + { + "input": "", + "output": "", + "data": { + "stories": [ + { + "title": "AAA" + }, + { + "title": "CCC" + } + ] + }, + "description": "an iterative block 2" + }, + { + "input": "", + "output": "", + "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" + } + ] +}