summaryrefslogtreecommitdiff
path: root/core/runtime/serialize_deserialize_test.js
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2023-07-01 18:00:14 -0600
committerGitHub <noreply@github.com>2023-07-02 00:00:14 +0000
commite746b6d80654ba4e4e26370fe6e4f784ce841d92 (patch)
tree153ffad92a96126b9ab8e906dcdabf7648755931 /core/runtime/serialize_deserialize_test.js
parentb9c0e7cd550ab14fa7da7e33ed87cbeeeb9785a0 (diff)
refactor(core): Extract deno_core (#19658)
`deno_core` is moving out! You'll find it at https://github.com/denoland/deno_core/ once this PR lands.
Diffstat (limited to 'core/runtime/serialize_deserialize_test.js')
-rw-r--r--core/runtime/serialize_deserialize_test.js74
1 files changed, 0 insertions, 74 deletions
diff --git a/core/runtime/serialize_deserialize_test.js b/core/runtime/serialize_deserialize_test.js
deleted file mode 100644
index 70397cdf8..000000000
--- a/core/runtime/serialize_deserialize_test.js
+++ /dev/null
@@ -1,74 +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: (index ${index}) ${a1[index]} !== ${a2[index]}`);
- }
- }
-}
-
-function main() {
- const emptyString = "";
- const emptyStringSerialized = [255, 15, 34, 0];
- assertArrayEquals(
- Deno.core.ops.op_serialize(emptyString),
- emptyStringSerialized,
- );
- assert(
- Deno.core.ops.op_deserialize(
- new Uint8Array(emptyStringSerialized),
- ) ===
- emptyString,
- );
-
- const primitiveValueArray = ["test", "a", null, undefined];
- // deno-fmt-ignore
- const primitiveValueArraySerialized = [
- 255, 15, 65, 4, 34, 4, 116, 101, 115, 116,
- 34, 1, 97, 48, 95, 36, 0, 4,
- ];
- assertArrayEquals(
- Deno.core.ops.op_serialize(primitiveValueArray),
- primitiveValueArraySerialized,
- );
-
- assertArrayEquals(
- Deno.core.ops.op_deserialize(
- new Uint8Array(primitiveValueArraySerialized),
- ),
- primitiveValueArray,
- );
-
- const circularObject = { test: null, test2: "dd", test3: "aa" };
- circularObject.test = circularObject;
- // deno-fmt-ignore
- const circularObjectSerialized = [
- 255, 15, 111, 34, 4, 116, 101, 115,
- 116, 94, 0, 34, 5, 116, 101, 115,
- 116, 50, 34, 2, 100, 100, 34, 5,
- 116, 101, 115, 116, 51, 34, 2, 97,
- 97, 123, 3,
- ];
-
- assertArrayEquals(
- Deno.core.ops.op_serialize(circularObject),
- circularObjectSerialized,
- );
-
- const deserializedCircularObject = Deno.core.ops.op_deserialize(
- new Uint8Array(circularObjectSerialized),
- );
- assert(deserializedCircularObject.test == deserializedCircularObject);
-}
-
-main();