diff options
author | 2022-03-15 00:48:28 -0700 | |
---|---|---|
committer | 2022-03-15 00:48:28 -0700 | |
commit | 069fce0033a0c02ab3d1019dba33dfe444c68789 (patch) | |
tree | 286beb61c035748fca99c98b4eec767bb79dff9a /integration/bunjs-only-snippets | |
parent | 57e42cc53898bab5fc33520151166b5fd36032fb (diff) | |
download | bun-069fce0033a0c02ab3d1019dba33dfe444c68789.tar.gz bun-069fce0033a0c02ab3d1019dba33dfe444c68789.tar.zst bun-069fce0033a0c02ab3d1019dba33dfe444c68789.zip |
Create unsafe.test.js
Diffstat (limited to 'integration/bunjs-only-snippets')
-rw-r--r-- | integration/bunjs-only-snippets/unsafe.test.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/integration/bunjs-only-snippets/unsafe.test.js b/integration/bunjs-only-snippets/unsafe.test.js new file mode 100644 index 000000000..c8c241020 --- /dev/null +++ b/integration/bunjs-only-snippets/unsafe.test.js @@ -0,0 +1,32 @@ +import { test, expect, it, describe } from "bun:test"; + +it("arrayBufferToString u8", () => { + var encoder = new TextEncoder(); + const bytes = encoder.encode("hello world"); + Bun.gc(true); + expect(Bun.unsafe.arrayBufferToString(bytes)).toBe("hello world"); +}); + +it("arrayBufferToString ArrayBuffer", () => { + var encoder = new TextEncoder(); + const bytes = encoder.encode("hello world"); + Bun.gc(true); + expect(Bun.unsafe.arrayBufferToString(bytes.buffer)).toBe("hello world"); +}); + +it("arrayBufferToString u16", () => { + var encoder = new TextEncoder(); + const bytes = encoder.encode("hello world"); + var uint16 = new Uint16Array(bytes.byteLength); + uint16.set(bytes); + const charCodes = Bun.unsafe + .arrayBufferToString(uint16) + .split("") + .map((a) => a.charCodeAt(0)); + Bun.gc(true); + for (let i = 0; i < charCodes.length; i++) { + expect("hello world"[i]).toBe(String.fromCharCode(charCodes[i])); + } + Bun.gc(true); + expect(charCodes.length).toBe("hello world".length); +}); |