|
| 1 | +import {expect} from 'chai'; |
| 2 | +import { |
| 3 | + encode, |
| 4 | + decode, |
| 5 | + isValid |
| 6 | +} from '../esnext'; |
| 7 | + |
| 8 | +describe('isValid', () => { |
| 9 | + it('should be false', () => { |
| 10 | + expect(isValid('1.1.1', 0)).to.be.false; |
| 11 | + expect(isValid('1.1.', 1)).to.be.false; |
| 12 | + expect(isValid('1.1.12', 1)).to.be.false; |
| 13 | + expect(isValid('1.1.1.1', 1)).to.be.false; |
| 14 | + expect(isValid('1.1.1-a', 1)).to.be.false; |
| 15 | + expect(isValid('1.12.1-a', 1)).to.be.false; |
| 16 | + }); |
| 17 | + |
| 18 | + it('should be true', () => { |
| 19 | + expect(isValid('1.1.1', 1)).to.be.true; |
| 20 | + expect(isValid('0.0.1', 1)).to.be.true; |
| 21 | + expect(isValid('12.1.1', 2)).to.be.true; |
| 22 | + }); |
| 23 | +}); |
| 24 | + |
| 25 | +describe('encode', () => { |
| 26 | + it('should throw error', () => { |
| 27 | + expect(() => encode('1', 1)).to.throw('not valid arguments'); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should encode', () => { |
| 31 | + expect(encode('0.0.0', 1)).to.be.eq(0); |
| 32 | + expect(encode('0.0.1', 1)).to.be.eq(1); |
| 33 | + expect(encode('0.1.1', 1)).to.be.eq(11); |
| 34 | + expect(encode('1.1.1', 1)).to.be.eq(111); |
| 35 | + expect(encode('1.1.1', 2)).to.be.eq(10101); |
| 36 | + }); |
| 37 | +}); |
| 38 | + |
| 39 | +describe('decode', () => { |
| 40 | + it('should throw error', () => { |
| 41 | + expect(() => decode(1111, 1)).to.throw('not valid arguments'); |
| 42 | + }); |
| 43 | + |
| 44 | + it('should decode', () => { |
| 45 | + expect(decode(0, 1)).to.be.eq('0.0.0'); |
| 46 | + expect(decode(1, 1)).to.be.eq('0.0.1'); |
| 47 | + expect(decode(11, 1)).to.be.eq('0.1.1'); |
| 48 | + expect(decode(111, 1)).to.be.eq('1.1.1'); |
| 49 | + expect(decode(10101, 2)).to.be.eq('1.1.1'); |
| 50 | + }); |
| 51 | +}); |
0 commit comments