WaypointError_test.res.mjs

 1// Generated by ReScript, PLEASE EDIT WITH CARE
 2
 3import * as Vitest from "vitest";
 4import * as Waypoint from "../src/ffi/Waypoint.res.mjs";
 5import * as Belt_Result from "@rescript/runtime/lib/es6/Belt_Result.js";
 6
 7Vitest.describe("Waypoint error handling", () => {
 8  Vitest.test("parses waypoint with RouteTooFar error", ctx => {
 9    let json = JSON.parse(`{"id":"wp-1","point":[10.0,20.0],"label":"Test","gid":"gid-1","country":"US","cons":[],"nonroutable":false,"error":["RouteTooFar"]}`);
10    let result = Waypoint.fromJSON(json);
11    ctx.expect(Belt_Result.isOk(result)).toBe(true);
12    if (result.TAG !== "Ok") {
13      return;
14    }
15    ctx.expect(result._0.error).toEqual(["RouteTooFar"]);
16  });
17  Vitest.test("parses waypoint without error field", ctx => {
18    let json = JSON.parse(`{"id":"wp-1","point":[10.0,20.0],"label":"Test","gid":"gid-1","country":"US","cons":[],"nonroutable":false}`);
19    let result = Waypoint.fromJSON(json);
20    ctx.expect(Belt_Result.isOk(result)).toBe(true);
21    if (result.TAG !== "Ok") {
22      return;
23    }
24    ctx.expect(result._0.error).toEqual(undefined);
25  });
26  Vitest.test("parses waypoint with empty error array", ctx => {
27    let json = JSON.parse(`{"id":"wp-1","point":[10.0,20.0],"label":"Test","gid":"gid-1","country":"US","cons":[],"nonroutable":false,"error":[]}`);
28    let result = Waypoint.fromJSON(json);
29    ctx.expect(Belt_Result.isOk(result)).toBe(true);
30    if (result.TAG !== "Ok") {
31      return;
32    }
33    ctx.expect(result._0.error).toEqual(undefined);
34  });
35  Vitest.test("parses waypoint with multiple errors", ctx => {
36    let json = JSON.parse(`{"id":"wp-1","point":[10.0,20.0],"label":"Test","gid":"gid-1","country":"US","cons":[],"nonroutable":false,"error":["RouteTooFar","RouteFailed"]}`);
37    let result = Waypoint.fromJSON(json);
38    ctx.expect(Belt_Result.isOk(result)).toBe(true);
39    if (result.TAG !== "Ok") {
40      return;
41    }
42    ctx.expect(result._0.error).toEqual([
43      "RouteTooFar",
44      "RouteFailed"
45    ]);
46  });
47  Vitest.test("error field is accessible in waypoint record", ctx => {
48    let wp_point = [
49      10.0,
50      20.0
51    ];
52    let wp_cons = [];
53    let wp_error = ["RouteTooFar"];
54    let errors = wp_error;
55    if (errors !== undefined) {
56      ctx.expect(errors).toEqual(["RouteTooFar"]);
57      ctx.expect(errors.includes("RouteTooFar")).toBe(true);
58      return;
59    }
60  });
61  Vitest.test("waypoint without error has None error field", ctx => {
62    ctx.expect(undefined).toEqual(undefined);
63  });
64});
65
66/*  Not a pure module */