|
| 1 | +var parser = require('../../src/parser') |
| 2 | +var { expect } = require('chai') |
| 3 | + |
| 4 | +describe('parser.js', () => { |
| 5 | + describe('#parse', () => { |
| 6 | + describe('Correct types', () => { |
| 7 | + it('Should parse numbers', () => { |
| 8 | + let object = parser.parse(10) |
| 9 | + |
| 10 | + expect(object.value).to.be.a('number') |
| 11 | + expect(object.type).to.be.a('string') |
| 12 | + |
| 13 | + expect(object.value).to.equal(10) |
| 14 | + expect(object.type).to.equal('px') |
| 15 | + }) |
| 16 | + |
| 17 | + it('Should parse strings', () => { |
| 18 | + let object = parser.parse('10') |
| 19 | + |
| 20 | + expect(object.value).to.be.a('number') |
| 21 | + expect(object.type).to.be.a('string') |
| 22 | + |
| 23 | + expect(object.value).to.equal(10) |
| 24 | + expect(object.type).to.equal('px') |
| 25 | + }) |
| 26 | + |
| 27 | + it ('Should parse "auto" string, auto => {type: "auto", value: 0}', () => { |
| 28 | + let object = parser.parse('auto') |
| 29 | + |
| 30 | + expect(object.value).to.equal(0) |
| 31 | + expect(object.type).to.equal('auto') |
| 32 | + }) |
| 33 | + |
| 34 | + it ('Should parse wrong types', () => { |
| 35 | + let nullValue = parser.parse(null) |
| 36 | + let booleanValue = parser.parse(false) |
| 37 | + |
| 38 | + expect(nullValue.value).to.equal(null) |
| 39 | + expect(nullValue.type).to.equal('') |
| 40 | + |
| 41 | + expect(booleanValue.value).to.equal(false) |
| 42 | + expect(booleanValue.type).to.equal('') |
| 43 | + }) |
| 44 | + }) |
| 45 | + |
| 46 | + describe('Parsing suffixed string', () => { |
| 47 | + it ('Should parse "px"', () => { |
| 48 | + let object = parser.parse('10px') |
| 49 | + |
| 50 | + expect(object.value).to.equal(10) |
| 51 | + expect(object.type).to.equal('px') |
| 52 | + }) |
| 53 | + |
| 54 | + it ('Should parse "%"', () => { |
| 55 | + let object = parser.parse('10%') |
| 56 | + |
| 57 | + expect(object.value).to.equal(10) |
| 58 | + expect(object.type).to.equal('%') |
| 59 | + }) |
| 60 | + |
| 61 | + it ('Should not parse "%px"', () => { |
| 62 | + let object = parser.parse('10%px') |
| 63 | + |
| 64 | + expect(object.value).to.be.a('string') |
| 65 | + expect(object.type).to.equal('') |
| 66 | + }) |
| 67 | + }) |
| 68 | + }) |
| 69 | +}) |
0 commit comments