[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-8d59dc4de5201274e310e4c54b9627a8934c3b88527886e3b421487c677d23eb.svg)](https://classroom.github.com/a/fzrjycLm)
[![Open in Codespaces](https://classroom.github.com/assets/launch-codespace-f4981d0f882b2a3f0472912d15f9806d57e124e0fc890972558857b51b24a6f9.svg)](https://classroom.github.com/open-in-codespaces?assignment_repo_id=10591016)
## constant-folding

## Installation
npm install @alu0100953275/constant-folding@lastest

## Usage as executable:
- bash:
  
```bash
$ ./bin/constant-folding-cli.js input.js output.js 
File read succesfully
Output written succesfully in output.js
```

- input.js:
  
```javascript
var f = 3+null;
var e = 4 | 3;
var d = 3+"c";
var b = 9 +1;
var a = 2+3*5+b;
```

- output.js:
  
```javascript
var f = 3;
var e = 7;
var d = '3c';
var b = 10;
var a = 17 + b;
```

## Usage from code:

```javascript
const constantFolding = require('constant-folding');
const input = `
var f = 3+null;
var e = 4 | 3;
var d = 3+"c";
var b = 9 +1;
var a = 2+3*5+b;
`;

console.log(constantFolding(input));
/*
  var f = 3;
  var e = 7;
  var d = '3c';
  var b = 10;
  var a = 17 + b;
  */
```

[The documentation of the function](https://ull-esit-pl-2021.github.io/constant-folding-module-alu0100953275/).

## Author

alu0100953275@ull.edu.es 

## Tests

- tests.js:

```javascript
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;`;
```

- run test:
  
```bash
$ npm run test

> @alu0100953275/constant-folding@1.1.0 test
> mocha



  constantFolding tests
    ✔ works correctly with normal functions 1
    ✔ works correctly with normal functions 2
    ✔ works correctly with normal functions 3
    ✔ works correctly with normal functions 4
    ✔ works correctly with normal functions 5
    ✔ works correctly with normal functions 6


  6 passing (34ms)
```