From 46b676ff7fe2d82f43e53852d28e498b3a476e81 Mon Sep 17 00:00:00 2001 From: MierenManz Date: Thu, 27 Apr 2023 19:54:43 +0200 Subject: [PATCH 01/13] primitive tests --- types/primitive/bool_test.ts | 21 +++++++++++++++++++++ types/primitive/f32_test.ts | 26 ++++++++++++++++++++++++++ types/primitive/f64_test.ts | 26 ++++++++++++++++++++++++++ types/primitive/i16_test.ts | 26 ++++++++++++++++++++++++++ types/primitive/i32_test.ts | 26 ++++++++++++++++++++++++++ types/primitive/i64_test.ts | 26 ++++++++++++++++++++++++++ types/primitive/i8_test.ts | 21 +++++++++++++++++++++ types/primitive/u16_test.ts | 26 ++++++++++++++++++++++++++ types/primitive/u32_test.ts | 26 ++++++++++++++++++++++++++ types/primitive/u64_test.ts | 26 ++++++++++++++++++++++++++ types/primitive/u8_test.ts | 21 +++++++++++++++++++++ 11 files changed, 271 insertions(+) create mode 100644 types/primitive/bool_test.ts create mode 100644 types/primitive/f32_test.ts create mode 100644 types/primitive/f64_test.ts create mode 100644 types/primitive/i16_test.ts create mode 100644 types/primitive/i32_test.ts create mode 100644 types/primitive/i64_test.ts create mode 100644 types/primitive/i8_test.ts create mode 100644 types/primitive/u16_test.ts create mode 100644 types/primitive/u32_test.ts create mode 100644 types/primitive/u64_test.ts create mode 100644 types/primitive/u8_test.ts diff --git a/types/primitive/bool_test.ts b/types/primitive/bool_test.ts new file mode 100644 index 0000000..fcbc30f --- /dev/null +++ b/types/primitive/bool_test.ts @@ -0,0 +1,21 @@ +import { bool } from "./bool.ts"; +import { assertEquals } from "https://deno.land/std@0.178.0/testing/asserts.ts"; + +Deno.test("Boolean", async ({ step }) => { + const buff = new ArrayBuffer(1); + const dt = new DataView(buff); + + await step("read", () => { + dt.setInt8(0, 0); + assertEquals(bool.read(dt), false); + dt.setInt8(0, 1); + assertEquals(bool.read(dt), true); + }); + + await step("write", () => { + bool.write(true, dt); + assertEquals(dt.getInt8(0), 1); + bool.write(false, dt); + assertEquals(dt.getInt8(0), 0); + }); +}); diff --git a/types/primitive/f32_test.ts b/types/primitive/f32_test.ts new file mode 100644 index 0000000..4dd0078 --- /dev/null +++ b/types/primitive/f32_test.ts @@ -0,0 +1,26 @@ +import { assertAlmostEquals } from "https://deno.land/std@0.178.0/testing/asserts.ts"; +import { f32le, f32be } from "./f32.ts"; + +Deno.test("f32", async ({ step }) => { + const buff = new ArrayBuffer(4); + const dt = new DataView(buff); + const value = 12.69; + + await step("read", () => { + // Little endian + dt.setFloat32(0, value, true); + assertAlmostEquals(value, f32le.read(dt), 0.01); + // Big endian + dt.setFloat32(0, value, false); + assertAlmostEquals(value, f32be.read(dt), 0.01); + }); + + await step("write", () => { + // Little endian + f32le.write(value, dt); + assertAlmostEquals(value, dt.getFloat32(0, true), 0.01); + // Big endian + f32be.write(value, dt); + assertAlmostEquals(value, dt.getFloat32(0, false), 0.01); + }); +}); diff --git a/types/primitive/f64_test.ts b/types/primitive/f64_test.ts new file mode 100644 index 0000000..a894124 --- /dev/null +++ b/types/primitive/f64_test.ts @@ -0,0 +1,26 @@ +import { assertEquals } from "https://deno.land/std@0.178.0/testing/asserts.ts"; +import { f64le, f64be } from "./f64.ts"; + +Deno.test("f64", async ({ step }) => { + const buff = new ArrayBuffer(8); + const dt = new DataView(buff); + const value = 12.69; + + await step("read", () => { + // Little endian + dt.setFloat64(0, value, true); + assertEquals(value, f64le.read(dt)); + // Big endian + dt.setFloat64(0, value, false); + assertEquals(value, f64be.read(dt)); + }); + + await step("write", () => { + // Little endian + f64le.write(value, dt); + assertEquals(value, dt.getFloat64(0, true)); + // Big endian + f64be.write(value, dt); + assertEquals(value, dt.getFloat64(0, false)); + }); +}); diff --git a/types/primitive/i16_test.ts b/types/primitive/i16_test.ts new file mode 100644 index 0000000..4d65666 --- /dev/null +++ b/types/primitive/i16_test.ts @@ -0,0 +1,26 @@ +import { i16le, i16be } from "./i16.ts"; +import { assertEquals } from "https://deno.land/std@0.178.0/testing/asserts.ts"; + +Deno.test("i16", async ({ step }) => { + const buff = new ArrayBuffer(2); + const dt = new DataView(buff); + const value = 12; + + await step("read", () => { + // Little endian + dt.setInt16(0, value, true); + assertEquals(value, i16le.read(dt)); + // Big endian + dt.setInt16(0, value, false); + assertEquals(value, i16be.read(dt)); + }); + + await step("write", () => { + // Little endian + i16le.write(value, dt); + assertEquals(value, dt.getInt16(0, true)); + // Big endian + i16be.write(value, dt); + assertEquals(value, dt.getInt16(0, false)); + }); +}); diff --git a/types/primitive/i32_test.ts b/types/primitive/i32_test.ts new file mode 100644 index 0000000..0b39b5c --- /dev/null +++ b/types/primitive/i32_test.ts @@ -0,0 +1,26 @@ +import { i32le, i32be } from "./i32.ts"; +import { assertEquals } from "https://deno.land/std@0.178.0/testing/asserts.ts"; + +Deno.test("i32", async ({ step }) => { + const buff = new ArrayBuffer(4); + const dt = new DataView(buff); + const value = 12; + + await step("read", () => { + // Little endian + dt.setInt32(0, value, true); + assertEquals(value, i32le.read(dt)); + // Big endian + dt.setInt32(0, value, false); + assertEquals(value, i32be.read(dt)); + }); + + await step("write", () => { + // Little endian + i32le.write(value, dt); + assertEquals(value, dt.getInt32(0, true)); + // Big endian + i32be.write(value, dt); + assertEquals(value, dt.getInt32(0, false)); + }); +}); diff --git a/types/primitive/i64_test.ts b/types/primitive/i64_test.ts new file mode 100644 index 0000000..e38259e --- /dev/null +++ b/types/primitive/i64_test.ts @@ -0,0 +1,26 @@ +import { i64le, i64be } from "./i64.ts"; +import { assertEquals } from "https://deno.land/std@0.178.0/testing/asserts.ts"; + +Deno.test("i64", async ({ step }) => { + const buff = new ArrayBuffer(8); + const dt = new DataView(buff); + const value = 12n; + + await step("read", () => { + // Little endian + dt.setBigInt64(0, value, true); + assertEquals(value, i64le.read(dt)); + // Big endian + dt.setBigInt64(0, value, false); + assertEquals(value, i64be.read(dt)); + }); + + await step("write", () => { + // Little endian + i64le.write(value, dt); + assertEquals(value, dt.getBigInt64(0, true)); + // Big endian + i64be.write(value, dt); + assertEquals(value, dt.getBigInt64(0, false)); + }); +}); diff --git a/types/primitive/i8_test.ts b/types/primitive/i8_test.ts new file mode 100644 index 0000000..3cbdedc --- /dev/null +++ b/types/primitive/i8_test.ts @@ -0,0 +1,21 @@ +import { i8 } from "./i8.ts"; +import { assertEquals } from "https://deno.land/std@0.178.0/testing/asserts.ts"; + +Deno.test("i8", async ({ step }) => { + const buff = new ArrayBuffer(1); + const dt = new DataView(buff); + + await step("read", () => { + dt.setInt8(0, 0); + assertEquals(i8.read(dt), 0); + dt.setInt8(0, 1); + assertEquals(i8.read(dt), 1); + }); + + await step("write", () => { + i8.write(1, dt); + assertEquals(dt.getInt8(0), 1); + i8.write(0, dt); + assertEquals(dt.getInt8(0), 0); + }); +}); diff --git a/types/primitive/u16_test.ts b/types/primitive/u16_test.ts new file mode 100644 index 0000000..a147108 --- /dev/null +++ b/types/primitive/u16_test.ts @@ -0,0 +1,26 @@ +import { u16le, u16be } from "./u16.ts"; +import { assertEquals } from "https://deno.land/std@0.178.0/testing/asserts.ts"; + +Deno.test("u16", async ({ step }) => { + const buff = new ArrayBuffer(2); + const dt = new DataView(buff); + const value = 12; + + await step("read", () => { + // Little endian + dt.setUint16(0, value, true); + assertEquals(value, u16le.read(dt)); + // Big endian + dt.setUint16(0, value, false); + assertEquals(value, u16be.read(dt)); + }); + + await step("write", () => { + // Little endian + u16le.write(value, dt); + assertEquals(value, dt.getUint16(0, true)); + // Big endian + u16be.write(value, dt); + assertEquals(value, dt.getUint16(0, false)); + }); +}); diff --git a/types/primitive/u32_test.ts b/types/primitive/u32_test.ts new file mode 100644 index 0000000..9f50e62 --- /dev/null +++ b/types/primitive/u32_test.ts @@ -0,0 +1,26 @@ +import { u32le, u32be } from "./u32.ts"; +import { assertEquals } from "https://deno.land/std@0.178.0/testing/asserts.ts"; + +Deno.test("u32", async ({ step }) => { + const buff = new ArrayBuffer(4); + const dt = new DataView(buff); + const value = 12; + + await step("read", () => { + // Little endian + dt.setUint32(0, value, true); + assertEquals(value, u32le.read(dt)); + // Big endian + dt.setUint32(0, value, false); + assertEquals(value, u32be.read(dt)); + }); + + await step("write", () => { + // Little endian + u32le.write(value, dt); + assertEquals(value, dt.getUint32(0, true)); + // Big endian + u32be.write(value, dt); + assertEquals(value, dt.getUint32(0, false)); + }); +}); diff --git a/types/primitive/u64_test.ts b/types/primitive/u64_test.ts new file mode 100644 index 0000000..690b8d3 --- /dev/null +++ b/types/primitive/u64_test.ts @@ -0,0 +1,26 @@ +import { u64le, u64be } from "./u64.ts"; +import { assertEquals } from "https://deno.land/std@0.178.0/testing/asserts.ts"; + +Deno.test("u64", async ({ step }) => { + const buff = new ArrayBuffer(8); + const dt = new DataView(buff); + const value = 12n; + + await step("read", () => { + // Little endian + dt.setBigUint64(0, value, true); + assertEquals(value, u64le.read(dt)); + // Big endian + dt.setBigUint64(0, value, false); + assertEquals(value, u64be.read(dt)); + }); + + await step("write", () => { + // Little endian + u64le.write(value, dt); + assertEquals(value, dt.getBigUint64(0, true)); + // Big endian + u64be.write(value, dt); + assertEquals(value, dt.getBigUint64(0, false)); + }); +}); diff --git a/types/primitive/u8_test.ts b/types/primitive/u8_test.ts new file mode 100644 index 0000000..1eabdad --- /dev/null +++ b/types/primitive/u8_test.ts @@ -0,0 +1,21 @@ +import { u8 } from "./u8.ts"; +import { assertEquals } from "https://deno.land/std@0.178.0/testing/asserts.ts"; + +Deno.test("u8", async ({ step }) => { + const buff = new ArrayBuffer(1); + const dt = new DataView(buff); + + await step("read", () => { + dt.setUint8(0, 0); + assertEquals(u8.read(dt), 0); + dt.setUint8(0, 1); + assertEquals(u8.read(dt), 1); + }); + + await step("write", () => { + u8.write(1, dt); + assertEquals(dt.getUint8(0), 1); + u8.write(0, dt); + assertEquals(dt.getUint8(0), 0); + }); +}); From a20361dfe507090d6d73dd2547f8764130cd36a0 Mon Sep 17 00:00:00 2001 From: MierenManz Date: Thu, 27 Apr 2023 20:01:52 +0200 Subject: [PATCH 02/13] use import_map --- types/primitive/bool_test.ts | 2 +- types/primitive/f32_test.ts | 2 +- types/primitive/f64_test.ts | 2 +- types/primitive/i16_test.ts | 2 +- types/primitive/i32_test.ts | 2 +- types/primitive/i64_test.ts | 2 +- types/primitive/i8_test.ts | 2 +- types/primitive/u16_test.ts | 2 +- types/primitive/u32_test.ts | 2 +- types/primitive/u64_test.ts | 2 +- types/primitive/u8_test.ts | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/types/primitive/bool_test.ts b/types/primitive/bool_test.ts index fcbc30f..c52ea0b 100644 --- a/types/primitive/bool_test.ts +++ b/types/primitive/bool_test.ts @@ -1,5 +1,5 @@ import { bool } from "./bool.ts"; -import { assertEquals } from "https://deno.land/std@0.178.0/testing/asserts.ts"; +import { assertEquals } from "std/testing/asserts.ts"; Deno.test("Boolean", async ({ step }) => { const buff = new ArrayBuffer(1); diff --git a/types/primitive/f32_test.ts b/types/primitive/f32_test.ts index 4dd0078..f62e619 100644 --- a/types/primitive/f32_test.ts +++ b/types/primitive/f32_test.ts @@ -1,4 +1,4 @@ -import { assertAlmostEquals } from "https://deno.land/std@0.178.0/testing/asserts.ts"; +import { assertAlmostEquals } from "std/testing/asserts.ts"; import { f32le, f32be } from "./f32.ts"; Deno.test("f32", async ({ step }) => { diff --git a/types/primitive/f64_test.ts b/types/primitive/f64_test.ts index a894124..d6856ce 100644 --- a/types/primitive/f64_test.ts +++ b/types/primitive/f64_test.ts @@ -1,4 +1,4 @@ -import { assertEquals } from "https://deno.land/std@0.178.0/testing/asserts.ts"; +import { assertEquals } from "std/testing/asserts.ts"; import { f64le, f64be } from "./f64.ts"; Deno.test("f64", async ({ step }) => { diff --git a/types/primitive/i16_test.ts b/types/primitive/i16_test.ts index 4d65666..7aa2975 100644 --- a/types/primitive/i16_test.ts +++ b/types/primitive/i16_test.ts @@ -1,5 +1,5 @@ import { i16le, i16be } from "./i16.ts"; -import { assertEquals } from "https://deno.land/std@0.178.0/testing/asserts.ts"; +import { assertEquals } from "std/testing/asserts.ts"; Deno.test("i16", async ({ step }) => { const buff = new ArrayBuffer(2); diff --git a/types/primitive/i32_test.ts b/types/primitive/i32_test.ts index 0b39b5c..f00d93b 100644 --- a/types/primitive/i32_test.ts +++ b/types/primitive/i32_test.ts @@ -1,5 +1,5 @@ import { i32le, i32be } from "./i32.ts"; -import { assertEquals } from "https://deno.land/std@0.178.0/testing/asserts.ts"; +import { assertEquals } from "std/testing/asserts.ts"; Deno.test("i32", async ({ step }) => { const buff = new ArrayBuffer(4); diff --git a/types/primitive/i64_test.ts b/types/primitive/i64_test.ts index e38259e..986fa3a 100644 --- a/types/primitive/i64_test.ts +++ b/types/primitive/i64_test.ts @@ -1,5 +1,5 @@ import { i64le, i64be } from "./i64.ts"; -import { assertEquals } from "https://deno.land/std@0.178.0/testing/asserts.ts"; +import { assertEquals } from "std/testing/asserts.ts"; Deno.test("i64", async ({ step }) => { const buff = new ArrayBuffer(8); diff --git a/types/primitive/i8_test.ts b/types/primitive/i8_test.ts index 3cbdedc..20ef077 100644 --- a/types/primitive/i8_test.ts +++ b/types/primitive/i8_test.ts @@ -1,5 +1,5 @@ import { i8 } from "./i8.ts"; -import { assertEquals } from "https://deno.land/std@0.178.0/testing/asserts.ts"; +import { assertEquals } from "std/testing/asserts.ts"; Deno.test("i8", async ({ step }) => { const buff = new ArrayBuffer(1); diff --git a/types/primitive/u16_test.ts b/types/primitive/u16_test.ts index a147108..c0c64eb 100644 --- a/types/primitive/u16_test.ts +++ b/types/primitive/u16_test.ts @@ -1,5 +1,5 @@ import { u16le, u16be } from "./u16.ts"; -import { assertEquals } from "https://deno.land/std@0.178.0/testing/asserts.ts"; +import { assertEquals } from "std/testing/asserts.ts"; Deno.test("u16", async ({ step }) => { const buff = new ArrayBuffer(2); diff --git a/types/primitive/u32_test.ts b/types/primitive/u32_test.ts index 9f50e62..88a1542 100644 --- a/types/primitive/u32_test.ts +++ b/types/primitive/u32_test.ts @@ -1,5 +1,5 @@ import { u32le, u32be } from "./u32.ts"; -import { assertEquals } from "https://deno.land/std@0.178.0/testing/asserts.ts"; +import { assertEquals } from "std/testing/asserts.ts"; Deno.test("u32", async ({ step }) => { const buff = new ArrayBuffer(4); diff --git a/types/primitive/u64_test.ts b/types/primitive/u64_test.ts index 690b8d3..fb3d379 100644 --- a/types/primitive/u64_test.ts +++ b/types/primitive/u64_test.ts @@ -1,5 +1,5 @@ import { u64le, u64be } from "./u64.ts"; -import { assertEquals } from "https://deno.land/std@0.178.0/testing/asserts.ts"; +import { assertEquals } from "std/testing/asserts.ts"; Deno.test("u64", async ({ step }) => { const buff = new ArrayBuffer(8); diff --git a/types/primitive/u8_test.ts b/types/primitive/u8_test.ts index 1eabdad..8a82e81 100644 --- a/types/primitive/u8_test.ts +++ b/types/primitive/u8_test.ts @@ -1,5 +1,5 @@ import { u8 } from "./u8.ts"; -import { assertEquals } from "https://deno.land/std@0.178.0/testing/asserts.ts"; +import { assertEquals } from "std/testing/asserts.ts"; Deno.test("u8", async ({ step }) => { const buff = new ArrayBuffer(1); From e8e392650e5dcb7860d8adaf9feae36853ce7b3b Mon Sep 17 00:00:00 2001 From: MierenManz Date: Thu, 27 Apr 2023 20:02:12 +0200 Subject: [PATCH 03/13] fmt --- types/primitive/bool_test.ts | 2 +- types/primitive/f32_test.ts | 2 +- types/primitive/f64_test.ts | 2 +- types/primitive/i16_test.ts | 4 ++-- types/primitive/i32_test.ts | 4 ++-- types/primitive/i64_test.ts | 4 ++-- types/primitive/i8_test.ts | 2 +- types/primitive/u16_test.ts | 4 ++-- types/primitive/u32_test.ts | 4 ++-- types/primitive/u64_test.ts | 4 ++-- types/primitive/u8_test.ts | 2 +- 11 files changed, 17 insertions(+), 17 deletions(-) diff --git a/types/primitive/bool_test.ts b/types/primitive/bool_test.ts index c52ea0b..d1a720a 100644 --- a/types/primitive/bool_test.ts +++ b/types/primitive/bool_test.ts @@ -1,7 +1,7 @@ import { bool } from "./bool.ts"; import { assertEquals } from "std/testing/asserts.ts"; -Deno.test("Boolean", async ({ step }) => { +Deno.test("Boolean", async ({ step }) => { const buff = new ArrayBuffer(1); const dt = new DataView(buff); diff --git a/types/primitive/f32_test.ts b/types/primitive/f32_test.ts index f62e619..7e723eb 100644 --- a/types/primitive/f32_test.ts +++ b/types/primitive/f32_test.ts @@ -1,5 +1,5 @@ import { assertAlmostEquals } from "std/testing/asserts.ts"; -import { f32le, f32be } from "./f32.ts"; +import { f32be, f32le } from "./f32.ts"; Deno.test("f32", async ({ step }) => { const buff = new ArrayBuffer(4); diff --git a/types/primitive/f64_test.ts b/types/primitive/f64_test.ts index d6856ce..30c64e3 100644 --- a/types/primitive/f64_test.ts +++ b/types/primitive/f64_test.ts @@ -1,5 +1,5 @@ import { assertEquals } from "std/testing/asserts.ts"; -import { f64le, f64be } from "./f64.ts"; +import { f64be, f64le } from "./f64.ts"; Deno.test("f64", async ({ step }) => { const buff = new ArrayBuffer(8); diff --git a/types/primitive/i16_test.ts b/types/primitive/i16_test.ts index 7aa2975..da0de74 100644 --- a/types/primitive/i16_test.ts +++ b/types/primitive/i16_test.ts @@ -1,7 +1,7 @@ -import { i16le, i16be } from "./i16.ts"; +import { i16be, i16le } from "./i16.ts"; import { assertEquals } from "std/testing/asserts.ts"; -Deno.test("i16", async ({ step }) => { +Deno.test("i16", async ({ step }) => { const buff = new ArrayBuffer(2); const dt = new DataView(buff); const value = 12; diff --git a/types/primitive/i32_test.ts b/types/primitive/i32_test.ts index f00d93b..b3b703e 100644 --- a/types/primitive/i32_test.ts +++ b/types/primitive/i32_test.ts @@ -1,7 +1,7 @@ -import { i32le, i32be } from "./i32.ts"; +import { i32be, i32le } from "./i32.ts"; import { assertEquals } from "std/testing/asserts.ts"; -Deno.test("i32", async ({ step }) => { +Deno.test("i32", async ({ step }) => { const buff = new ArrayBuffer(4); const dt = new DataView(buff); const value = 12; diff --git a/types/primitive/i64_test.ts b/types/primitive/i64_test.ts index 986fa3a..c9df343 100644 --- a/types/primitive/i64_test.ts +++ b/types/primitive/i64_test.ts @@ -1,7 +1,7 @@ -import { i64le, i64be } from "./i64.ts"; +import { i64be, i64le } from "./i64.ts"; import { assertEquals } from "std/testing/asserts.ts"; -Deno.test("i64", async ({ step }) => { +Deno.test("i64", async ({ step }) => { const buff = new ArrayBuffer(8); const dt = new DataView(buff); const value = 12n; diff --git a/types/primitive/i8_test.ts b/types/primitive/i8_test.ts index 20ef077..dd3d5fd 100644 --- a/types/primitive/i8_test.ts +++ b/types/primitive/i8_test.ts @@ -1,7 +1,7 @@ import { i8 } from "./i8.ts"; import { assertEquals } from "std/testing/asserts.ts"; -Deno.test("i8", async ({ step }) => { +Deno.test("i8", async ({ step }) => { const buff = new ArrayBuffer(1); const dt = new DataView(buff); diff --git a/types/primitive/u16_test.ts b/types/primitive/u16_test.ts index c0c64eb..f75aa0d 100644 --- a/types/primitive/u16_test.ts +++ b/types/primitive/u16_test.ts @@ -1,7 +1,7 @@ -import { u16le, u16be } from "./u16.ts"; +import { u16be, u16le } from "./u16.ts"; import { assertEquals } from "std/testing/asserts.ts"; -Deno.test("u16", async ({ step }) => { +Deno.test("u16", async ({ step }) => { const buff = new ArrayBuffer(2); const dt = new DataView(buff); const value = 12; diff --git a/types/primitive/u32_test.ts b/types/primitive/u32_test.ts index 88a1542..f3dd825 100644 --- a/types/primitive/u32_test.ts +++ b/types/primitive/u32_test.ts @@ -1,7 +1,7 @@ -import { u32le, u32be } from "./u32.ts"; +import { u32be, u32le } from "./u32.ts"; import { assertEquals } from "std/testing/asserts.ts"; -Deno.test("u32", async ({ step }) => { +Deno.test("u32", async ({ step }) => { const buff = new ArrayBuffer(4); const dt = new DataView(buff); const value = 12; diff --git a/types/primitive/u64_test.ts b/types/primitive/u64_test.ts index fb3d379..e429d69 100644 --- a/types/primitive/u64_test.ts +++ b/types/primitive/u64_test.ts @@ -1,7 +1,7 @@ -import { u64le, u64be } from "./u64.ts"; +import { u64be, u64le } from "./u64.ts"; import { assertEquals } from "std/testing/asserts.ts"; -Deno.test("u64", async ({ step }) => { +Deno.test("u64", async ({ step }) => { const buff = new ArrayBuffer(8); const dt = new DataView(buff); const value = 12n; diff --git a/types/primitive/u8_test.ts b/types/primitive/u8_test.ts index 8a82e81..f2ca35a 100644 --- a/types/primitive/u8_test.ts +++ b/types/primitive/u8_test.ts @@ -1,7 +1,7 @@ import { u8 } from "./u8.ts"; import { assertEquals } from "std/testing/asserts.ts"; -Deno.test("u8", async ({ step }) => { +Deno.test("u8", async ({ step }) => { const buff = new ArrayBuffer(1); const dt = new DataView(buff); From b794006cd7596af1fb31a75ddd3cbe5915dbd721 Mon Sep 17 00:00:00 2001 From: MierenManz Date: Thu, 27 Apr 2023 20:13:01 +0200 Subject: [PATCH 04/13] strings --- types/string/fixed_length_test.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 types/string/fixed_length_test.ts diff --git a/types/string/fixed_length_test.ts b/types/string/fixed_length_test.ts new file mode 100644 index 0000000..1ca96a2 --- /dev/null +++ b/types/string/fixed_length_test.ts @@ -0,0 +1,21 @@ +import { assertEquals } from "https://deno.land/std@0.184.0/testing/asserts.ts"; +import { FixedLengthString } from "./fixed_length.ts"; + +Deno.test("Fixed Length String", async ({step}) => { + const value = "Lorem Ipsum"; + const buffer = new ArrayBuffer(value.length); + const dt = new DataView(buffer); + const fixedLengthStringType = new FixedLengthString(value.length); + + await step("read", () => { + const byteView = new Uint8Array(buffer); + byteView.set(value.split("").map(x => x.charCodeAt(0))); + assertEquals(fixedLengthStringType.read(dt) , value); + }); + + await step("write", () => { + const byteView = new Uint8Array(buffer); + fixedLengthStringType.write("LOREM IPSUM", dt); + assertEquals(new TextDecoder().decode(byteView), value.toUpperCase()); + }); +}) \ No newline at end of file From 5e7322ece295acbc7697c96cee0010944eb10765 Mon Sep 17 00:00:00 2001 From: MierenManz Date: Thu, 27 Apr 2023 21:40:00 +0200 Subject: [PATCH 05/13] bitflag tests --- types/bitflags/bitflags16_test.ts | 69 +++++++++++++++++++++++++++++++ types/bitflags/bitflags8_test.ts | 69 +++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 types/bitflags/bitflags16_test.ts create mode 100644 types/bitflags/bitflags8_test.ts diff --git a/types/bitflags/bitflags16_test.ts b/types/bitflags/bitflags16_test.ts new file mode 100644 index 0000000..c84dc7a --- /dev/null +++ b/types/bitflags/bitflags16_test.ts @@ -0,0 +1,69 @@ +import { BitFlags16 } from "./bitflags16.ts"; +import { assertEquals } from "std/testing/asserts.ts"; + +Deno.test("bitflags16", async ({ step }) => { + const buff = new ArrayBuffer(2); + const dt = new DataView(buff); + const bitflags16 = new BitFlags16({ + 1: 1 << 8, + 2: 1 << 9, + 3: 1 << 10, + 4: 1 << 11, + 5: 1 << 12, + 6: 1 << 13, + 7: 1 << 14, + 8: 1 << 15, + }); + + await step("read", () => { + dt.setUint16(0, 0b1111111100000000); + assertEquals(bitflags16.read(dt), { + 1: true, + 2: true, + 3: true, + 4: true, + 5: true, + 6: true, + 7: true, + 8: true, + }); + + dt.setUint16(0, 0b0000000100000000); + assertEquals(bitflags16.read(dt), { + 1: true, + 2: false, + 3: false, + 4: false, + 5: false, + 6: false, + 7: false, + 8: false, + }); + }); + + await step("write", () => { + bitflags16.write({ + 1: true, + 2: true, + 3: true, + 4: true, + 5: true, + 6: true, + 7: true, + 8: true, + }, dt); + assertEquals(dt.getUint16(0), 0b1111111100000000); + + bitflags16.write({ + 1: true, + 2: false, + 3: false, + 4: false, + 5: false, + 6: false, + 7: false, + 8: false, + }, dt); + assertEquals(dt.getUint16(0), 0b0000000100000000); + }); +}); diff --git a/types/bitflags/bitflags8_test.ts b/types/bitflags/bitflags8_test.ts new file mode 100644 index 0000000..a58e942 --- /dev/null +++ b/types/bitflags/bitflags8_test.ts @@ -0,0 +1,69 @@ +import { BitFlags8 } from "./bitflags8.ts"; +import { assertEquals } from "std/testing/asserts.ts"; + +Deno.test("bitflags8", async ({ step }) => { + const buff = new ArrayBuffer(1); + const dt = new DataView(buff); + const bitflags8 = new BitFlags8({ + 1: 1, + 2: 1 << 1, + 3: 1 << 2, + 4: 1 << 3, + 5: 1 << 4, + 6: 1 << 5, + 7: 1 << 6, + 8: 1 << 7, + }); + + await step("read", () => { + dt.setUint8(0, 0b11111111); + assertEquals(bitflags8.read(dt), { + 1: true, + 2: true, + 3: true, + 4: true, + 5: true, + 6: true, + 7: true, + 8: true, + }); + + dt.setUint8(0, 1); + assertEquals(bitflags8.read(dt), { + 1: true, + 2: false, + 3: false, + 4: false, + 5: false, + 6: false, + 7: false, + 8: false, + }); + }); + + await step("write", () => { + bitflags8.write({ + 1: true, + 2: true, + 3: true, + 4: true, + 5: true, + 6: true, + 7: true, + 8: true, + }, dt); + assertEquals(dt.getUint8(0), 0b11111111); + + bitflags8.write({ + 1: true, + 2: false, + 3: false, + 4: false, + 5: false, + 6: false, + 7: false, + 8: false, + }, dt); + assertEquals(dt.getUint8(0), 0b00000001); + }); +}); From ba13e42b2020316868ac6365887d174d925be6fd Mon Sep 17 00:00:00 2001 From: MierenManz Date: Thu, 27 Apr 2023 21:51:08 +0200 Subject: [PATCH 06/13] fmt --- types/string/fixed_length_test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/types/string/fixed_length_test.ts b/types/string/fixed_length_test.ts index 1ca96a2..3d545ab 100644 --- a/types/string/fixed_length_test.ts +++ b/types/string/fixed_length_test.ts @@ -1,7 +1,7 @@ import { assertEquals } from "https://deno.land/std@0.184.0/testing/asserts.ts"; import { FixedLengthString } from "./fixed_length.ts"; -Deno.test("Fixed Length String", async ({step}) => { +Deno.test("Fixed Length String", async ({ step }) => { const value = "Lorem Ipsum"; const buffer = new ArrayBuffer(value.length); const dt = new DataView(buffer); @@ -9,8 +9,8 @@ Deno.test("Fixed Length String", async ({step}) => { await step("read", () => { const byteView = new Uint8Array(buffer); - byteView.set(value.split("").map(x => x.charCodeAt(0))); - assertEquals(fixedLengthStringType.read(dt) , value); + byteView.set(value.split("").map((x) => x.charCodeAt(0))); + assertEquals(fixedLengthStringType.read(dt), value); }); await step("write", () => { @@ -18,4 +18,4 @@ Deno.test("Fixed Length String", async ({step}) => { fixedLengthStringType.write("LOREM IPSUM", dt); assertEquals(new TextDecoder().decode(byteView), value.toUpperCase()); }); -}) \ No newline at end of file +}); From 197e29d2aefa4e5432d305c253070f8302673c34 Mon Sep 17 00:00:00 2001 From: MierenManz Date: Thu, 27 Apr 2023 22:19:51 +0200 Subject: [PATCH 07/13] test --- types/bitflags/bitflags32_test.ts | 110 ++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 types/bitflags/bitflags32_test.ts diff --git a/types/bitflags/bitflags32_test.ts b/types/bitflags/bitflags32_test.ts new file mode 100644 index 0000000..6f39728 --- /dev/null +++ b/types/bitflags/bitflags32_test.ts @@ -0,0 +1,110 @@ +import { BitFlags32 } from "./bitflags32.ts"; +import { assertEquals } from "std/testing/asserts.ts"; + +Deno.test("bitflags32", async ({ step }) => { + const buff = new ArrayBuffer(4); + const dt = new DataView(buff); + const bitflags32 = new BitFlags32({ + 16: 0x10000, + 17: 0x20000, + 18: 0x40000, + 19: 0x80000, + 20: 0x100000, + 21: 0x200000, + 22: 0x400000, + 23: 0x800000, + 24: 0x1000000, + 25: 0x2000000, + 26: 0x4000000, + 27: 0x8000000, + 28: 0x10000000, + 29: 0x20000000, + 30: 0x40000000, + 31: 0x80000000, + }); + + await step("read", () => { + dt.setUint32(0, 0xFFFF0000); + console.log("0x" + dt.getUint32(0).toString(16).toUpperCase()); + assertEquals(bitflags32.read(dt), { + 16: true, + 17: true, + 18: true, + 19: true, + 20: true, + 21: true, + 22: true, + 23: true, + 24: true, + 25: true, + 26: true, + 27: true, + 28: true, + 29: true, + 30: true, + 31: true, + }); + + dt.setUint32(0, 0x10000); + assertEquals(bitflags32.read(dt), { + 16: true, + 17: false, + 18: false, + 19: false, + 20: false, + 21: false, + 22: false, + 23: false, + 24: false, + 25: false, + 26: false, + 27: false, + 28: false, + 29: false, + 30: false, + 31: false, + }); + }); + + await step("write", () => { + bitflags32.write({ + 16: true, + 17: true, + 18: true, + 19: true, + 20: true, + 21: true, + 22: true, + 23: true, + 24: true, + 25: true, + 26: true, + 27: true, + 28: true, + 29: true, + 30: true, + 31: true, + }, dt); + assertEquals(dt.getUint32(0), 0xFFFF0000); + + bitflags32.write({ + 16: true, + 17: false, + 18: false, + 19: false, + 20: false, + 21: false, + 22: false, + 23: false, + 24: false, + 25: false, + 26: false, + 27: false, + 28: false, + 29: false, + 30: false, + 31: false, + }, dt); + assertEquals(dt.getUint32(0), 0x10000); + }); +}); From af12988cdd0fd80ab817a4870fe351bdb4bcaa2c Mon Sep 17 00:00:00 2001 From: MierenManz Date: Thu, 27 Apr 2023 22:22:50 +0200 Subject: [PATCH 08/13] remove console log --- types/bitflags/bitflags64_test.ts | 69 +++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 types/bitflags/bitflags64_test.ts diff --git a/types/bitflags/bitflags64_test.ts b/types/bitflags/bitflags64_test.ts new file mode 100644 index 0000000..729aaa0 --- /dev/null +++ b/types/bitflags/bitflags64_test.ts @@ -0,0 +1,69 @@ +import { BitFlags64 } from "./bitflags64.ts"; +import { assertEquals } from "std/testing/asserts.ts"; + +Deno.test("bitflags64", async ({ step }) => { + const buff = new ArrayBuffer(8); + const dt = new DataView(buff); + const bitflags64 = new BitFlags64({ + 1: 1n, + 2: BigInt(1 << 1), + 3: BigInt(1 << 2), + 4: BigInt(1 << 3), + 5: BigInt(1 << 4), + 6: BigInt(1 << 5), + 7: BigInt(1 << 6), + 8: BigInt(1 << 7), + }); + + await step("read", () => { + dt.setUint8(7, 0b11111111); + assertEquals(bitflags64.read(dt), { + 1: true, + 2: true, + 3: true, + 4: true, + 5: true, + 6: true, + 7: true, + 8: true, + }); + + dt.setUint8(7, 1); + assertEquals(bitflags64.read(dt), { + 1: true, + 2: false, + 3: false, + 4: false, + 5: false, + 6: false, + 7: false, + 8: false, + }); + }); + + await step("write", () => { + bitflags64.write({ + 1: true, + 2: true, + 3: true, + 4: true, + 5: true, + 6: true, + 7: true, + 8: true, + }, dt); + assertEquals(dt.getUint8(7), 0b11111111); + + bitflags64.write({ + 1: true, + 2: false, + 3: false, + 4: false, + 5: false, + 6: false, + 7: false, + 8: false, + }, dt); + assertEquals(dt.getUint8(7), 0b00000001); + }); +}); From 639fe9494e3ab18018cceb14c0d54a2d8464fbc9 Mon Sep 17 00:00:00 2001 From: MierenManz Date: Thu, 27 Apr 2023 22:22:56 +0200 Subject: [PATCH 09/13] fuck.. --- types/bitflags/bitflags32_test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/types/bitflags/bitflags32_test.ts b/types/bitflags/bitflags32_test.ts index 6f39728..5cb5265 100644 --- a/types/bitflags/bitflags32_test.ts +++ b/types/bitflags/bitflags32_test.ts @@ -25,7 +25,6 @@ Deno.test("bitflags32", async ({ step }) => { await step("read", () => { dt.setUint32(0, 0xFFFF0000); - console.log("0x" + dt.getUint32(0).toString(16).toUpperCase()); assertEquals(bitflags32.read(dt), { 16: true, 17: true, From 65b4ae4ea93053f741895e3fed51df6fff4953cb Mon Sep 17 00:00:00 2001 From: MierenManz Date: Thu, 27 Apr 2023 23:35:45 +0200 Subject: [PATCH 10/13] x --- types/array/array_buffer_test.ts | 22 ++++++++++++++++++++++ types/array/array_test.ts | 20 ++++++++++++++++++++ types/array/typed_array_test.ts | 18 ++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 types/array/array_buffer_test.ts create mode 100644 types/array/array_test.ts create mode 100644 types/array/typed_array_test.ts diff --git a/types/array/array_buffer_test.ts b/types/array/array_buffer_test.ts new file mode 100644 index 0000000..aa74c30 --- /dev/null +++ b/types/array/array_buffer_test.ts @@ -0,0 +1,22 @@ +import { ArrayBufferType } from "./array_buffer.ts"; +import { assertEquals } from "std/testing/asserts.ts"; + +Deno.test("Array Buffer", async ({ step }) => { + const ab = new ArrayBuffer(4); + const dt = new DataView(ab); + const byteView = new Uint8Array(ab); + const abType = new ArrayBufferType(4); + + await step("read", () => { + byteView.set([1, 2, 3, 4]); + const newAB = abType.read(dt); + assertEquals(new Uint8Array(newAB), byteView); + }); + + await step("write", () => { + byteView.set([0, 0, 0, 0]); + abType.write(Uint8Array.of(1, 2, 3, 4).buffer, dt); + + assertEquals(byteView, Uint8Array.of(1, 2, 3, 4)); + }); +}); diff --git a/types/array/array_test.ts b/types/array/array_test.ts new file mode 100644 index 0000000..5595173 --- /dev/null +++ b/types/array/array_test.ts @@ -0,0 +1,20 @@ +import { assertEquals } from "https://deno.land/std@0.184.0/testing/asserts.ts"; +import { u8 } from "../primitive/u8.ts"; +import { ArrayType } from "./array.ts"; + +Deno.test("Array Type", async ({ step }) => { + const ab = new ArrayBuffer(2); + const dt = new DataView(ab); + const byteView = new Uint8Array(ab); + const byteArray = new ArrayType(u8, 2); + + await step("read", () => { + byteView.set([1, 2]); + assertEquals(byteArray.read(dt), [1, 2]); + }); + + await step("write", () => { + byteArray.write([3, 4], dt); + assertEquals(byteView, Uint8Array.of(3, 4)); + }); +}); diff --git a/types/array/typed_array_test.ts b/types/array/typed_array_test.ts new file mode 100644 index 0000000..48ba6cd --- /dev/null +++ b/types/array/typed_array_test.ts @@ -0,0 +1,18 @@ +import { assertEquals } from "std/testing/asserts.ts"; +import { TypedArrayType } from "./typed_array.ts"; + +Deno.test("TypedArray", async ({ step }) => { + const ab = new ArrayBuffer(2); + const byteView = new Uint8Array(ab); + const dt = new DataView(ab); + const typedArray = new TypedArrayType(Uint8Array, 2); + await step("read", () => { + byteView.set([1, 2]); + assertEquals(typedArray.read(dt), Uint8Array.of(1, 2)); + }); + + await step("write", () => { + typedArray.write(Uint8Array.of(3, 4), dt); + assertEquals(byteView, Uint8Array.of(3, 4)); + }); +}); From 6ff3bc81b5a1c1c282f65ac145f6166b5b927ea9 Mon Sep 17 00:00:00 2001 From: MierenManz Date: Mon, 1 May 2023 17:10:10 +0200 Subject: [PATCH 11/13] fix last test --- types/array/typed_array.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/array/typed_array.ts b/types/array/typed_array.ts index b526dd3..b05c6a7 100644 --- a/types/array/typed_array.ts +++ b/types/array/typed_array.ts @@ -44,7 +44,7 @@ export class TypedArrayType write(value: T, dataView: DataView, byteOffset = 0) { // @ts-ignore Sets the dataView buffer to the value - new this.Constructor(dataView, byteOffset).set(value); + new this.Constructor(dataView.buffer, byteOffset).set(value); } view(dataView: DataView, byteOffset = 0): T { From 5a895e23e5725d37fa841fc10e422f567b0b65d0 Mon Sep 17 00:00:00 2001 From: MierenManz Date: Mon, 1 May 2023 17:10:22 +0200 Subject: [PATCH 12/13] x idk --- deno.lock | 3 ++- types/leb128/_i64leb128.ts | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/deno.lock b/deno.lock index 55b8a59..61f4b55 100644 --- a/deno.lock +++ b/deno.lock @@ -8,7 +8,8 @@ }, "npm": { "specifiers": { - "wabt": "wabt@1.0.32" + "wabt": "wabt@1.0.32", + "wabt@1.0.32": "wabt@1.0.32" }, "packages": { "wabt@1.0.32": { diff --git a/types/leb128/_i64leb128.ts b/types/leb128/_i64leb128.ts index 4d717f5..85dfb29 100644 --- a/types/leb128/_i64leb128.ts +++ b/types/leb128/_i64leb128.ts @@ -3,9 +3,9 @@ const bytes = Uint8Array.from( atob( - "AGFzbQEAAAABDAJgAX8Cfn9gAX4BfwMDAgABBQMBAAEHGQMGbWVtb3J5AgAEcmVhZAAABXdyaXRlAAEKhAECQwEDfgJAA0AgADEAACIDQv8AgyAChiABhCEBIAJCB3wiAiADQoABg1ANASAAQQFqIQBCxgBUDQALAAsgASACQgeApws+AQF/AkADQCAAQoB/g1ANASABIABC/wCDQoABhDwAACAAQgeIIQAgAUEBaiEBDAALCyABIAA8AABBASABags=", + "AGFzbQEAAAABDAJgAX8Cfn9gAX4BfwMDAgABBQMBAAEHGQMGbWVtb3J5AgAEcmVhZAAABXdyaXRlAAEKhAECQwEDfgJAA0AgADEAACIDQv8AgyAChiABhCEBIAJCB3wiAiADQoABg1ANASAAQQFqIQBCxgBUDQALAAsgASACQgeApws+AQF/AkADQCAAQoB/g1ANASABIABC/wCDQoABhDwAACAAQgeIIQAgAUEBaiEBDAALCyABIAA8AABBASABags=" ), - (c) => c.charCodeAt(0), + (c) => c.charCodeAt(0) ); const { instance } = await WebAssembly.instantiate(bytes); From 3e71edd71d80e2a59c971a8ab599526f1a6c9fcc Mon Sep 17 00:00:00 2001 From: MierenManz Date: Mon, 1 May 2023 17:10:40 +0200 Subject: [PATCH 13/13] !? --- types/leb128/_i64leb128.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/leb128/_i64leb128.ts b/types/leb128/_i64leb128.ts index 85dfb29..4d717f5 100644 --- a/types/leb128/_i64leb128.ts +++ b/types/leb128/_i64leb128.ts @@ -3,9 +3,9 @@ const bytes = Uint8Array.from( atob( - "AGFzbQEAAAABDAJgAX8Cfn9gAX4BfwMDAgABBQMBAAEHGQMGbWVtb3J5AgAEcmVhZAAABXdyaXRlAAEKhAECQwEDfgJAA0AgADEAACIDQv8AgyAChiABhCEBIAJCB3wiAiADQoABg1ANASAAQQFqIQBCxgBUDQALAAsgASACQgeApws+AQF/AkADQCAAQoB/g1ANASABIABC/wCDQoABhDwAACAAQgeIIQAgAUEBaiEBDAALCyABIAA8AABBASABags=" + "AGFzbQEAAAABDAJgAX8Cfn9gAX4BfwMDAgABBQMBAAEHGQMGbWVtb3J5AgAEcmVhZAAABXdyaXRlAAEKhAECQwEDfgJAA0AgADEAACIDQv8AgyAChiABhCEBIAJCB3wiAiADQoABg1ANASAAQQFqIQBCxgBUDQALAAsgASACQgeApws+AQF/AkADQCAAQoB/g1ANASABIABC/wCDQoABhDwAACAAQgeIIQAgAUEBaiEBDAALCyABIAA8AABBASABags=", ), - (c) => c.charCodeAt(0) + (c) => c.charCodeAt(0), ); const { instance } = await WebAssembly.instantiate(bytes);