This commit is contained in:
Nathan Rashleigh committed 2026-05-26 16:27:50 +10:00
1 parent 32adb5ddac
commit 1e49010aa9
17 files changed
+1049

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
import { expect, test } from "bun:test";
import { encodeDevicesql } from "../src/pdb/strings.ts";
test("empty encodes to 0x03", () => {
expect(Array.from(encodeDevicesql(""))).toEqual([0x03]);
});
test("short ascii uses short form", () => {
const out = encodeDevicesql("ABC");
// length = 3+1 = 4; (4<<1)|1 = 9
expect(out[0]).toBe(9);
expect(Array.from(out.slice(1))).toEqual([0x41, 0x42, 0x43]);
});
test("non-ascii uses utf-16 form", () => {
const out = encodeDevicesql("é");
expect(out[0]).toBe(0x90);
// total_length = utf16 bytes (2) + 4 = 6
expect(out[1]).toBe(6);
expect(out[2]).toBe(0);
expect(out[3]).toBe(0);
expect(out[4]).toBe(0xe9);
expect(out[5]).toBe(0x00);
});
+30
View File
@@ -0,0 +1,30 @@
import { expect, test } from "bun:test";
import { mkdtemp, readFile, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { newDatabase, newTrack } from "../src/model.ts";
import { writePdb } from "../src/pdb/writer.ts";
import { PAGE_SIZE } from "../src/pdb/pager.ts";
test("writes a multi-page-aligned pdb file", async () => {
const dir = await mkdtemp(join(tmpdir(), "maple-ts-"));
try {
const db = newDatabase();
db.artists.push({ id: 1, name: "A" });
db.albums.push({ id: 1, name: "Alb", artist_id: 1 });
db.tracks.push(newTrack({
id: 1, title: "T", artist_id: 1, album_id: 1,
filename: "t.mp3", file_path: "/Contents/A/Alb/t.mp3",
}));
db.playlist_nodes.push({ id: 1, parent_id: 0, sort_order: 1, name: "P", is_folder: false });
db.playlist_entries.push({ playlist_id: 1, track_id: 1, entry_index: 1 });
const out = join(dir, "export.pdb");
await writePdb(db, out);
const buf = await readFile(out);
expect(buf.length % PAGE_SIZE).toBe(0);
expect(buf.length).toBeGreaterThanOrEqual(PAGE_SIZE * 6);
} finally {
await rm(dir, { recursive: true, force: true });
}
});