mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-19 21:03:09 +00:00
20 lines
833 B
JavaScript
20 lines
833 B
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { imageFromAsciiArt } = require('../.test-build/app/graphics/image.js');
|
|
|
|
test('imageFromAsciiArt maps characters through the palette', () => {
|
|
const image = imageFromAsciiArt(['#/.', ' _#'], { '#': 255, '/': 128, '_': 64 });
|
|
assert.equal(image.width, 3);
|
|
assert.equal(image.height, 2);
|
|
assert.deepEqual([...image.pixels], [255, 128, 0, 0, 64, 255]);
|
|
});
|
|
|
|
test('imageFromAsciiArt pads short lines and lets the palette override the background', () => {
|
|
const image = imageFromAsciiArt(['.#', '.'], { '#': 300, '.': 10 });
|
|
assert.deepEqual([...image.pixels], [10, 255, 10, 0]);
|
|
});
|
|
|
|
test('imageFromAsciiArt rejects characters missing from the palette', () => {
|
|
assert.throws(() => imageFromAsciiArt(['#x'], { '#': 255 }), /"x"/);
|
|
});
|