|
| 1 | +var should = require('chai').should(); |
| 2 | +var expect = require('chai').expect; |
| 3 | +var simplepeg = require('./../src/speg'); |
| 4 | +var ex = require('./../src/exceptions'); |
| 5 | + |
| 6 | +describe('exceptions - ', function() { |
| 7 | + it('should throw correct error when grammar is wrong',function() { |
| 8 | + expect(function() { |
| 9 | + var parser = new simplepeg.SPEG(); |
| 10 | + parser.parse_grammar('!!!'); |
| 11 | + }).to.throw(ex.GrammarParseError); |
| 12 | + }); |
| 13 | + it('should throw correct error when text is wrong',function() { |
| 14 | + expect(function() { |
| 15 | + var parser = new simplepeg.SPEG(); |
| 16 | + parser.parse_grammar('GRAMMAR test a -> "A";'); |
| 17 | + parser.parse_text('B'); |
| 18 | + }).to.throw(ex.TextParseError); |
| 19 | + }); |
| 20 | + it('should throw when text called before grammar',function() { |
| 21 | + expect(function() { |
| 22 | + var parser = new simplepeg.SPEG(); |
| 23 | + parser.parse_text('B'); |
| 24 | + }).to.throw(Error); |
| 25 | + }); |
| 26 | + it('should (speg.parse) throw correct error when grammar is wrong',function() { |
| 27 | + expect(function() { |
| 28 | + var parser = new simplepeg.SPEG(); |
| 29 | + parser.parse('!!!', 'B'); |
| 30 | + }).to.throw(ex.GrammarParseError); |
| 31 | + }); |
| 32 | + it('should (speg.parse) throw correct error when text is wrong',function() { |
| 33 | + expect(function() { |
| 34 | + var parser = new simplepeg.SPEG(); |
| 35 | + parser.parse('GRAMMAR test a -> "A";', 'B'); |
| 36 | + }).to.throw(ex.TextParseError); |
| 37 | + }); |
| 38 | +}); |
0 commit comments