puzzlescript
Version:
Play PuzzleScript games in your terminal!
115 lines (91 loc) • 2.13 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-env jasmine */
const parser_1 = __importDefault(require("./parser"));
const serializer_1 = __importDefault(require("./serializer"));
function checkGrammar(code) {
// check that it does not throw an Error
const { data } = parser_1.default.parse(code);
const json = new serializer_1.default(data).toJson();
expect(json).toMatchSnapshot();
const game2 = serializer_1.default.fromJson(json, code);
// verify the toKey representation of all the rules is the same as before
if (data.rules.length !== game2.rules.length) {
throw new Error(`BUG: rule lengths do not match`);
}
data.rules.forEach((rule, index) => {
const rule2 = game2.rules[index];
// if (rule.toKey() !== rule2.toKey()) {
// debugger
// throw new Error(`BUG: rule.toKey mismatch.\norig=${rule.toKey()}\nnew =${rule2.toKey()}`)
// }
expect(rule.toKey()).toEqual(rule2.toKey());
});
// const json2 = new Serializer(game2).toJson()
// expect(json2).toEqual(json)
}
describe('serializer', () => {
it('parses an empty game', () => {
checkGrammar(`title Test Game`);
});
it('parses a simple game', () => {
checkGrammar(`title Test Game
===
OBJECTS
===
background .
black
player P
yellow
===
COLLISIONLAYERS
===
background
player
===
RULES
===
[ NO player | background ] -> [ RANDOM player | > background ]
===
LEVELS
===
MESSAGE hello
..P..
`);
});
it('parses a game with RANDOM, loops, and debug statements', () => {
checkGrammar(`title Test Game
===
OBJECTS
===
background .
black
player
yellow
===
LEGEND
===
P = player AND background
===
COLLISIONLAYERS
===
background
player
===
RULES
===
STARTLOOP
RANDOM RIGID LATE UP [ > player ] -> [ RANDOM player ] DEBUGGER
ENDLOOP
===
LEVELS
===
MESSAGE hello
P.
`);
});
});
//# sourceMappingURL=serializer.spec.js.map