UNPKG

parsing

Version:
57 lines (52 loc) 1.66 kB
/* * Parsing - JSON grammar-based parser * Copyright (c) Dan Phillimore (asmblah) * http://asmblah.github.com/parsing/ * * Released under the MIT license * https://github.com/asmblah/parsing/raw/master/MIT-LICENSE.txt */ 'use strict'; var expect = require('chai').expect, Parser = require('../../../src/Parser'); describe('Parser "oneOf" qualifier', function () { it('should support capturing bounds for every AST node with a single rule', function () { var grammarSpec = { ignore: 'whitespace', rules: { 'my_rule': { components: { oneOf: [ {name: 'your_capture', what: /your\n \w+/}, {name: 'my_capture', what: /my\n \w+/} ] } }, 'whitespace': /\s+/, }, start: 'my_rule', bounds: 'my_bounds' }, options = { captureAllBounds: true }, parser = new Parser(grammarSpec, null, options), code = ' my\n text '; expect(parser.parse(code)).to.deep.equal({ name: 'my_rule', my_capture: 'my\n text', my_bounds: { start: { offset: 2, line: 1, column: 3 }, end: { offset: 10, line: 2, column: 6 } } }); }); });