|
1 | 1 | import { describe, expect, it } from "./suite.ts"; |
2 | | -import { createPlatformScript, external, map, number } from "../mod.ts"; |
| 2 | +import { createPlatformScript, external, map, number, parse } from "../mod.ts"; |
3 | 3 |
|
4 | 4 | import * as _ from "https://raw.githubusercontent.com/lodash/lodash/4.17.21-es/lodash.js"; |
5 | 5 |
|
6 | 6 | describe("external", () => { |
7 | 7 | it("can represent any arbitrary javascript value", async () => { |
8 | 8 | let obj = { unqiue: "object" }; |
9 | | - let ps = createPlatformScript(map({ |
10 | | - "extern": external(obj), |
11 | | - })); |
12 | | - expect((await ps.eval(ps.parse("$extern"))).value).toBe(obj); |
| 9 | + let ps = createPlatformScript(() => |
| 10 | + map({ |
| 11 | + "extern": external(obj), |
| 12 | + }) |
| 13 | + ); |
| 14 | + expect((await ps.eval(parse("$extern"))).value).toBe(obj); |
13 | 15 | }); |
14 | 16 |
|
15 | 17 | it("can define new PS values from the external value", async () => { |
16 | 18 | let obj = { I: { contain: { the: { number: number(5) } } } }; |
17 | | - let ps = createPlatformScript(map({ |
18 | | - "truly": external(obj, (path, o) => _.get(o, path)), |
19 | | - })); |
| 19 | + let ps = createPlatformScript(() => |
| 20 | + map({ |
| 21 | + "truly": external(obj, (path, o) => _.get(o, path)), |
| 22 | + }) |
| 23 | + ); |
20 | 24 |
|
21 | | - let program = ps.parse("$truly.I.contain.the.number"); |
| 25 | + let program = parse("$truly.I.contain.the.number"); |
22 | 26 | expect((await ps.eval(program)).value).toEqual(5); |
23 | 27 | }); |
24 | 28 | it("errors if a dereference is undefined", async () => { |
25 | | - let ps = createPlatformScript(map({ |
26 | | - "oops": external({}, () => void 0), |
27 | | - })); |
| 29 | + let ps = createPlatformScript(() => |
| 30 | + map({ |
| 31 | + "oops": external({}, () => void 0), |
| 32 | + }) |
| 33 | + ); |
28 | 34 | try { |
29 | | - await ps.eval(ps.parse("$oops.i.did.it.again")); |
| 35 | + await ps.eval(parse("$oops.i.did.it.again")); |
30 | 36 | throw new Error("expected block to throw, but it did not"); |
31 | 37 | } catch (error) { |
32 | 38 | expect(error.name).toEqual("ReferenceError"); |
33 | 39 | } |
34 | 40 | }); |
35 | 41 | it("errors if a derefenence does not return a PSValue", async () => { |
36 | | - let ps = createPlatformScript(map({ |
37 | | - "oops": external( |
38 | | - { wrong: "type" }, |
39 | | - //@ts-expect-error situation could happen if you are using JavaScript... |
40 | | - () => ({ type: "WAT!!", value: "hi" }), |
41 | | - ), |
42 | | - })); |
| 42 | + let ps = createPlatformScript(() => |
| 43 | + map({ |
| 44 | + "oops": external( |
| 45 | + { wrong: "type" }, |
| 46 | + //@ts-expect-error situation could happen if you are using JavaScript... |
| 47 | + () => ({ type: "WAT!!", value: "hi" }), |
| 48 | + ), |
| 49 | + }) |
| 50 | + ); |
43 | 51 |
|
44 | 52 | try { |
45 | | - await ps.eval(ps.parse("$oops.wrong")); |
| 53 | + await ps.eval(parse("$oops.wrong")); |
46 | 54 | throw new Error("expected block to throw, but it did not"); |
47 | 55 | } catch (error) { |
48 | 56 | expect(error.message).toMatch( |
|
0 commit comments