Accepts decimal or 0x-hex GID input. gid=0 is rendered as the literal 'empty'; non-zero values print the three components in a parse-stable space-separated key=value form.
62 lines
2.0 KiB
JavaScript
62 lines
2.0 KiB
JavaScript
'use strict';
|
|
|
|
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { run } = require('../src/cli');
|
|
|
|
class Sink {
|
|
constructor() { this.chunks = []; }
|
|
write(s) { this.chunks.push(s); }
|
|
get text() { return this.chunks.join(''); }
|
|
}
|
|
|
|
test('decode: 196 prints (0,12,1)', () => {
|
|
const out = new Sink(); const err = new Sink();
|
|
const code = run(['decode', '196'], { out, err });
|
|
assert.equal(code, 0);
|
|
assert.equal(out.text, 'atlas=0 tile=12 rotation=1\n');
|
|
});
|
|
|
|
test('decode: 0 prints "empty"', () => {
|
|
const out = new Sink(); const err = new Sink();
|
|
const code = run(['decode', '0'], { out, err });
|
|
assert.equal(code, 0);
|
|
assert.equal(out.text, 'empty\n');
|
|
});
|
|
|
|
test('decode: hex (0xc4) parses to 196', () => {
|
|
const out = new Sink(); const err = new Sink();
|
|
const code = run(['decode', '0xc4'], { out, err });
|
|
assert.equal(code, 0);
|
|
assert.equal(out.text, 'atlas=0 tile=12 rotation=1\n');
|
|
});
|
|
|
|
test('decode: non-zero with tile=0 prints components (not "empty")', () => {
|
|
// gid=4 = (0<<24) | (0<<4) | (1<<2) → atlas=0 tile=0 rot=1
|
|
const out = new Sink(); const err = new Sink();
|
|
const code = run(['decode', '4'], { out, err });
|
|
assert.equal(code, 0);
|
|
assert.equal(out.text, 'atlas=0 tile=0 rotation=1\n');
|
|
});
|
|
|
|
test('decode: 16777232 from demo_v2 wall layer → (1,1,0)', () => {
|
|
const out = new Sink(); const err = new Sink();
|
|
const code = run(['decode', '16777232'], { out, err });
|
|
assert.equal(code, 0);
|
|
assert.equal(out.text, 'atlas=1 tile=1 rotation=0\n');
|
|
});
|
|
|
|
test('decode: no args prints usage, exit 1', () => {
|
|
const out = new Sink(); const err = new Sink();
|
|
const code = run(['decode'], { out, err });
|
|
assert.equal(code, 1);
|
|
assert.match(err.text, /usage: sporel-mapper decode/);
|
|
});
|
|
|
|
test('decode: bogus arg prints error, exit 1', () => {
|
|
const out = new Sink(); const err = new Sink();
|
|
const code = run(['decode', 'xyz'], { out, err });
|
|
assert.equal(code, 1);
|
|
assert.match(err.text, /error/i);
|
|
});
|