Skip to content

Commit

Permalink
chore(msgpack): format test names (#4381)
Browse files Browse the repository at this point in the history
  • Loading branch information
timreichen authored Feb 24, 2024
1 parent 8693c81 commit 9882fbf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
30 changes: 15 additions & 15 deletions msgpack/decode_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
import { assertEquals, assertThrows } from "../assert/mod.ts";
import { decode } from "./decode.ts";

Deno.test("positive fixint", () => {
Deno.test("decode() handles positive fixint", () => {
for (let i = 0; i <= 0x7f; i++) {
assertEquals(decode(Uint8Array.of(i)), i);
}
});

Deno.test("fixmap", () => {
Deno.test("decode() handles fixmap", () => {
const map = { "a": 2, "b": 3 };
const encodedMap = [0b1010_0001, 97, 2, 0b1010_0001, 98, 3];

assertEquals(decode(Uint8Array.of(0b10000000 | 2, ...encodedMap)), map);
});

Deno.test("fixarray", () => {
Deno.test("decode() handles fixarray", () => {
const array = [0, 1, 2, 3, 4, 5, 6];

assertEquals(
Expand All @@ -25,7 +25,7 @@ Deno.test("fixarray", () => {
);
});

Deno.test("fixstr", () => {
Deno.test("decode() handles fixstr", () => {
const str = "hello world!";
const encoded = new TextEncoder().encode(str);

Expand All @@ -35,14 +35,14 @@ Deno.test("fixstr", () => {
);
});

Deno.test("nil, (never used), false, true", () => {
Deno.test("decode() handles nil, (never used), false, true", () => {
assertEquals(decode(Uint8Array.of(0xc0)), null); // nil
assertThrows(() => decode(Uint8Array.of(0xc1))); // (never used)
assertEquals(decode(Uint8Array.of(0xc2)), false); // false
assertEquals(decode(Uint8Array.of(0xc3)), true); // true
});

Deno.test("bin 8, bin 16, bin 32", () => {
Deno.test("decode() handles bin 8, bin 16, bin 32", () => {
const arr = Uint8Array.of(0, 1, 2, 3, 4, 5, 6, 7);
assertEquals(decode(Uint8Array.of(0xc4, arr.length, ...arr)), arr);
assertEquals(decode(Uint8Array.of(0xc5, 0, arr.length, ...arr)), arr);
Expand All @@ -52,13 +52,13 @@ Deno.test("bin 8, bin 16, bin 32", () => {
);
});

Deno.test("ext 8, ext 16, ext 32", () => {
Deno.test("decode() handles ext 8, ext 16, ext 32", () => {
assertThrows(() => decode(Uint8Array.of(0xc7)));
assertThrows(() => decode(Uint8Array.of(0xc8)));
assertThrows(() => decode(Uint8Array.of(0xc9)));
});

Deno.test("float 32, float 64", () => {
Deno.test("decode() handles float 32, float 64", () => {
assertEquals(
decode(Uint8Array.of(0xca, 0x43, 0xd2, 0x58, 0x52)),
420.69000244140625,
Expand All @@ -71,7 +71,7 @@ Deno.test("float 32, float 64", () => {
);
});

Deno.test("uint8, uint16, uint32, uint64", () => {
Deno.test("decode() handles uint8, uint16, uint32, uint64", () => {
assertEquals(decode(Uint8Array.of(0xcc, 0xff)), 255);
assertEquals(decode(Uint8Array.of(0xcd, 0xff, 0xff)), 65535);
assertEquals(
Expand All @@ -86,7 +86,7 @@ Deno.test("uint8, uint16, uint32, uint64", () => {
);
});

Deno.test("int8, int16, int32, int64", () => {
Deno.test("decode() handles int8, int16, int32, int64", () => {
assertEquals(decode(Uint8Array.of(0xd0, 0x80)), -128);
assertEquals(decode(Uint8Array.of(0xd1, 0x80, 0x00)), -32768);
assertEquals(
Expand All @@ -101,15 +101,15 @@ Deno.test("int8, int16, int32, int64", () => {
);
});

Deno.test("fixext 1, fixext 2, fixext 4, fixext 8, fixext 16", () => {
Deno.test("decode() handles fixext 1, fixext 2, fixext 4, fixext 8, fixext 16", () => {
assertThrows(() => decode(Uint8Array.of(0xd4)));
assertThrows(() => decode(Uint8Array.of(0xd5)));
assertThrows(() => decode(Uint8Array.of(0xd6)));
assertThrows(() => decode(Uint8Array.of(0xd7)));
assertThrows(() => decode(Uint8Array.of(0xd8)));
});

Deno.test("str 8, str 16, str 32", () => {
Deno.test("decode() handles str 8, str 16, str 32", () => {
const str = "hello world!";
const encoded = new TextEncoder().encode(str);

Expand All @@ -124,7 +124,7 @@ Deno.test("str 8, str 16, str 32", () => {
);
});

Deno.test("array 16, array 32", () => {
Deno.test("decode() handles array 16, array 32", () => {
const array = [0, 1, 2, 3, 4, 5, 6];

assertEquals(
Expand All @@ -137,15 +137,15 @@ Deno.test("array 16, array 32", () => {
);
});

Deno.test("map 16, map 32", () => {
Deno.test("decode() handles map 16, map 32", () => {
const map = { "a": 2, "b": 3 };
const encodedMap = [0b1010_0001, 97, 2, 0b1010_0001, 98, 3];

assertEquals(decode(Uint8Array.of(0xde, 0, 2, ...encodedMap)), map);
assertEquals(decode(Uint8Array.of(0xdf, 0, 0, 0, 2, ...encodedMap)), map);
});

Deno.test("negative fixint", () => {
Deno.test("decode() handles negative fixint", () => {
for (let i = -32; i <= -1; i++) {
assertEquals(decode(Uint8Array.of(i)), i);
}
Expand Down
20 changes: 10 additions & 10 deletions msgpack/encode_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { decode, encode } from "./mod.ts";
const moduleDir = path.dirname(path.fromFileUrl(import.meta.url));
const testdataDir = path.resolve(moduleDir, "testdata");

Deno.test("testdata", () => {
Deno.test("encode() handles testdata", () => {
const one = JSON.parse(
Deno.readTextFileSync(path.join(testdataDir, "1.json")),
);
Expand All @@ -34,7 +34,7 @@ Deno.test("testdata", () => {
assertEquals(decode(encode(five)), five);
});

Deno.test("positive numbers", () => {
Deno.test("encode() handles positive numbers", () => {
assertEquals(encode(1), Uint8Array.of(1));
assertEquals(decode(encode(1)), 1);

Expand All @@ -54,7 +54,7 @@ Deno.test("positive numbers", () => {
assertEquals(decode(encode(20000000000)), 20000000000);
});

Deno.test("negative numbers", () => {
Deno.test("encode() handles negative numbers", () => {
assertEquals(encode(-1), Uint8Array.of(255));
assertEquals(decode(encode(-1)), -1);

Expand All @@ -74,15 +74,15 @@ Deno.test("negative numbers", () => {
assertEquals(decode(encode(-600000000000)), -600000000000);
});

Deno.test("floats", () => {
Deno.test("encode() handles floats", () => {
assertEquals(
encode(0.3),
Uint8Array.of(0xcb, 63, 211, 51, 51, 51, 51, 51, 51),
);
assertEquals(decode(encode(0.3)), 0.3);
});

Deno.test("bigints", () => {
Deno.test("encode() handles bigints", () => {
assertEquals(encode(0n), Uint8Array.of(0xcf, 0, 0, 0, 0, 0, 0, 0, 0));
assertEquals(decode(encode(0n)), 0n);
assertEquals(
Expand All @@ -102,7 +102,7 @@ Deno.test("bigints", () => {
assertThrows(() => encode(-99999999999999999999999n));
});

Deno.test("strings", () => {
Deno.test("encode() handles strings", () => {
assertEquals(
encode("hello world"),
Uint8Array.of(171, 104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100),
Expand Down Expand Up @@ -138,7 +138,7 @@ Deno.test("strings", () => {
assertEquals(decode(encode(reallyLongString)), reallyLongString);
});

Deno.test("arrays", () => {
Deno.test("encode() handles arrays", () => {
const arr0: never[] = [];
assertEquals(decode(encode(arr0)), arr0);

Expand All @@ -152,7 +152,7 @@ Deno.test("arrays", () => {
assertEquals(decode(encode(nestedArr)), nestedArr);
});

Deno.test("maps", () => {
Deno.test("encode() handles maps", () => {
const map0 = {};
assertEquals(decode(encode(map0)), map0);

Expand All @@ -163,7 +163,7 @@ Deno.test("maps", () => {
assertEquals(decode(encode(nestedMap)), nestedMap);
});

Deno.test("huge array with 100k objects", () => {
Deno.test("encode() handles huge array with 100k objects", () => {
const bigArray = [];
for (let i = 0; i < 100000; i++) {
bigArray.push({ a: { i: `${i}` }, i: i });
Expand All @@ -173,7 +173,7 @@ Deno.test("huge array with 100k objects", () => {
assertEquals(decode(encode(bigObject)), bigObject);
});

Deno.test("huge object with 100k properties", () => {
Deno.test("encode() handles huge object with 100k properties", () => {
const bigObject = {};
for (let i = 0; i < 100000; i++) {
const _ = Object.defineProperty(bigObject, `prop_${i}`, {
Expand Down

0 comments on commit 9882fbf

Please sign in to comment.