From ec8760ddba0b83979b1d7b8301bc4bf9b48e8158 Mon Sep 17 00:00:00 2001 From: TheAfroOfDoom Date: Mon, 20 May 2024 11:46:00 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20Add=20tests=20with=20incorrect?= =?UTF-8?q?=20parse=20result=20-=20we=20want=20these=20to=20result=20in=20?= =?UTF-8?q?errors,=20but=20they=20pass=20right=20now?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/test-out/parser/util.spec.js | 12 ++++ .../argument/minecraftComponent.spec.js | 62 +++++++++++++++++++ .../test-out/parser/command.spec.js | 54 ++++++++++++++++ packages/core/test/parser/util.spec.ts | 1 + .../test/mcfunction/parser/argument.spec.ts | 1 + .../mcfunction/test/parser/command.spec.ts | 1 + 6 files changed, 131 insertions(+) diff --git a/__snapshots__/packages/core/test-out/parser/util.spec.js b/__snapshots__/packages/core/test-out/parser/util.spec.js index bc2cd9e9a..b9c3785ee 100644 --- a/__snapshots__/packages/core/test-out/parser/util.spec.js +++ b/__snapshots__/packages/core/test-out/parser/util.spec.js @@ -197,6 +197,18 @@ exports['concatOnTrailingBackslash() Parse "tru⧵↓e" 1'] = { "errors": [] } +exports['concatOnTrailingBackslash() Parse "tru⧵↓↓e" 1'] = { + "node": { + "type": "boolean", + "range": { + "start": 0, + "end": 7 + }, + "value": true + }, + "errors": [] +} + exports['dumpErrors() should not output errors when wrapped with `dumpErrors()` 1'] = { "node": { "type": "boolean", diff --git a/__snapshots__/packages/java-edition/test-out/mcfunction/parser/argument/minecraftComponent.spec.js b/__snapshots__/packages/java-edition/test-out/mcfunction/parser/argument/minecraftComponent.spec.js index 77af2d2b5..3e18c5e13 100644 --- a/__snapshots__/packages/java-edition/test-out/mcfunction/parser/argument/minecraftComponent.spec.js +++ b/__snapshots__/packages/java-edition/test-out/mcfunction/parser/argument/minecraftComponent.spec.js @@ -170,6 +170,68 @@ exports['mcfunction argument minecraft:component Parse "["hello ⧵ ↓world"]" "errors": [] } +exports['mcfunction argument minecraft:component Parse "["hello⧵↓↓world"]" 1'] = { + "node": { + "type": "json:array", + "range": { + "start": 0, + "end": 17 + }, + "children": [ + { + "type": "item", + "range": { + "start": 1, + "end": 16 + }, + "children": [ + { + "type": "json:string", + "range": { + "start": 1, + "end": 16 + }, + "value": "helloworld", + "valueMap": [ + { + "inner": { + "start": 0, + "end": 0 + }, + "outer": { + "start": 2, + "end": 2 + } + } + ] + } + ], + "value": { + "type": "json:string", + "range": { + "start": 1, + "end": 16 + }, + "value": "helloworld", + "valueMap": [ + { + "inner": { + "start": 0, + "end": 0 + }, + "outer": { + "start": 2, + "end": 2 + } + } + ] + } + } + ] + }, + "errors": [] +} + exports['mcfunction argument minecraft:component Parse "["⧵u12⧵ ↓ 34"]" 1'] = { "node": { "type": "json:array", diff --git a/__snapshots__/packages/mcfunction/test-out/parser/command.spec.js b/__snapshots__/packages/mcfunction/test-out/parser/command.spec.js index b21a9b1fc..06c0358c9 100644 --- a/__snapshots__/packages/mcfunction/test-out/parser/command.spec.js +++ b/__snapshots__/packages/mcfunction/test-out/parser/command.spec.js @@ -677,6 +677,60 @@ exports['mcfunction parser command() Parse "sa⧵↓y hi" 1'] = { "errors": [] } +exports['mcfunction parser command() Parse "sa⧵↓↓y h⧵ ↓ i" 1'] = { + "node": { + "type": "mcfunction:command", + "range": { + "start": 0, + "end": 13 + }, + "children": [ + { + "type": "mcfunction:command_child", + "range": { + "start": 0, + "end": 6 + }, + "children": [ + { + "type": "mcfunction:command_child/literal", + "range": { + "start": 0, + "end": 6 + }, + "value": "say" + } + ], + "path": [ + "say" + ] + }, + { + "type": "mcfunction:command_child", + "range": { + "start": 7, + "end": 13 + }, + "children": [ + { + "type": "mcfunction:command_child/literal", + "range": { + "start": 7, + "end": 13 + }, + "value": "hi" + } + ], + "path": [ + "say", + "hi" + ] + } + ] + }, + "errors": [] +} + exports['mcfunction parser command() Should not exceed max call stack 1'] = { "node": "OMITTED", "errors": [ diff --git a/packages/core/test/parser/util.spec.ts b/packages/core/test/parser/util.spec.ts index 5375db823..93d867526 100644 --- a/packages/core/test/parser/util.spec.ts +++ b/packages/core/test/parser/util.spec.ts @@ -145,6 +145,7 @@ describe('concatOnTrailingBackslash()', () => { { content: 'tru\\ \n e' }, { content: 'tru\\ \n \\\n e' }, { content: 'tru\\e \\ \n e' }, + { content: 'tru\\\n\ne' }, ], }, ] diff --git a/packages/java-edition/test/mcfunction/parser/argument.spec.ts b/packages/java-edition/test/mcfunction/parser/argument.spec.ts index d62433302..52544cb9c 100644 --- a/packages/java-edition/test/mcfunction/parser/argument.spec.ts +++ b/packages/java-edition/test/mcfunction/parser/argument.spec.ts @@ -80,6 +80,7 @@ const Suites: Partial< '{"text":"hello world"}', '[""]', '["hello \\ \nworld"]', + '["hello\\\n\nworld"]', '["\\u12\\ \n 34"]', '["\\uab\\ \n nd"]', ], diff --git a/packages/mcfunction/test/parser/command.spec.ts b/packages/mcfunction/test/parser/command.spec.ts index df2a4e756..d41f4f91b 100644 --- a/packages/mcfunction/test/parser/command.spec.ts +++ b/packages/mcfunction/test/parser/command.spec.ts @@ -53,6 +53,7 @@ describe('mcfunction parser command()', () => { { content: 'sa\\\ny hi' }, { content: 'sa\\ \n y hi' }, { content: 'sa\\ \n y h\\ \n i' }, + { content: 'sa\\\n\ny h\\ \n i' }, ] for (const { content } of cases) { it(`Parse "${showWhitespaceGlyph(content)}"`, () => {