"use strict";

const terser = require('terser');

test('minimize boolean values', () => {
  const code = `
    let a = true;
    let b = false`;
  return terser.minify(code).then(minify => {
    expect(minify.code).toBe('let a=!0,b=!1;');
  });
});
test('terinary operator with var and let', () => {
  const code = `
    var x = 3;
    let a = 1;
    let result = (a == 1) ? true : false
    result = (x == 1) ? true : false;
    `;
  return terser.minify(code).then(minify => {
    expect(minify.code).toBe('var x=3;let a=1,result=1==a;result=1==x;');
  });
});
test('terinary operator with const', () => {
  const code = `
    const x = 3;
    const a = 1;
    let result = (a == 1) ? true : false
    result = (x == 1) ? true : false;
    `;
  return terser.minify(code).then(minify => {
    expect(minify.code).toBe('const x=3,a=1;let result=!0;result=!1;');
  });
});
test('minimize values when using logical and comparision operators', () => {
  const code = `
    let result = (true && true ) ? true : false
    result = (1>2) ? true : false;
    `;
  return terser.minify(code).then(minify => {
    expect(minify.code).toBe('let result=!0;result=!1;');
  });
});