@weborigami/language 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { DeepObjectMap, ObjectMap, Tree } from "@weborigami/async-tree";
1
+ import { ObjectMap, Tree } from "@weborigami/async-tree";
2
2
  import assert from "node:assert";
3
3
  import { describe, test } from "node:test";
4
4
 
@@ -155,16 +155,37 @@ describe("ops", () => {
155
155
  assert(ops.greaterThanOrEqual("ab", "aa"));
156
156
  });
157
157
 
158
+ test("ops.inOperator returns true if a is in object b", () => {
159
+ assert.strictEqual(ops.inOperator("a", { a: 1, b: 2 }), true);
160
+ assert.strictEqual(ops.inOperator("c", { a: 1, b: 2 }), false);
161
+ const arr = [0, 0, 0];
162
+ assert.strictEqual(ops.inOperator(1, arr), true);
163
+ assert.strictEqual(ops.inOperator(3, arr), false);
164
+ });
165
+
158
166
  test("ops.inherited walks up the object parent chain", async () => {
159
- const tree = new DeepObjectMap({
160
- a: {
161
- b: {},
167
+ const tree = new ObjectMap(
168
+ {
169
+ a: {
170
+ b: {},
171
+ },
162
172
  },
163
- });
173
+ { deep: true }
174
+ );
164
175
  const b = await Tree.traverse(tree, "a", "b");
165
176
  assert.equal(await ops.inherited(2, { object: b }), tree);
166
177
  });
167
178
 
179
+ test("ops.instanceOf checks prototype chain", () => {
180
+ class Parent {}
181
+ class Child extends Parent {}
182
+ const child = new Child();
183
+ assert.strictEqual(ops.instanceOf(child, Child), true);
184
+ assert.strictEqual(ops.instanceOf(child, Parent), true);
185
+ assert.strictEqual(ops.instanceOf(child, Object), true);
186
+ assert.strictEqual(ops.instanceOf(child, Array), false);
187
+ });
188
+
168
189
  test("ops.lambda defines a function with no inputs", async () => {
169
190
  const code = createCode([ops.lambda, [], [ops.literal, "result"]]);
170
191
  const fn = await evaluate(code);
@@ -368,12 +389,15 @@ describe("ops", () => {
368
389
 
369
390
  describe("ops.scope", () => {
370
391
  test("returns the scope of the given tree", async () => {
371
- const tree = new DeepObjectMap({
372
- a: {
373
- b: {},
392
+ const tree = new ObjectMap(
393
+ {
394
+ a: {
395
+ b: {},
396
+ },
397
+ c: 1,
374
398
  },
375
- c: 1,
376
- });
399
+ { deep: true }
400
+ );
377
401
  const a = await tree.get("a");
378
402
  const b = await a.get("b");
379
403
  const scope = await ops.scope(b);
@@ -1,21 +0,0 @@
1
- import assert from "node:assert";
2
- import { describe, test } from "node:test";
3
- import jsGlobals from "../../src/project/jsGlobals.js";
4
-
5
- describe("jsGlobals", () => {
6
- test("wraps static methods to bind them to defining object", async () => {
7
- const all = jsGlobals.Promise.all;
8
- const value = await all([Promise.resolve("hi")]);
9
- assert.equal(value, "hi");
10
- });
11
-
12
- test("can invoke a global constructor", async () => {
13
- const { Number: fixture } = jsGlobals;
14
- // Without `new`
15
- const instance1 = fixture(5);
16
- assert.equal(instance1, 5);
17
- // With `new`
18
- const instance = new fixture();
19
- assert(instance instanceof Number);
20
- });
21
- });