tumble/test/01_basics_mocha.coffee

35 lines
1.3 KiB
CoffeeScript
Raw Normal View History

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-05-01 05:08:58 +00:00
fs = require 'fs'
path = require 'path'
2013-03-06 17:57:12 +00:00
2013-04-17 17:10:06 +00:00
tumble = require('../lib/tumble').parse;
2013-04-27 20:53:31 +00:00
parse = require('../lib/parser');
2013-03-06 17:57:12 +00:00
2013-05-01 05:08:58 +00:00
test_data = JSON.parse(fs.readFileSync(path.join(__dirname, 'data.json'), 'utf-8'))
describe "Basic Functionality", ->
2013-05-01 05:08:58 +00:00
for data in test_data.data
do (data) ->
it "should work with #{data.description}", ->
2013-04-28 22:23:35 +00:00
r = parse(tumble(data.input), data.data)
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
2013-04-28 22:23:35 +00:00
r = parse(tumble(data.input), data.data)
2013-04-18 05:05:15 +00:00
assert.ok false, "It did not throw the exception"
catch err
2013-04-27 20:53:31 +00:00
assert.ok err.id == 'recursion-error', "Recursion depth exeception thrown."