summaryrefslogtreecommitdiff
path: root/core/encode_decode_test.js
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2023-06-13 20:03:10 -0600
committerGitHub <noreply@github.com>2023-06-14 02:03:10 +0000
commitec8e9d4f5bd2c8eed5f086356c1c6dd7c8b40b7f (patch)
tree2ffda9204901bfb757e8ce6359d1fc6aa2f9964b /core/encode_decode_test.js
parentfd9d6baea311d9b227b130749647a86838ba2ccc (diff)
chore(core): Refactor runtime and split out tests (#19491)
This is a quick first refactoring to split the tests out of runtime and move runtime-related code to a top-level runtime module. There will be a followup to refactor imports a bit, but this is the major change that will most likely conflict with other work and I want to merge it early.
Diffstat (limited to 'core/encode_decode_test.js')
-rw-r--r--core/encode_decode_test.js69
1 files changed, 0 insertions, 69 deletions
diff --git a/core/encode_decode_test.js b/core/encode_decode_test.js
deleted file mode 100644
index 0f4668765..000000000
--- a/core/encode_decode_test.js
+++ /dev/null
@@ -1,69 +0,0 @@
-// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
-"use strict";
-function assert(cond) {
- if (!cond) {
- throw Error("assert");
- }
-}
-
-function assertArrayEquals(a1, a2) {
- if (a1.length !== a2.length) throw Error("assert");
-
- for (const index in a1) {
- if (a1[index] !== a2[index]) {
- throw Error("assert");
- }
- }
-}
-
-function main() {
- // deno-fmt-ignore
- const fixture1 = [
- 0xf0, 0x9d, 0x93, 0xbd,
- 0xf0, 0x9d, 0x93, 0xae,
- 0xf0, 0x9d, 0x94, 0x81,
- 0xf0, 0x9d, 0x93, 0xbd
- ];
- // deno-fmt-ignore
- const fixture2 = [
- 72, 101, 108, 108,
- 111, 32, 239, 191,
- 189, 239, 191, 189,
- 32, 87, 111, 114,
- 108, 100
- ];
-
- const empty = Deno.core.ops.op_encode("");
- if (empty.length !== 0) throw new Error("assert");
-
- assertArrayEquals(
- Array.from(Deno.core.ops.op_encode("𝓽𝓮𝔁𝓽")),
- fixture1,
- );
- assertArrayEquals(
- Array.from(Deno.core.ops.op_encode("Hello \udc12\ud834 World")),
- fixture2,
- );
-
- const emptyBuf = Deno.core.ops.op_decode(new Uint8Array(0));
- if (emptyBuf !== "") throw new Error("assert");
-
- assert(Deno.core.ops.op_decode(new Uint8Array(fixture1)) === "𝓽𝓮𝔁𝓽");
- assert(
- Deno.core.ops.op_decode(new Uint8Array(fixture2)) ===
- "Hello �� World",
- );
-
- // See https://github.com/denoland/deno/issues/6649
- let thrown = false;
- try {
- Deno.core.ops.op_decode(new Uint8Array(2 ** 29));
- } catch (e) {
- thrown = true;
- assert(e instanceof RangeError);
- assert(e.message === "string too long");
- }
- assert(thrown);
-}
-
-main();