chai = require 'chai' assert = chai.assert expect = chai.expect should = chai.should() util = require 'util' 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" } ] describe "Basic Functionality", -> for data in test_data do (data) -> it "should work with #{data.description}", -> r = tumble(data.input) r = parse(r, data.data) r.should.equal data.output 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) r = parse(r, data.data) assert.ok false, "It did not throw the exception" catch err assert.ok err.id == 'recursion-error', "Recursion depth exeception thrown."