- commit
- 4a8d37159c5bebf31bb14b949907329dd7624bcd
- parent
- 2950532bd6347894934f5d91bb1b270d8ccd56d0
- author
- Dami <dami.etoile@gmail.com>
| M | src/ | 4 | +++- |
| M | tests/ | 9 | +++++++++ |
@@ -80,8 +80,10 @@ function normalizeObject(object, index, level, path, customProperties, issues) {
8080 else if (object.x < 0 || object.y < 0 || object.x >= level.width || object.y >= level.height) add(issues, 'coordinate-range', path, `position (${object.x}, ${object.y}) is outside the ${level.width}x${level.height} board`, object);8181 if (object.id !== undefined && (typeof object.id !== 'string' || object.id.length === 0)) add(issues, 'object-id', `${path}.id`, 'must be a non-empty string', object.id);8282 const id = object.id || `o${index}`;83- const kind = object.kind || (object.text !== undefined ? 'word' : 'object');83+ const kind = object.kind === undefined ? (object.text !== undefined ? 'word' : 'object') : object.kind;8484 if (kind !== 'word' && kind !== 'object') add(issues, 'object-kind', `${path}.kind`, "must be 'word' or 'object'", kind);85+ if (kind === 'word' && object.noun !== undefined) add(issues, 'object-field', `${path}.noun`, 'word cannot include noun', object.noun);86+ if (kind === 'object' && object.text !== undefined) add(issues, 'object-field', `${path}.text`, 'object cannot include text', object.text);8587 const text = typeof object.text === 'string' ? object.text.toUpperCase() : object.text;8688 const noun = typeof object.noun === 'string' ? object.noun.toUpperCase() : object.noun;8789 if (kind === 'word') {@@ -58,6 +58,15 @@ test('rejects unknown level and object fields instead of dropping authored data'
5858 assert.deepEqual(issues.map(issue => issue.code), ['unsupported-field', 'unsupported-field']);5959 });6060 61+test('rejects conflicting object fields and falsey explicit kinds', () => {62+ const issues = validateLevel({ width: 2, height: 1, objects: [63+ { kind: 'word', text: 'MIAU', noun: 'ROCK', x: 0, y: 0 },64+ { kind: 'object', noun: 'MIAU', text: 'FLAG', x: 1, y: 0 },65+ ] });66+ assert.deepEqual(issues.map(issue => issue.path), ['level.objects[0].noun', 'level.objects[1].text']);67+ assert.deepEqual(validateLevel({ width: 1, height: 1, objects: [{ kind: '', noun: 'MIAU', x: 0, y: 0 }] }).map(issue => issue.code), ['object-kind']);68+});69+6170 test('engine diagnostics retain the second automaton identity and canonical issue', () => {6271 assert.throws(() => createGame({6372 width: 1,