Files
xxditb/tests/bs/index.js
T
2026-09-24 11:16:57 -05:00

67 lines
2.6 KiB
JavaScript

import { test, read } from "$TEST_HELPER"
import { XXD } from "$PROJECT/src/XXD.src";
const OWN_TEST_DIR = "$PROJECT/tests/bs/";
const PLAINTEXT_INPUT_FILE = "xxd-8.2.3995.c";
const BIN_FILE = "256.bin";
test(function handcrafted_byte_array() {
let bytes = Uint8Array.from([
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8,
0xF7, 0xF6, 0xF5, 0xF4, 0xF3, 0xF2, 0xF1, 0xF0
]);
let xxd = new XXD(bytes);
xxd.exec();
let output = String(xxd);
test.is(output,
"00000000: 0001 0203 0405 0607 0809 0a0b 0c0d 0e0f ................" +
"\n00000010: fffe fdfc fbfa f9f8 f7f6 f5f4 f3f2 f1f0 ................" +
"\n"
);
})
XXD.from = function(bytes) {
let doer = new XXD(bytes);
doer.exec();
return doer;
}
test(function two_lines() {
return read(OWN_TEST_DIR + PLAINTEXT_INPUT_FILE, true).then((bytes) => {
let output = String(XXD.from(bytes));
test.ok(output.startsWith(
"00000000: 2f2a 2078 7864 3a20 6d79 2068 6578 6475 /* xxd: my hexdu" +
"\n00000010: 6d70 2066 6163 696c 6974 792e 206a 770a mp facility. jw." +
"\n"
));
});
})
test(function compressed_tarball_halfblock() {
return read(OWN_TEST_DIR + BIN_FILE, true).then((bytes) => {
let output = String(XXD.from(bytes));
test.is(output,
"00000000: fd37 7a58 5a00 0004 e6d6 b446 0200 2101 .7zXZ......F..!." +
"\n00000010: 1600 0000 742f e5a3 e404 1bef fe5d 0038 ....t/.......].8" +
"\n00000020: 184b 766c d90a 4eb8 9ab3 cfa1 b304 ab25 .Kvl..N........%" +
"\n00000030: 78fc 9ea5 cda2 07a8 216b 11a0 a07b e145 x.......!k...{.E" +
"\n00000040: 18c6 60cb 1c18 a2fd 1144 3f10 697d 0284 ..`......D?.i}.." +
"\n00000050: de74 489f 5b42 619c 1a32 4358 9238 4ac5 .tH.[Ba..2CX.8J." +
"\n00000060: 9fea cc65 5db7 37d4 01d7 163d ca8e 7440 ...e].7....=..t@" +
"\n00000070: ab8f ec6a 3cbf a931 adef 650a 62bf 8560 ...j<..1..e.b..`" +
"\n00000080: 9002 b8a7 996f 404e 1a2c b240 2e1b 7169 .....o@N.,.@..qi" +
"\n00000090: ec0f 5eb4 cf58 c564 fb41 9ba0 0e7b d632 ..^..X.d.A...{.2" +
"\n000000a0: 1692 999b 9746 61c3 f27d 4ed9 fbf7 9931 .....Fa..}N....1" +
"\n000000b0: 1bf5 f13b 979e e66a d192 cd47 48f7 06fd ...;...j...GH..." +
"\n000000c0: c0f0 0e2d 08ac 93a5 7354 5960 8704 aa27 ...-....sTY`...'" +
"\n000000d0: 2256 5446 206b 82cf 1ebb cdc6 a450 e784 \"VTF k.......P.." +
"\n000000e0: 744e 5149 8f85 8ab7 8fac e330 0e0c 498a tNQI.......0..I." +
"\n000000f0: c11b b264 ce33 55b1 408e ba41 59e9 9d6e ...d.3U.@..AY..n" +
"\n"
);
});
})