clone

a browser grid puzzle game where you push words around to rewrite the rules of each level

test(juice): preserve pre-push sentence cells on removal

Dami committed 426762f
commit
426762f23ac70bff421ee2cdce4f6c8ca2172720
parent
e02d208e32297a4e82ff0d2f0385b67d91628567
author
Dami <dami.etoile@gmail.com>
1 file changed, +27 -0
Mtests/juice.test.js27+++++++++++++++++++++++++++
M tests/juice.test.js +27 -0
@@ -1,5 +1,6 @@
11 import test from 'node:test';22 import assert from 'node:assert/strict';3+import { createGame } from '../src/engine.js';34 import { createJuice, JUICE_TIMINGS } from '../src/juice.js';45 56 const state = objects => ({ objects });
@@ -84,6 +85,32 @@ test('physical sentence bars use ids and freeze removed pre-move cells', () => {
8485 assert.deepEqual(bar.frozenCells.map(cell => [cell.x, cell.y]), [[0, 0], [1, 0], [2, 0]]);8586 });8687 88+test('engine push breaking a sentence freezes its pre-push cells', () => {89+ const game = createGame({90+ width: 5,91+ height: 3,92+ objects: [93+ { id: 'miau', kind: 'object', noun: 'MIAU', x: 1, y: 2 },94+ { id: 'word-miau', kind: 'word', text: 'MIAU', x: 1, y: 1 },95+ { id: 'word-is', kind: 'word', text: 'IS', x: 2, y: 1 },96+ { id: 'word-you', kind: 'word', text: 'YOU', x: 3, y: 1 },97+ ],98+ });99+ const before = game.getState();100+ assert.deepEqual(before.sentences.map(sentence => sentence.ids), [['word-miau', 'word-is', 'word-you']]);101+ const juice = createJuice({ now: () => 0 });102+ juice.syncState(before, 0);103+ juice.beginInput(0);104+ const result = game.step(0, -1);105+ const after = game.getState();106+ assert.equal(result.accepted, true);107+ assert.deepEqual(after.sentences, []);108+ juice.consume(result, 0, after);109+ const removed = juice.frame(0).sentences.find(sentence => sentence.phase === 'removing');110+ assert.ok(removed);111+ assert.deepEqual(removed.frozenCells.map(cell => [cell.x, cell.y]), [[1, 1], [2, 1], [3, 1]]);112+});113+87114 test('snap preserves the rule hold while it finishes movement', () => {88115 const juice = createJuice({ now: () => 0 });89116 const rule = { text: 'MIAU IS YOU', subject: 'MIAU', predicate: 'YOU', sourceIds: ['a', 'b', 'c'], axis: 'h' };