Files
sprites/tools/build/test/sprites.test.ts
Christopher Monsanto 73f5954407 Adopt the house import style
Node builtins come in as node:-prefixed namespace imports;
multi-symbol internal imports use short namespace aliases (artifact,
cas, subst, db, api, executor). Single-symbol pulls, types, and the
buildfile DSL names stay braced, matching the sanctioned exceptions.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-21 01:13:14 -04:00

42 lines
1.7 KiB
TypeScript

import assert from 'node:assert/strict';
import * as fs from 'node:fs';
import * as os from 'node:os';
import * as pathlib from 'node:path';
import {test} from 'node:test';
import {base, spritedata, spriteglob} from '../helpers.ts';
test('spritedata parses id and flags', () => {
assert.deepEqual(spritedata('10080'), {id: '10080', data: {}});
assert.deepEqual(spritedata('10080-a'), {id: '10080', data: {a: true}});
assert.deepEqual(spritedata('10016-b-s'), {id: '10016', data: {b: true, s: true}});
assert.deepEqual(spritedata('123-xmega'), {id: '123', data: {x: 'mega'}});
// Lua gmatch("[^-]+") skips empty segments
assert.deepEqual(spritedata('12--b'), {id: '12', data: {b: true}});
});
test('base strips directory and final extension', () => {
assert.equal(base('src/models/6-mega-x.gif'), '6-mega-x');
});
test('spriteglob filters by flag truthiness', () => {
let dir = fs.mkdtempSync(pathlib.join(os.tmpdir(), 'spriteglob-'));
try {
for (let name of ['1.png', '1-a.png', '2-b.png', '2-b-s.png', '3-g.png', '.hidden.png']) {
fs.writeFileSync(pathlib.join(dir, name), '');
}
assert.deepEqual(
spriteglob(`${dir}/*.png`, {a: false}).map(p => pathlib.basename(p)),
['1.png', '2-b-s.png', '2-b.png', '3-g.png']);
assert.deepEqual(
spriteglob(`${dir}/*.png`, {b: false, s: false}).map(p => pathlib.basename(p)),
['1-a.png', '1.png', '3-g.png']);
assert.deepEqual(
spriteglob(`${dir}/*.png`, {b: true}).map(p => pathlib.basename(p)),
['2-b-s.png', '2-b.png']);
} finally {
fs.rmSync(dir, {recursive: true, force: true});
}
});