| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- var TextParser = require('seed/src/text-parser'),
- config = require('seed/src/config')
- describe('UNIT: TextNode Parser', function () {
- describe('.parse()', function () {
-
- it('should return null if no interpolate tags are present', function () {
- var result = TextParser.parse('hello no tags')
- assert.strictEqual(result, null)
- })
- it('should ignore escapped tags', function () {
- var result = TextParser.parse('test {{key}} {{hello}}')
- assert.strictEqual(result.length, 3)
- assert.strictEqual(result[2], ' {{hello}}')
- })
- var tokens = TextParser.parse('hello {{a}}! {{ bcd }}{{d.e.f}} {{a + (b || c) ? d : e}} {{>test}}')
-
- it('should extract correct amount of tokens', function () {
- assert.strictEqual(tokens.length, 9)
- })
- it('should extract plain strings', function () {
- assert.strictEqual(typeof tokens[0], 'string')
- assert.strictEqual(typeof tokens[2], 'string')
- assert.strictEqual(typeof tokens[5], 'string')
- assert.strictEqual(typeof tokens[7], 'string')
- })
- it('should extract basic keys', function () {
- assert.strictEqual(tokens[1].key, 'a')
- })
- it('should trim extracted keys', function () {
- assert.strictEqual(tokens[3].key, 'bcd')
- })
- it('should extract nested keys', function () {
- assert.strictEqual(tokens[4].key, 'd.e.f')
- })
- it('should extract expressions', function () {
- assert.strictEqual(tokens[6].key, 'a + (b || c) ? d : e')
- })
- it('should extract partials', function () {
- assert.strictEqual(tokens[8].key, '>test')
- })
- })
- describe('.buildRegex()', function () {
- before(function () {
- config.interpolateTags = {
- open: '<%',
- close: '%>'
- }
- TextParser.buildRegex()
- })
-
- it('should update the interpolate tags and work', function () {
- var tokens = TextParser.parse('hello <%a%>! <% bcd %><%d.e.f%> <%a + (b || c) ? d : e%>')
- assert.strictEqual(tokens.length, 7)
- assert.strictEqual(typeof tokens[0], 'string')
- assert.strictEqual(typeof tokens[2], 'string')
- assert.strictEqual(typeof tokens[5], 'string')
- assert.strictEqual(tokens[1].key, 'a')
- assert.strictEqual(tokens[3].key, 'bcd')
- assert.strictEqual(tokens[4].key, 'd.e.f')
- assert.strictEqual(tokens[6].key, 'a + (b || c) ? d : e')
- })
- after(function () {
- config.interpolateTags = {
- open: '{{',
- close: '}}'
- }
- TextParser.buildRegex()
- })
- })
- })
|