import cloneDeep from "../lib/transformation/util/clone-deep.js";

describe("util", () => {
  it("deep clone", () => {
    const circle = {};
    circle.circle = circle;
    const object = {};

    const ast = {
      type: "Program",
      extra: {
        circle,
        circle2: circle,
      },
      object,
      object2: object,
    };
    const cloned = cloneDeep(ast);

    expect(cloned.object === ast.object).toBe(false);
    expect(cloned.object === cloned.object2).toBe(false);

    expect(cloned.extra.circle === ast.extra.circle).toBe(false);
    expect(cloned.extra.circle === cloned.extra.circle2).toBe(true);
    expect(cloned.extra.circle === cloned.extra.circle.circle).toBe(true);
  });

  it("deep clone circle", () => {
    const circle = {};
    circle.circle = circle;

    const ast = {
      type: "Program",
      circle,
    };
    expect(() => {
      cloneDeep(ast);
    }).toThrow("Babel-deepClone: Cycles are not allowed in AST");
  });
});
