32 lines
998 B
TypeScript
32 lines
998 B
TypeScript
import { expect, test } from "bun:test";
|
|
import { uint_bytes_to_num, utf8_decode, utf8_encode } from "./tools";
|
|
|
|
test("parse_uint - 0xFF", () => {
|
|
expect(uint_bytes_to_num(new Uint8Array([0x0, 0x0, 0x0, 0xFF]))).toBe(0xFF);
|
|
});
|
|
|
|
test("parse_uint - 0xFF00", () => {
|
|
expect(uint_bytes_to_num(new Uint8Array([0x0, 0x0, 0xFF, 0x0]))).toBe(0xFF00);
|
|
});
|
|
|
|
test("parse_uint - 0xFF0000", () => {
|
|
expect(uint_bytes_to_num(new Uint8Array([0x0, 0xFF, 0x0, 0x0]))).toBe(0xFF0000);
|
|
});
|
|
|
|
test("parse_uint - 0xFF000000", () => {
|
|
expect(uint_bytes_to_num(new Uint8Array([0xFF, 0x0, 0x0, 0x0]))).toBe(0xFF000000);
|
|
});
|
|
|
|
test("decode_utf8 - \"test\"", () => {
|
|
expect(utf8_decode(new Uint8Array([0x74, 0x65, 0x73, 0x74]))).toBe("test");
|
|
});
|
|
|
|
test("encode_utf8 - \"test\"", () => {
|
|
expect(utf8_encode("test")).toMatchObject(new Uint8Array([0x74, 0x65, 0x73, 0x74]));
|
|
});
|
|
|
|
test("encode_decode_utf8 - \"Hello, world!\"", () => {
|
|
const text = "Hello, world!";
|
|
expect(utf8_decode(utf8_encode(text))).toBe(text);
|
|
});
|