]> Lady’s Gitweb - Pisces/blobdiff - value.test.js
Add methods for own entries and values to object.js
[Pisces] / value.test.js
index 9121af479c46f3e2a190ec64742bf82ffd31ae34..ce6464d07091e19fd89b84b578d7a0ede3cb258f 100644 (file)
@@ -8,6 +8,7 @@
 // file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
 
 import {
+  assertEquals,
   assertStrictEquals,
   assertThrows,
   describe,
@@ -15,8 +16,13 @@ import {
 } from "./dev-deps.js";
 import {
   ASYNC_ITERATOR,
+  completePropertyDescriptor,
   HAS_INSTANCE,
   IS_CONCAT_SPREADABLE,
+  isAccessorDescriptor,
+  isDataDescriptor,
+  isFullyPopulatedDescriptor,
+  isGenericDescriptor,
   ITERATOR,
   LN10,
   LN2,
@@ -48,6 +54,7 @@ import {
   toIndex,
   toLength,
   toPrimitive,
+  toPropertyKey,
   type,
   UNDEFINED,
   UNSCOPABLES,
@@ -239,21 +246,259 @@ describe("UNSCOPABLES", () => {
   });
 });
 
-describe("Ε", () => {
-  it("[[Get]] is ε", () => {
-    assertStrictEquals(Ε, Number.EPSILON);
+describe("completePropertyDescriptor", () => {
+  it("[[Call]] completes a generic descriptor", () => {
+    const desc = {};
+    completePropertyDescriptor(desc);
+    assertEquals(desc, {
+      configurable: false,
+      enumerable: false,
+      value: undefined,
+      writable: false,
+    });
+  });
+
+  it("[[Call]] completes a data descriptor", () => {
+    const desc = { value: undefined };
+    completePropertyDescriptor(desc);
+    assertEquals(desc, {
+      configurable: false,
+      enumerable: false,
+      value: undefined,
+      writable: false,
+    });
+  });
+
+  it("[[Call]] completes an accessor descriptor", () => {
+    const desc = { get: undefined };
+    completePropertyDescriptor(desc);
+    assertEquals(desc, {
+      configurable: false,
+      enumerable: false,
+      get: undefined,
+      set: undefined,
+    });
+  });
+
+  it("[[Call]] throws an error when the descriptor is undefined", () => {
+    assertThrows(() => new completePropertyDescriptor(undefined));
+  });
+
+  it("[[Construct]] throws an error", () => {
+    assertThrows(() => new completePropertyDescriptor({}));
+  });
+
+  describe(".length", () => {
+    it("[[Get]] returns the correct length", () => {
+      assertStrictEquals(completePropertyDescriptor.length, 1);
+    });
+  });
+
+  describe(".name", () => {
+    it("[[Get]] returns the correct name", () => {
+      assertStrictEquals(
+        completePropertyDescriptor.name,
+        "completePropertyDescriptor",
+      );
+    });
   });
 });
 
-describe("Π", () => {
-  it("[[Get]] is π", () => {
-    assertStrictEquals(Π, Math.PI);
+describe("isAccessorDescriptor", () => {
+  it("[[Call]] returns false for a generic descriptor", () => {
+    assertStrictEquals(isAccessorDescriptor({}), false);
+  });
+
+  it("[[Get]] returns false for a data descriptor", () => {
+    assertStrictEquals(
+      isAccessorDescriptor({ value: undefined }),
+      false,
+    );
+    assertStrictEquals(
+      isAccessorDescriptor({ writable: undefined }),
+      false,
+    );
+  });
+
+  it("[[Get]] returns true for an accessor descriptor", () => {
+    assertStrictEquals(isAccessorDescriptor({ get: undefined }), true);
+    assertStrictEquals(isAccessorDescriptor({ set: undefined }), true);
+  });
+
+  it("[[Get]] returns false for undefined", () => {
+    assertStrictEquals(isAccessorDescriptor(undefined), false);
+  });
+
+  it("[[Construct]] throws an error", () => {
+    assertThrows(() => new isAccessorDescriptor({}));
+  });
+
+  describe(".length", () => {
+    it("[[Get]] returns the correct length", () => {
+      assertStrictEquals(isAccessorDescriptor.length, 1);
+    });
+  });
+
+  describe(".name", () => {
+    it("[[Get]] returns the correct name", () => {
+      assertStrictEquals(
+        isAccessorDescriptor.name,
+        "isAccessorDescriptor",
+      );
+    });
   });
 });
 
-describe("ℇ", () => {
-  it("[[Get]] is ℇ", () => {
-    assertStrictEquals(ℇ, Math.E);
+describe("isDataDescriptor", () => {
+  it("[[Call]] returns false for a generic descriptor", () => {
+    assertStrictEquals(isDataDescriptor({}), false);
+  });
+
+  it("[[Get]] returns true for a data descriptor", () => {
+    assertStrictEquals(isDataDescriptor({ value: undefined }), true);
+    assertStrictEquals(isDataDescriptor({ writable: true }), true);
+  });
+
+  it("[[Get]] returns false for an accessor descriptor", () => {
+    assertStrictEquals(isDataDescriptor({ get: undefined }), false);
+    assertStrictEquals(isDataDescriptor({ set: undefined }), false);
+  });
+
+  it("[[Get]] returns false for undefined", () => {
+    assertStrictEquals(isDataDescriptor(undefined), false);
+  });
+
+  it("[[Construct]] throws an error", () => {
+    assertThrows(() => new isDataDescriptor({}));
+  });
+
+  describe(".length", () => {
+    it("[[Get]] returns the correct length", () => {
+      assertStrictEquals(isDataDescriptor.length, 1);
+    });
+  });
+
+  describe(".name", () => {
+    it("[[Get]] returns the correct name", () => {
+      assertStrictEquals(isDataDescriptor.name, "isDataDescriptor");
+    });
+  });
+});
+
+describe("isFullyPopulatedDescriptor", () => {
+  it("[[Call]] returns false for a generic descriptor", () => {
+    assertStrictEquals(isFullyPopulatedDescriptor({}), false);
+  });
+
+  it("[[Get]] returns false for a non‐fully‐populated data descriptor", () => {
+    assertStrictEquals(
+      isFullyPopulatedDescriptor({ value: undefined }),
+      false,
+    );
+    assertStrictEquals(
+      isFullyPopulatedDescriptor({ writable: true }),
+      false,
+    );
+  });
+
+  it("[[Get]] returns true for a fully‐populated data descriptor", () => {
+    assertStrictEquals(
+      isFullyPopulatedDescriptor({
+        configurable: true,
+        enumerable: true,
+        value: undefined,
+        writable: true,
+      }),
+      true,
+    );
+  });
+
+  it("[[Get]] returns false for a non‐fully‐populated accessor descriptor", () => {
+    assertStrictEquals(
+      isFullyPopulatedDescriptor({ get: undefined }),
+      false,
+    );
+    assertStrictEquals(
+      isFullyPopulatedDescriptor({ set: undefined }),
+      false,
+    );
+  });
+
+  it("[[Get]] returns true for a fully‐populated accessor descriptor", () => {
+    assertStrictEquals(
+      isFullyPopulatedDescriptor({
+        configurable: true,
+        enumerable: true,
+        get: undefined,
+        set: undefined,
+      }),
+      true,
+    );
+  });
+
+  it("[[Get]] returns false for undefined", () => {
+    assertStrictEquals(isFullyPopulatedDescriptor(undefined), false);
+  });
+
+  it("[[Construct]] throws an error", () => {
+    assertThrows(() => new isFullyPopulatedDescriptor({}));
+  });
+
+  describe(".length", () => {
+    it("[[Get]] returns the correct length", () => {
+      assertStrictEquals(isFullyPopulatedDescriptor.length, 1);
+    });
+  });
+
+  describe(".name", () => {
+    it("[[Get]] returns the correct name", () => {
+      assertStrictEquals(
+        isFullyPopulatedDescriptor.name,
+        "isFullyPopulatedDescriptor",
+      );
+    });
+  });
+});
+
+describe("isGenericDescriptor", () => {
+  it("[[Call]] returns true for a generic descriptor", () => {
+    assertStrictEquals(isGenericDescriptor({}), true);
+  });
+
+  it("[[Get]] returns false for a data descriptor", () => {
+    assertStrictEquals(
+      isGenericDescriptor({ value: undefined }),
+      false,
+    );
+    assertStrictEquals(isGenericDescriptor({ writable: true }), false);
+  });
+
+  it("[[Get]] returns false for an accessor descriptor", () => {
+    assertStrictEquals(isGenericDescriptor({ get: undefined }), false);
+    assertStrictEquals(isGenericDescriptor({ set: undefined }), false);
+  });
+
+  it("[[Get]] returns false for undefined", () => {
+    assertStrictEquals(isGenericDescriptor(undefined), false);
+  });
+
+  it("[[Construct]] throws an error", () => {
+    assertThrows(() => new isGenericDescriptor({}));
+  });
+
+  describe(".length", () => {
+    it("[[Get]] returns the correct length", () => {
+      assertStrictEquals(isGenericDescriptor.length, 1);
+    });
+  });
+
+  describe(".name", () => {
+    it("[[Get]] returns the correct name", () => {
+      assertStrictEquals(
+        isGenericDescriptor.name,
+        "isGenericDescriptor",
+      );
+    });
   });
 });
 
@@ -747,6 +992,47 @@ describe("toPrimitive", () => {
   });
 });
 
+describe("toPropertyKey", () => {
+  it("returns a string or symbol", () => {
+    const sym = Symbol();
+    assertStrictEquals(toPropertyKey(sym), sym);
+    assertStrictEquals(
+      toPropertyKey(new String("success")),
+      "success",
+    );
+  });
+
+  it("favours the `toString` representation", () => {
+    assertStrictEquals(
+      toPropertyKey({
+        toString() {
+          return "success";
+        },
+        valueOf() {
+          return "failure";
+        },
+      }),
+      "success",
+    );
+  });
+
+  it("[[Construct]] throws an error", () => {
+    assertThrows(() => new toPropertyKey(""));
+  });
+
+  describe(".length", () => {
+    it("[[Get]] returns the correct length", () => {
+      assertStrictEquals(toPropertyKey.length, 1);
+    });
+  });
+
+  describe(".name", () => {
+    it("[[Get]] returns the correct name", () => {
+      assertStrictEquals(toPropertyKey.name, "toPropertyKey");
+    });
+  });
+});
+
 describe("type", () => {
   it('[[Call]] returns "null" for null', () => {
     assertStrictEquals(type(null), "null");
@@ -784,3 +1070,21 @@ describe("type", () => {
     });
   });
 });
+
+describe("Ε", () => {
+  it("[[Get]] is ε", () => {
+    assertStrictEquals(Ε, Number.EPSILON);
+  });
+});
+
+describe("Π", () => {
+  it("[[Get]] is π", () => {
+    assertStrictEquals(Π, Math.PI);
+  });
+});
+
+describe("ℇ", () => {
+  it("[[Get]] is ℇ", () => {
+    assertStrictEquals(ℇ, Math.E);
+  });
+});
This page took 0.028079 seconds and 4 git commands to generate.