From 0aa1353c1f350630e95fb3ff7b451bee305f0f52 Mon Sep 17 00:00:00 2001 From: ASDAlexander77 Date: Sat, 28 Nov 2026 17:26:15 +0000 Subject: [PATCH] Tests for TSLANG 222: Object.create(null), Object.defineProperty of a value, a run-time symbol's description Co-Authored-By: Claude Opus 5.5 --- tests/object_create_null.ts | 9 ++++++ ...ject_define_property_symbol_description.ts | 28 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 tests/object_create_null.ts create mode 100644 tests/object_define_property_symbol_description.ts diff --git a/tests/object_create_null.ts b/tests/object_create_null.ts new file mode 100644 index 0000000..b9d682f --- /dev/null +++ b/tests/object_create_null.ts @@ -0,0 +1,9 @@ +// Object.create(null) is an object of no keys that takes any, a dictionary of `any` (TSLANG 222). +function main() { + const o = Object.create(null); + o["k"] = 5; + o["s"] = "t"; + assert(o["k"] == 5 && o["s"] == "t", "create(null)"); + assert(Object.keys(o).length == 2, "create(null) keys"); + console.log("ALL DONE"); +} diff --git a/tests/object_define_property_symbol_description.ts b/tests/object_define_property_symbol_description.ts new file mode 100644 index 0000000..2410e67 --- /dev/null +++ b/tests/object_define_property_symbol_description.ts @@ -0,0 +1,28 @@ +// Object.defineProperty of a dictionary given a literal descriptor of a `value` is `d[k] = value` (writable, +// enumerable and configurable are not kept); `s.description` of a symbol known only at run time is its text +// without `Symbol(` and `)` (TSLANG 222). +function pick(b: boolean): symbol { + return b ? Symbol("a") : Symbol("bb"); +} + +function defineProperty() { + const d: { [key: string]: number } = {}; + const same = Object.defineProperty(d, "x", { value: 42, writable: true }); + Object.defineProperty(d, "y", { value: 7 }); + assert(d["x"] == 42 && d["y"] == 7 && same["x"] == 42, "defineProperty"); + assert(Object.keys(d).join(",") == "x,y", "defineProperty keys"); +} + +function symbolDescription() { + const r = pick(false); + assert(r.toString() == "Symbol(bb)", "run-time toString"); + assert(r.description == "bb" && r.description.length == 2, "run-time description"); + const q = pick(true); + assert(q.description == "a", "another run-time description"); +} + +function main() { + defineProperty(); + symbolDescription(); + console.log("ALL DONE"); +}