From a38e28bcf6fa6ed30ebab78a6d0a0a59ce25b9f9 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Wed, 6 Mar 2024 15:47:14 -0800 Subject: [PATCH 1/4] Separate data model errors from syntax errors Split out data model errors into their own file and label tests according to the error name from the spec. No new test cases are added/removed. --- test/README.md | 8 ++++++- test/data-model-errors.json | 47 +++++++++++++++++++++++++++++++++++++ test/syntax-errors.json | 20 ---------------- 3 files changed, 54 insertions(+), 21 deletions(-) create mode 100644 test/data-model-errors.json diff --git a/test/README.md b/test/README.md index 2469ce68f5..984c91d7c4 100644 --- a/test/README.md +++ b/test/README.md @@ -3,7 +3,13 @@ and are here relicensed by their original author (Eemeli Aro) under the Unicode These test files are intended to be useful for testing multiple different message processors in different ways: -- `syntax-errors.json` — An array of strings that should produce a Syntax Error or a Data Model Error when parsed. +- `syntax-errors.json` — An array of strings that should produce a Syntax Error when parsed. + +- `data-model-errors.json` - An array of pairs of error names and arrays of strings: + - `error: string` (required) - The name of the error; names are defined in + ["MessageFormat 2.0 Errors"](https://github.com/unicode-org/message-format-wg/blob/main/spec/errors.md) + in the spec. + - `tests: string[]` (required): An array of strings that should produce `error` when processed. - `test-core.json` — An array of test cases that do not depend on any registry definitions. Each test may include some of the following fields: diff --git a/test/data-model-errors.json b/test/data-model-errors.json new file mode 100644 index 0000000000..ce787cbfb6 --- /dev/null +++ b/test/data-model-errors.json @@ -0,0 +1,47 @@ +[ + { + "error": "Variant Key Mismatch", + "tests": [ + ".match {$foo :x} * * {{foo}}", + ".match {$foo :x} {$bar :x} * {{foo}}" + ] + }, + { + "error": "Missing Fallback Variant", + "tests": [ + ".match {:foo} 1 {{_}}", + ".match {:foo} other {{_}}", + ".match {:foo} {:bar} * 1 {{_}} 1 * {{_}}" + ] + }, + { + "error": "Missing Selector Annotation", + "tests": [ + ".match {$foo} one {{one}} * {{other}}", + ".input {$foo} .match {$foo} one {{one}} * {{other}}", + ".local $foo = {$bar} .match {$foo} one {{one}} * {{other}}" + ] + }, + { + "error": "Duplicate Declaration", + "tests": [ + ".input {$foo} .input {$foo} {{_}}", + ".input {$foo} .local $foo = {42} {{_}}", + ".local $foo = {42} .input {$foo} {{_}}", + ".local $foo = {:unknown} .local $foo = {42} {{_}}", + ".local $foo = {$bar} .local $bar = {42} {{_}}", + ".local $foo = {$foo} {{_}}", + ".local $foo = {$bar} .local $bar = {$baz} {{_}}", + ".local $foo = {$bar :func} .local $bar = {$baz} {{_}}", + ".local $foo = {42 :func opt=$foo} {{_}}", + ".local $foo = {42 :func opt=$bar} .local $bar = {42} {{_}}", + ] + }, + { + "error": "Duplicate Option Name", + "tests": [ + "bad {:placeholder option=x option=x}", + "bad {:placeholder ns:option=x ns:option=y}" + ] + } +] diff --git a/test/syntax-errors.json b/test/syntax-errors.json index c607e632e8..9d23dad24a 100644 --- a/test/syntax-errors.json +++ b/test/syntax-errors.json @@ -20,8 +20,6 @@ "bad {:} placeholder", "bad {\\u0000placeholder}", "no-equal {|42| :number minimumFractionDigits 2}", - "bad {:placeholder option=x option=x}", - "bad {:placeholder ns:option=x ns:option=y}", "bad {:placeholder option=}", "bad {:placeholder option value}", "bad {:placeholder option:value}", @@ -41,20 +39,10 @@ "no {|placeholder| end", "no {|literal} end", "no {|literal or placeholder end", - ".input {$foo} .input {$foo} {{_}}", - ".input {$foo} .local $foo = {42} {{_}}", - ".local $foo = {42} .input {$foo} {{_}}", - ".local $foo = {:unknown} .local $foo = {42} {{_}}", ".local bar = {|foo|} {{_}}", ".local #bar = {|foo|} {{_}}", ".local $bar {|foo|} {{_}}", ".local $bar = |foo| {{_}}", - ".local $foo = {$bar} .local $bar = {42} {{_}}", - ".local $foo = {$foo} {{_}}", - ".local $foo = {$bar} .local $bar = {$baz} {{_}}", - ".local $foo = {$bar :func} .local $bar = {$baz} {{_}}", - ".local $foo = {42 :func opt=$foo} {{_}}", - ".local $foo = {42 :func opt=$bar} .local $bar = {42} {{_}}", ".match {#foo} * {{foo}}", ".match {} * {{foo}}", ".match {|foo| :x} {|bar| :x} ** {{foo}}", @@ -62,12 +50,4 @@ ".match {|x| :x} * foo", ".match {|x| :x} * {{foo}} extra", ".match |x| * {{foo}}", - ".match {:foo} 1 {{_}}", - ".match {:foo} other {{_}}", - ".match {:foo} {:bar} * 1 {{_}} 1 * {{_}}", - ".match {$foo :x} * * {{foo}}", - ".match {$foo :x} {$bar :x} * {{foo}}", - ".match {$foo} one {{one}} * {{other}}", - ".input {$foo} .match {$foo} one {{one}} * {{other}}", - ".local $foo = {$bar} .match {$foo} one {{one}} * {{other}}" ] From e3139f1a162b8c3500b005fb2fd2eb9de2b0029d Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Fri, 8 Mar 2024 17:20:52 -0800 Subject: [PATCH 2/4] Reformat data model error test file --- test/README.md | 7 ++-- test/data-model-errors.json | 71 +++++++++++++++---------------------- 2 files changed, 32 insertions(+), 46 deletions(-) diff --git a/test/README.md b/test/README.md index 984c91d7c4..1db6e0c17b 100644 --- a/test/README.md +++ b/test/README.md @@ -5,11 +5,12 @@ These test files are intended to be useful for testing multiple different messag - `syntax-errors.json` — An array of strings that should produce a Syntax Error when parsed. -- `data-model-errors.json` - An array of pairs of error names and arrays of strings: - - `error: string` (required) - The name of the error; names are defined in +- `data-model-errors.json` - An object with string keys and arrays of strings as values, + where each key is the name of an error and its value is array of strings that + should produce `error` when processed. + Error names are defined in ["MessageFormat 2.0 Errors"](https://github.com/unicode-org/message-format-wg/blob/main/spec/errors.md) in the spec. - - `tests: string[]` (required): An array of strings that should produce `error` when processed. - `test-core.json` — An array of test cases that do not depend on any registry definitions. Each test may include some of the following fields: diff --git a/test/data-model-errors.json b/test/data-model-errors.json index ce787cbfb6..3c7f1c9b88 100644 --- a/test/data-model-errors.json +++ b/test/data-model-errors.json @@ -1,47 +1,32 @@ [ - { - "error": "Variant Key Mismatch", - "tests": [ - ".match {$foo :x} * * {{foo}}", - ".match {$foo :x} {$bar :x} * {{foo}}" - ] - }, - { - "error": "Missing Fallback Variant", - "tests": [ - ".match {:foo} 1 {{_}}", - ".match {:foo} other {{_}}", - ".match {:foo} {:bar} * 1 {{_}} 1 * {{_}}" - ] - }, - { - "error": "Missing Selector Annotation", - "tests": [ - ".match {$foo} one {{one}} * {{other}}", - ".input {$foo} .match {$foo} one {{one}} * {{other}}", - ".local $foo = {$bar} .match {$foo} one {{one}} * {{other}}" - ] - }, - { - "error": "Duplicate Declaration", - "tests": [ - ".input {$foo} .input {$foo} {{_}}", - ".input {$foo} .local $foo = {42} {{_}}", - ".local $foo = {42} .input {$foo} {{_}}", - ".local $foo = {:unknown} .local $foo = {42} {{_}}", - ".local $foo = {$bar} .local $bar = {42} {{_}}", - ".local $foo = {$foo} {{_}}", - ".local $foo = {$bar} .local $bar = {$baz} {{_}}", - ".local $foo = {$bar :func} .local $bar = {$baz} {{_}}", - ".local $foo = {42 :func opt=$foo} {{_}}", - ".local $foo = {42 :func opt=$bar} .local $bar = {42} {{_}}", - ] - }, - { - "error": "Duplicate Option Name", - "tests": [ + "Variant Key Mismatch": [ + ".match {$foo :x} * * {{foo}}", + ".match {$foo :x} {$bar :x} * {{foo}}" + ], + "Missing Fallback Variant": [ + ".match {:foo} 1 {{_}}", + ".match {:foo} other {{_}}", + ".match {:foo} {:bar} * 1 {{_}} 1 * {{_}}" + ], + "Missing Selector Annotation": [ + ".match {$foo} one {{one}} * {{other}}", + ".input {$foo} .match {$foo} one {{one}} * {{other}}", + ".local $foo = {$bar} .match {$foo} one {{one}} * {{other}}" + ], + "Duplicate Declaration": [ + ".input {$foo} .input {$foo} {{_}}", + ".input {$foo} .local $foo = {42} {{_}}", + ".local $foo = {42} .input {$foo} {{_}}", + ".local $foo = {:unknown} .local $foo = {42} {{_}}", + ".local $foo = {$bar} .local $bar = {42} {{_}}", + ".local $foo = {$foo} {{_}}", + ".local $foo = {$bar} .local $bar = {$baz} {{_}}", + ".local $foo = {$bar :func} .local $bar = {$baz} {{_}}", + ".local $foo = {42 :func opt=$foo} {{_}}", + ".local $foo = {42 :func opt=$bar} .local $bar = {42} {{_}}", + ], + "Duplicate Option Name": [ "bad {:placeholder option=x option=x}", "bad {:placeholder ns:option=x ns:option=y}" - ] - } + ] ] From 077fbc7abdb588a7ef79923891e9c9b048ecfc79 Mon Sep 17 00:00:00 2001 From: Addison Phillips Date: Sat, 9 Mar 2024 07:10:40 -0800 Subject: [PATCH 3/4] Update test/syntax-errors.json Co-authored-by: Eemeli Aro --- test/syntax-errors.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/syntax-errors.json b/test/syntax-errors.json index 9d23dad24a..2d73b83961 100644 --- a/test/syntax-errors.json +++ b/test/syntax-errors.json @@ -49,5 +49,5 @@ ".match * {{foo}}", ".match {|x| :x} * foo", ".match {|x| :x} * {{foo}} extra", - ".match |x| * {{foo}}", + ".match |x| * {{foo}}" ] From 50d9c54ab0f9a90ba42274c9b6d987be9b4db268 Mon Sep 17 00:00:00 2001 From: Addison Phillips Date: Sat, 9 Mar 2024 07:10:45 -0800 Subject: [PATCH 4/4] Update test/README.md Co-authored-by: Eemeli Aro --- test/README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/README.md b/test/README.md index 1db6e0c17b..b049946d2e 100644 --- a/test/README.md +++ b/test/README.md @@ -8,9 +8,7 @@ These test files are intended to be useful for testing multiple different messag - `data-model-errors.json` - An object with string keys and arrays of strings as values, where each key is the name of an error and its value is array of strings that should produce `error` when processed. - Error names are defined in - ["MessageFormat 2.0 Errors"](https://github.com/unicode-org/message-format-wg/blob/main/spec/errors.md) - in the spec. + Error names are defined in ["MessageFormat 2.0 Errors"](../spec/errors.md) in the spec. - `test-core.json` — An array of test cases that do not depend on any registry definitions. Each test may include some of the following fields: