Wraps gid.encodeGid, prints the packed-u32 as decimal on stdout, emits usage on stderr on bad arity, and a labelled error on out-of-range or non-integer input.
55 lines
1.7 KiB
JavaScript
55 lines
1.7 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('encode: (0,12,1) prints 196 with trailing newline, exit 0', () => {
|
|
const out = new Sink(); const err = new Sink();
|
|
const code = run(['encode', '0', '12', '1'], { out, err });
|
|
assert.equal(code, 0);
|
|
assert.equal(out.text, '196\n');
|
|
assert.equal(err.text, '');
|
|
});
|
|
|
|
test('encode: rotation defaults to 0', () => {
|
|
const out = new Sink(); const err = new Sink();
|
|
const code = run(['encode', '0', '12'], { out, err });
|
|
assert.equal(code, 0);
|
|
assert.equal(out.text, '192\n');
|
|
});
|
|
|
|
test('encode: no args prints usage to stderr, exit 1', () => {
|
|
const out = new Sink(); const err = new Sink();
|
|
const code = run(['encode'], { out, err });
|
|
assert.equal(code, 1);
|
|
assert.match(err.text, /usage: sporel-mapper encode/);
|
|
});
|
|
|
|
test('encode: too many args prints usage, exit 1', () => {
|
|
const out = new Sink(); const err = new Sink();
|
|
const code = run(['encode', '0', '0', '0', '0'], { out, err });
|
|
assert.equal(code, 1);
|
|
assert.match(err.text, /usage/);
|
|
});
|
|
|
|
test('encode: out-of-range tile prints error, exit 1', () => {
|
|
const out = new Sink(); const err = new Sink();
|
|
const code = run(['encode', '0', '99999999', '0'], { out, err });
|
|
assert.equal(code, 1);
|
|
assert.match(err.text, /error: tile/);
|
|
});
|
|
|
|
test('encode: non-integer arg prints error, exit 1', () => {
|
|
const out = new Sink(); const err = new Sink();
|
|
const code = run(['encode', '0', 'abc', '0'], { out, err });
|
|
assert.equal(code, 1);
|
|
assert.match(err.text, /error/i);
|
|
});
|