import test from "node:test"; import assert from "node:assert/strict"; import { parseSortValue, compareSortValues, sortableTable } from "../src/list_sorting.js"; test("zero-padded and ordinary lap times sort chronologically", () => { const times = ["00:59.000", "0:10.000", "01:00.000", "00:09,500", "1:02:03.000"]; assert.deepEqual(times.map(parseSortValue), [59, 10, 60, 9.5, 3723]); assert.deepEqual([...times].sort((a, b) => compareSortValues(parseSortValue(a), parseSortValue(b))), ["00:09,500", "0:10.000", "00:59.000", "01:00.000", "1:02:03.000"]); }); test("distinct numeric-looking names have deterministic ascending and descending order", () => { for (const [left, right] of [["09", "9"], ["Car 09", "Car 9"], ["009", "09"]]) { const comparison = compareSortValues(left, right); assert.notEqual(comparison, 0); assert.equal(Math.sign(comparison), -Math.sign(compareSortValues(right, left))); assert.equal(Math.sign(comparison), -Math.sign(compareSortValues(left, right, "desc"))); } assert.ok(compareSortValues("Car 2", "Car 10") < 0); }); test("missing times stay last in both sort directions", () => { for (const direction of ["asc", "desc"]) { assert.ok(compareSortValues(null, 20, direction) > 0); assert.ok(compareSortValues(20, NaN, direction) < 0); } assert.equal(parseSortValue("-"), null); assert.equal(parseSortValue("-00:01.500"), -1.5); assert.equal(parseSortValue("+0.250s"), 0.25); }); test("tables can declare names and identifiers as text columns", () => { assert.match(sortableTable('
', 'timing-passings', [1, 2, 3]), /data-sort-text-columns="1,2,3"/); });