UNPKG

@alu0101051420/constant-folding

Version:
41 lines (35 loc) 1.51 kB
const constantFolding = require('../src/constant-folding'); const should = require('chai').should(); const binaryExamples = [ { "input": "a=2*3;", "result": "a = 6;" }, { "input": "a=2+3;", "result": "a = 5;" }, { "input": "a=2/3;", "result": "a = 0.6666666666666666;" } ] const arrayExamples = [ { "input": `['a', 'b', 'c'].concat(['d', 'e'], 'f', 'g', ['h']);`, "result": "[\n a,\n b,\n c,\n d,\n e,\n f,\n g,\n h\n];" }, { "input": `["a", "b", "c"].join();`, "result": "a, b, c;" }, { "input": `["a", "b", "c"].join('&');`, "result": "a & b & c;" }, { "input": `[1, 2, 3].length;`, "result": "3;" }, { "input": `[1, 2, 3][2 - 1];`, "result": "2;" }, { "input": `[1, 2, 3].shift();`, "result": "1;" }, { "input": `[1, 2, 3].slice(0, 1 + 1); `, "result": "[\n 1,\n 2\n];" }, { "input": `['a', 'b', 'c'].pop(); `, "result": "c;" }, { "input": `['a', 'b', 'c'].reverse(); `, "result": "[\n c,\n b,\n a\n];" }, ] it('constantFolding module importing correctly', () => { constantFolding.should.not.equal(undefined); }) describe('constantFolding binary operation tests', () => { binaryExamples.forEach((example) => { it(example.input, () => { constantFolding(example.input).should.equal(example.result); }) }) }); describe('constantFolding array operation tests', () => { arrayExamples.forEach((example) => { it(example.input, () => { constantFolding(example.input).should.equal(example.result); }) }) });