// Generated by ReScript, PLEASE EDIT WITH CARE

import * as Mocha from "mocha";
import * as Belt_Int from "@rescript/runtime/lib/es6/Belt_Int.mjs";
import * as Test_utils from "./test_utils.mjs";
import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.mjs";

let Inline_record = /* @__PURE__ */Primitive_exceptions.create("Record_extension_test.Inline_record");

let SinglePayload = /* @__PURE__ */Primitive_exceptions.create("Record_extension_test.SinglePayload");

let TuplePayload = /* @__PURE__ */Primitive_exceptions.create("Record_extension_test.TuplePayload");

function f(x) {
  if (x.RE_EXN_ID === Inline_record) {
    let y = Belt_Int.fromString(x.y);
    if (y !== undefined) {
      return x.x + y | 0;
    } else {
      return;
    }
  }
  if (x.RE_EXN_ID === SinglePayload) {
    return Belt_Int.fromString(x._1);
  }
  if (x.RE_EXN_ID !== TuplePayload) {
    return;
  }
  let v1 = Belt_Int.fromString(x._2);
  if (v1 !== undefined) {
    return x._1 + v1 | 0;
  }
}

Mocha.describe("File \"record_extension_test.res\", line 25, characters 9-16", () => {
  Mocha.test("record extension", () => {
    Test_utils.eq("File \"record_extension_test.res\", line 27, characters 7-14", f({
      RE_EXN_ID: Inline_record,
      x: 3,
      y: "4"
    }), 7);
    Test_utils.eq("File \"record_extension_test.res\", line 28, characters 7-14", f({
      RE_EXN_ID: SinglePayload,
      _1: "1"
    }), 1);
    Test_utils.eq("File \"record_extension_test.res\", line 29, characters 7-14", f({
      RE_EXN_ID: TuplePayload,
      _1: 1,
      _2: "2"
    }), 3);
  });
});

function f2(x) {
  if (typeof x !== "object" || x.TAG !== "C") {
    return 0;
  } else {
    return x.x;
  }
}

function f2_with(x) {
  if (typeof x !== "object" || x.TAG !== "C") {
    return x;
  } else {
    return {
      TAG: "C",
      x: 0,
      y: x.y
    };
  }
}

let A = /* @__PURE__ */Primitive_exceptions.create("Record_extension_test.A");

let B = /* @__PURE__ */Primitive_exceptions.create("Record_extension_test.B");

let C = /* @__PURE__ */Primitive_exceptions.create("Record_extension_test.C");

function u(f) {
  try {
    return f();
  } catch (raw_x) {
    let x = Primitive_exceptions.internalToException(raw_x);
    if (x.RE_EXN_ID === A) {
      return x.name + x.x | 0;
    } else if (x.RE_EXN_ID === B) {
      return x._1 + x._2 | 0;
    } else if (x.RE_EXN_ID === C) {
      return x.name;
    } else {
      return -1;
    }
  }
}

Mocha.describe("File \"record_extension_test.res\", line 68, characters 9-16", () => {
  Mocha.test("record extension with exceptions", () => {
    Test_utils.eq("File \"record_extension_test.res\", line 70, characters 7-14", u(() => {
      throw {
        RE_EXN_ID: A,
        name: 1,
        x: 1,
        Error: new Error()
      };
    }), 2);
    Test_utils.eq("File \"record_extension_test.res\", line 71, characters 7-14", u(() => {
      throw {
        RE_EXN_ID: B,
        _1: 1,
        _2: 2,
        Error: new Error()
      };
    }), 3);
    Test_utils.eq("File \"record_extension_test.res\", line 72, characters 7-14", u(() => {
      throw {
        RE_EXN_ID: C,
        name: 4,
        Error: new Error()
      };
    }), 4);
  });
});

export {
  Inline_record,
  SinglePayload,
  TuplePayload,
  f,
  f2,
  f2_with,
  A,
  B,
  C,
  u,
}
/*  Not a pure module */
