74 lines
3.2 KiB
TypeScript
74 lines
3.2 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import test from "node:test";
|
|
import { parseHeader } from "../src/dbc/codec";
|
|
import { DbcTable } from "../src/dbc/table";
|
|
import { DbcSchemaBundle } from "../src/dbc/types";
|
|
|
|
const extensionRoot = path.resolve(__dirname, "..");
|
|
const projectRoot = path.resolve(extensionRoot, "..");
|
|
const bundle = JSON.parse(
|
|
fs.readFileSync(path.join(extensionRoot, "schemas", "12340.json"), "utf8")
|
|
) as DbcSchemaBundle;
|
|
|
|
const projectDbcs = [
|
|
"assets/dbc/3.3.5a/CreatureModelData.dbc",
|
|
"assets/dbc/3.3.5a/CreatureDisplayInfo.dbc",
|
|
"src/Data/ruRU/patch-ruRU-Z/DBFilesClient/SpellVisualKitModelAttach.dbc",
|
|
"src/Data/ruRU/patch-ruRU-Z/DBFilesClient/Spell.dbc",
|
|
"src/Data/ruRU/patch-ruRU-Z/DBFilesClient/CreatureDisplayInfoExtra.dbc",
|
|
"src/Data/ruRU/patch-ruRU-Z/DBFilesClient/BarberShopStyle.dbc",
|
|
"src/Data/ruRU/patch-ruRU-5/DBFilesClient/Achievement.dbc",
|
|
"src/Data/patch-Z/DBFilesClient/LFGDungeons.dbc",
|
|
"src/Data/patch-Z/DBFilesClient/ItemDisplayInfo.dbc",
|
|
"src/Data/patch-Z/DBFilesClient/Item.dbc"
|
|
];
|
|
|
|
test("bundled build 12340 schemas match every project DBC record size", () => {
|
|
for (const relativePath of projectDbcs) {
|
|
const fullPath = path.join(projectRoot, ...relativePath.split("/"));
|
|
const bytes = fs.readFileSync(fullPath);
|
|
const header = parseHeader(bytes);
|
|
const tableName = path.basename(relativePath, ".dbc").toLowerCase();
|
|
const schema = bundle.tables[tableName];
|
|
assert.ok(schema, `Missing schema for ${relativePath}`);
|
|
assert.equal(schema.recordSize, header.recordSize, `Record size mismatch for ${relativePath}`);
|
|
}
|
|
});
|
|
|
|
test("opens every project DBC with named columns", () => {
|
|
for (const relativePath of projectDbcs) {
|
|
const fullPath = path.join(projectRoot, ...relativePath.split("/"));
|
|
const bytes = fs.readFileSync(fullPath);
|
|
const tableName = path.basename(relativePath, ".dbc").toLowerCase();
|
|
const schema = bundle.tables[tableName]!;
|
|
const table = new DbcTable(bytes, schema);
|
|
const page = table.getPage(0, 1);
|
|
assert.equal(page.rows.length, table.header.recordCount > 0 ? 1 : 0);
|
|
assert.equal(page.rows[0]?.length ?? schema.columns.length, schema.columns.length);
|
|
}
|
|
});
|
|
|
|
test("round-trips project numeric and localized-string tables", () => {
|
|
for (const relativePath of [projectDbcs[2]!, projectDbcs[5]!]) {
|
|
const fullPath = path.join(projectRoot, ...relativePath.split("/"));
|
|
const bytes = fs.readFileSync(fullPath);
|
|
const tableName = path.basename(relativePath, ".dbc").toLowerCase();
|
|
const schema = bundle.tables[tableName]!;
|
|
const source = new DbcTable(bytes, schema);
|
|
const reparsed = new DbcTable(source.serialize(), schema);
|
|
assert.equal(reparsed.header.recordCount, source.header.recordCount);
|
|
|
|
for (const rowIndex of [0, Math.floor(source.rows.length / 2), source.rows.length - 1]) {
|
|
for (let columnIndex = 0; columnIndex < schema.columns.length; columnIndex += 1) {
|
|
assert.equal(
|
|
reparsed.getCell(rowIndex, columnIndex),
|
|
source.getCell(rowIndex, columnIndex),
|
|
`${relativePath}, row ${rowIndex + 1}, ${schema.columns[columnIndex]!.name}`
|
|
);
|
|
}
|
|
}
|
|
}
|
|
});
|