"use strict";

const {
  convertCode
} = require('../utilities');

test('computed-properties', () => {
  const inputCode = `var obj = {
  ["x" + foo]: "heh",
  ["y" + bar]: "noo",
  foo: "foo",
  bar: "bar",
};`;
  const outputCode = `var obj = {
  ["x" + foo]: "heh",
  ["y" + bar]: "noo",
  foo: "foo",
  bar: "bar"
};`;
  expect(convertCode(inputCode)).toBe(outputCode);
});
test('unicode', () => {
  const inputCode = `var string = "foo💩bar";
var match = string.match(/foo(.)bar/u);`;
  const outputCode = `var string = "foo💩bar";
var match = string.match(/foo(.)bar/u);`;
  expect(convertCode(inputCode)).toBe(outputCode);
});
test('destructuring', () => {
  const inputCode = `let { x, y } = obj;
let [a, b, ...rest] = arr;`;
  const outputCode = `let {
  x,
  y
} = obj;
let [a, b, ...rest] = arr;`;
  expect(convertCode(inputCode)).toBe(outputCode);
});
test('duplicate-keys', () => {
  const inputCode = `var x = { a: 5, a: 6};
var y = {
  get a() {},
  set a(x) {},
  a: 3,
};`;
  const outputCode = `var x = {
  a: 5,
  a: 6
};
var y = {
  get a() {},
  set a(x) {},
  a: 3
};`;
  expect(convertCode(inputCode)).toBe(outputCode);
});
test('instance of', () => {
  const inputCode = 'foo instanceof Bar;';
  const outputCode = 'foo instanceof Bar;';
  expect(convertCode(inputCode)).toBe(outputCode);
});
test('function name', () => {
  const inputCode = 'let number = x => x;';
  const outputCode = 'let number = x => x;';
  expect(convertCode(inputCode)).toBe(outputCode);
});
test('template literals', () => {
  // eslint-disable-next-line no-template-curly-in-string
  const inputCode = '`foo${bar}`'; // eslint-disable-next-line no-template-curly-in-string

  const outputCode = '`foo${bar}`;';
  expect(convertCode(inputCode)).toBe(outputCode);
});
test('shorthand properties', () => {
  const inputCode = 'var o = { a, b, c };';
  const outputCode = `var o = {
  a,
  b,
  c
};`;
  expect(convertCode(inputCode)).toBe(outputCode);
});