"use strict";

/* eslint-disable max-lines */
const terser = require('terser');

describe('normal for loop', () => {
  it('minimize variable names inside the loop  when using let type', () => {
    const code = `
    for (let book = 0; book < 4; book += 1) {
       console.log(book);
    };
    `;
    return terser.minify(code).then(minify => {
      expect(minify.code).toBe('for(let o=0;o<4;o+=1)console.log(o);');
    });
  });
  it('for loop with variable keyword var', () => {
    const code = `
    for (var book = 0; book < 4; book += 1) {
       console.log(book);
    };
    `;
    return terser.minify(code).then(minify => {
      expect(minify.code).toBe('for(var book=0;book<4;book+=1)console.log(book);');
    });
  });
  it('remove unused variable with keyword let and const', () => {
    const code = `
    for (let number = 0;number>28;number++){
        console.log(number);
        let number2 = 28;
        const number3 = 32;
    };
    `;
    return terser.minify(code).then(minify => {
      expect(minify.code).toBe('for(let o=0;o>28;o++){console.log(o)}');
    });
  });
  it('take unused variable with keyword var', () => {
    const code = `
    for (let number = 0;number>28;number++){
        console.log(number);
        var number2 = 28;
        var number3 = 32;
    };
    `;
    return terser.minify(code).then(minify => {
      expect(minify.code).toBe('for(let e=0;e>28;e++){console.log(e);var number2=28,number3=32}');
    });
  });
  it('remove unused and unwanted codes like if statement', () => {
    const code = `
    for (let number = 0;number>28;number++){
        console.log(number);
        if(true){
            let i = 0;
        }
    };
    `;
    return terser.minify(code).then(minify => {
      expect(minify.code).toBe('for(let o=0;o>28;o++){console.log(o)}');
    });
  });
  it('using break in loops', () => {
    const code = `
    for (let number = 0;number>28;number++){
        console.log(number);
        break;
    };
    `;
    return terser.minify(code).then(minify => {
      expect(minify.code).toBe('for(let o=0;o>28;o++){console.log(o);break}');
    });
  });
  it('using breaks in loops with an condition', () => {
    const code = `
    for (let number = 0;number>28;number++){
        console.log(number);
        if(number != 0)
        break;
    };
    `;
    return terser.minify(code).then(minify => {
      expect(minify.code).toBe('for(let o=0;o>28&&(console.log(o),0==o);o++);');
    });
  });
  it('using continue in loops with an condition', () => {
    const code = `
    for (let number = 0;number>28;number++){
        if(number > 0)
        continue;
        console.log(2);
    };
    `;
    return terser.minify(code).then(minify => {
      expect(minify.code).toBe('for(let o=0;o>28;o++)o>0||console.log(2);');
    });
  });
  it('remove the code which are write below the continue', () => {
    const code = `
    for (let number = 0;number>28;number++){
        console.log(2)
        continue;
        console.log(3)
      
    };
    `;
    return terser.minify(code).then(minify => {
      expect(minify.code).toBe('for(let o=0;o>28;o++)console.log(2);');
    });
  });
});