mirror of
https://github.com/denoland/deno.git
synced 2024-12-30 02:59:11 -05:00
f60720090c
Moving some additional NAPI and. FFI tests out of the tree root.
49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
|
|
import { assert, assertEquals, loadTestLibrary } from "./common.js";
|
|
|
|
const testSymbol = loadTestLibrary();
|
|
|
|
Deno.test("napi symbol1", () => {
|
|
const sym = testSymbol.symbolNew("test");
|
|
assertEquals(sym.toString(), "Symbol(test)");
|
|
|
|
const myObj = {};
|
|
const fooSym = testSymbol.symbolNew("foo");
|
|
const otherSym = testSymbol.symbolNew("bar");
|
|
myObj.foo = "bar";
|
|
myObj[fooSym] = "baz";
|
|
myObj[otherSym] = "bing";
|
|
assertEquals(myObj.foo, "bar");
|
|
assertEquals(myObj[fooSym], "baz");
|
|
assertEquals(myObj[otherSym], "bing");
|
|
});
|
|
|
|
Deno.test("napi symbol2", () => {
|
|
const sym = testSymbol.symbolNew("test");
|
|
assertEquals(sym.toString(), "Symbol(test)");
|
|
|
|
const myObj = {};
|
|
const fooSym = testSymbol.symbolNew("foo");
|
|
myObj.foo = "bar";
|
|
myObj[fooSym] = "baz";
|
|
|
|
assertEquals(Object.keys(myObj), ["foo"]);
|
|
assertEquals(Object.getOwnPropertyNames(myObj), ["foo"]);
|
|
assertEquals(Object.getOwnPropertySymbols(myObj), [fooSym]);
|
|
});
|
|
|
|
Deno.test("napi symbol3", () => {
|
|
assert(testSymbol.symbolNew() !== testSymbol.symbolNew());
|
|
assert(testSymbol.symbolNew("foo") !== testSymbol.symbolNew("foo"));
|
|
assert(testSymbol.symbolNew("foo") !== testSymbol.symbolNew("bar"));
|
|
|
|
const foo1 = testSymbol.symbolNew("foo");
|
|
const foo2 = testSymbol.symbolNew("foo");
|
|
const object = {
|
|
[foo1]: 1,
|
|
[foo2]: 2,
|
|
};
|
|
assertEquals(object[foo1], 1);
|
|
assertEquals(object[foo2], 2);
|
|
});
|