|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const chai = require('chai'); |
| 4 | +const shallowDeepEqual = require('chai-shallow-deep-equal'); |
| 5 | +const Parser = require('../lib/parser'); |
| 6 | + |
| 7 | +let expect = chai.expect; |
| 8 | + |
| 9 | +describe('Parser → Unicode range', () => { |
| 10 | + |
| 11 | + chai.use(shallowDeepEqual); |
| 12 | + |
| 13 | + let fixtures = [ |
| 14 | + { |
| 15 | + it: 'should parse single codepoint', |
| 16 | + test: 'U+26', |
| 17 | + expected: [ |
| 18 | + { type: 'unicode-range', value: 'U+26' }, |
| 19 | + ] |
| 20 | + }, |
| 21 | + { |
| 22 | + it: 'should parse other single codepoint', |
| 23 | + test: 'U+0-7F', |
| 24 | + expected: [ |
| 25 | + { type: 'unicode-range', value: 'U+0-7F' }, |
| 26 | + ] |
| 27 | + }, |
| 28 | + { |
| 29 | + it: 'should parse codepoint range', |
| 30 | + test: 'U+0025-00FF', |
| 31 | + expected: [ |
| 32 | + { type: 'unicode-range', value: 'U+0025-00FF' }, |
| 33 | + ] |
| 34 | + }, |
| 35 | + { |
| 36 | + it: 'should parse wildcard range', |
| 37 | + test: 'U+4??', |
| 38 | + expected: [ |
| 39 | + { type: 'unicode-range', value: 'U+4??' }, |
| 40 | + ] |
| 41 | + }, |
| 42 | + { |
| 43 | + it: 'should parse multiple values', |
| 44 | + test: 'U+0025-00FF, U+4??', |
| 45 | + expected: [ |
| 46 | + { type: 'unicode-range', value: 'U+0025-00FF' }, |
| 47 | + { type: 'comma', value: ',', raws: { before: '', after: '' } }, |
| 48 | + { type: 'unicode-range', value: 'U+4??', raws: { before: ' ', after: '' } }, |
| 49 | + ] |
| 50 | + } |
| 51 | + ]; |
| 52 | + |
| 53 | + fixtures.forEach((fixture) => { |
| 54 | + it(fixture.it, () => { |
| 55 | + let ast = new Parser(fixture.test).parse(); |
| 56 | + |
| 57 | + ast.first.walk((node, index) => { |
| 58 | + let expected = fixture.expected[index]; |
| 59 | + |
| 60 | + if (expected) { |
| 61 | + expect(node).to.shallowDeepEqual(expected); |
| 62 | + } |
| 63 | + }); |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | +}); |
0 commit comments