UNPKG

@alu0100953275/constant-folding

Version:
36 lines (34 loc) 1.25 kB
const constantFolding = require('../src/constant-folding'); const should = require('chai').should(); const example1 = `a=2*3;`; const example2 = `3+null;`; const example3 = `4 | 3;`; const example4 = `3+"c";`; const example5 = `9 +1;`; const example6 = `2+3*5+b;`; const expectedOutput1 = `a = 6;`; const expectedOutput2 = `3;`; const expectedOutput3 = `7;`; const expectedOutput4 = `'3c';`; const expectedOutput5 = `10;`; const expectedOutput6 = `17 + b;`; describe('constantFolding tests', () => { it('works correctly with normal functions 1', () => { constantFolding(example1).should .equal(expectedOutput1); }); it('works correctly with normal functions 2', () => { constantFolding(example2).should .equal(expectedOutput2); }); it('works correctly with normal functions 3', () => { constantFolding(example3).should .equal(expectedOutput3); }); it('works correctly with normal functions 4', () => { constantFolding(example4).should .equal(expectedOutput4); }); it('works correctly with normal functions 5', () => { constantFolding(example5).should .equal(expectedOutput5); }); it('works correctly with normal functions 6', () => { constantFolding(example6).should .equal(expectedOutput6); }); });