@alu0101350158/constant-folding
Version:
Constant Folding javascript code
55 lines (53 loc) • 1.71 kB
JavaScript
const constantFolding = require('../src/constant-folding');
const should = require('chai').should();
const example1 = `a=2*3;`;
const expectedOutput1 = `a = 6;`;
const example2 = `[1, 2, 3].length;`;
const expectedOutput2 = `3;`;
const example3 = `["a", "b", "c"].join();`;
const expectedOutput3 = `'a,b,c';`;
const example4 = `["a", "b", "c"].join('@');`;
const expectedOutput4 = `'a@b@c';`;
const example5 = `[1, 2, 3][2-1];`;
const expectedOutput5 = `2;`;
const example6 = `[a, b, c].pop();`;
const expectedOutput6 = `c;`;
const example7 = `[a, b, c].reverse();`;
const expectedOutput7 = `[c, b, a];`;
const example10 = `["a", "b", "c"].concat(["d", "e"], "f", "g", ["h"]);`;
const expectedOutput10 = `[
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h'
];`;
/**
* Tests de la funcion constantFolding
*/
describe('constantFolding tests', () => {
it('works correctly with normal functions', () => {
constantFolding(example1).should .equal(expectedOutput1);
});
it('works correctly with array length', () => {
constantFolding(example2).should .equal(expectedOutput2);
});
it('works correctly with array join', () => {
constantFolding(example3).should .equal(expectedOutput3);
});
it('works correctly with array join with arguments', () => {
constantFolding(example4).should .equal(expectedOutput4);
});
it('works correctly with array []', () => {
constantFolding(example5).should .equal(expectedOutput5);
});
it('works correctly with array pop', () => {
constantFolding(example6).should .equal(expectedOutput6);
});
it('works correctly with array concat', () => {
constantFolding(example10).should .equal(expectedOutput10);
});
});