tumble/test/01_basics_mocha.coffee

36 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
2016-06-29 14:34:18 +00:00
tumble = require('../lib/lexer').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}", ->
2016-06-29 14:34:18 +00:00
r = tumble(data.input)
r = parse(r, 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
2016-06-29 14:34:18 +00:00
assert.ok true, "Recursion depth exeception thrown."