From 956e94a549d9104427bf8e4d6a5259ab1f0cecc2 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Wed, 26 Mar 2025 00:54:21 +0200 Subject: [PATCH 1/3] Drop source from non-fallback formatted parts --- test/schemas/v0/tests.schema.json | 32 ++++++++++++++++++------------- test/tests/fallback.json | 9 ++++++--- test/tests/functions/number.json | 8 +------- test/tests/syntax.json | 16 ++-------------- test/tests/u-options.json | 25 +++--------------------- 5 files changed, 31 insertions(+), 59 deletions(-) diff --git a/test/schemas/v0/tests.schema.json b/test/schemas/v0/tests.schema.json index 96aaf2a975..01e734b793 100644 --- a/test/schemas/v0/tests.schema.json +++ b/test/schemas/v0/tests.schema.json @@ -290,9 +290,6 @@ "close" ] }, - "source": { - "type": "string" - }, "name": { "type": "string" }, @@ -308,8 +305,7 @@ "description": "Message expression part.", "type": "object", "required": [ - "type", - "source" + "type" ], "not": { "required": [ @@ -321,9 +317,6 @@ "type": { "type": "string" }, - "source": { - "type": "string" - }, "locale": { "type": "string" }, @@ -334,11 +327,7 @@ "properties": { "type": { "type": "string" - }, - "source": { - "type": "string" - }, - "value": {} + } }, "required": [ "type" @@ -347,6 +336,23 @@ }, "value": {} } + }, + { + "description": "Fallback part.", + "type": "object", + "additionalProperties": false, + "required": [ + "type", + "source" + ], + "properties": { + "type": { + "const": "fallback" + }, + "source": { + "type": "string" + } + } } ] } diff --git a/test/tests/fallback.json b/test/tests/fallback.json index fd1429c9b6..0a6ae32587 100644 --- a/test/tests/fallback.json +++ b/test/tests/fallback.json @@ -11,7 +11,8 @@ { "description": "function with unquoted literal operand", "src": "{42 :test:function fails=format}", - "exp": "{|42|}" + "exp": "{|42|}", + "expParts": [{ "type": "fallback", "source": "|42|" }] }, { "description": "function with quoted literal operand", @@ -26,7 +27,8 @@ { "description": "annotated implicit input variable", "src": "{$var :number}", - "exp": "{$var}" + "exp": "{$var}", + "expParts": [{ "type": "fallback", "source": "$var" }] }, { "description": "local variable with unknown function in declaration", @@ -46,7 +48,8 @@ { "description": "function with no operand", "src": "{:test:undefined}", - "exp": "{:test:undefined}" + "exp": "{:test:undefined}", + "expParts": [{ "type": "fallback", "source": ":test:undefined" }] } ] } diff --git a/test/tests/functions/number.json b/test/tests/functions/number.json index 89f859164e..e98d179246 100644 --- a/test/tests/functions/number.json +++ b/test/tests/functions/number.json @@ -326,13 +326,7 @@ "expParts": [ { "type": "number", - "source": "|42|", - "parts": [ - { - "type": "integer", - "value": "42" - } - ] + "parts": [{ "type": "integer", "value": "42" }] } ] } diff --git a/test/tests/syntax.json b/test/tests/syntax.json index 4c825f4189..1e8e3048a4 100644 --- a/test/tests/syntax.json +++ b/test/tests/syntax.json @@ -412,13 +412,7 @@ "description": "... attribute -> \"@\" identifier s \"=\" s quoted-literal ...", "src": "{42 @foo=|bar|}", "exp": "42", - "expParts": [ - { - "type": "string", - "source": "|42|", - "value": "42" - } - ] + "expParts": [{ "type": "string", "value": "42" }] }, { "description": "... quoted-literal", @@ -722,13 +716,7 @@ { "src": "{42 @foo @bar=13}", "exp": "42", - "expParts": [ - { - "type": "string", - "source": "|42|", - "value": "42" - } - ] + "expParts": [{ "type": "string", "value": "42" }] }, { "src": "{{trailing whitespace}} \n", diff --git a/test/tests/u-options.json b/test/tests/u-options.json index 6ae9264f71..815f3d9e58 100644 --- a/test/tests/u-options.json +++ b/test/tests/u-options.json @@ -54,13 +54,7 @@ "expParts": [ { "type": "text", "value": "hello " }, { "type": "bidiIsolation", "value": "\u2066" }, - { - "type": "string", - "source": "|world|", - "dir": "ltr", - "id": "foo", - "value": "world" - }, + { "type": "string", "dir": "ltr", "id": "foo", "value": "world" }, { "type": "bidiIsolation", "value": "\u2069" } ] @@ -71,13 +65,7 @@ "expParts": [ { "type": "text", "value": "hello " }, { "type": "bidiIsolation", "value": "\u2067" }, - { - "type": "string", - "source": "|world|", - "dir": "rtl", - "locale": "en-US", - "value": "world" - }, + { "type": "string", "dir": "rtl", "locale": "en-US", "value": "world" }, { "type": "bidiIsolation", "value": "\u2069" } ] }, @@ -89,7 +77,6 @@ { "type": "bidiIsolation", "value": "\u2068" }, { "type": "string", - "source": "|world|", "locale": "en-US", "value": "world" }, @@ -102,13 +89,7 @@ "expParts": [ { "type": "text", "value": "hello " }, { "type": "bidiIsolation", "value": "\u2066" }, - { - "type": "string", - "source": "|world|", - "dir": "ltr", - "id": "foo", - "value": "world" - }, + { "type": "string", "dir": "ltr", "id": "foo", "value": "world" }, { "type": "bidiIsolation", "value": "\u2069" } ] }, From 08430089b5d9fe16f93a3d799f5dd44c41848fd7 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Wed, 26 Mar 2025 01:28:29 +0200 Subject: [PATCH 2/3] Fix test schema, fix ajv warnings --- .github/workflows/validate_tests.yml | 3 +-- test/schemas/v0/tests.schema.json | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.github/workflows/validate_tests.yml b/.github/workflows/validate_tests.yml index 7d8ed254e9..beb4ee2948 100644 --- a/.github/workflows/validate_tests.yml +++ b/.github/workflows/validate_tests.yml @@ -7,7 +7,6 @@ on: paths: - test/** pull_request: - branches: '**' paths: - test/** @@ -22,7 +21,7 @@ jobs: run: npm install --global ajv-cli - name: Validate tests using the latest schema version run: > - ajv validate --spec=draft2020 + ajv validate --spec=draft2020 --allow-union-types -s $(ls -1v schemas/*/*schema.json | tail -1) -d 'tests/**/*.json' working-directory: ./test diff --git a/test/schemas/v0/tests.schema.json b/test/schemas/v0/tests.schema.json index 01e734b793..35bf6d4792 100644 --- a/test/schemas/v0/tests.schema.json +++ b/test/schemas/v0/tests.schema.json @@ -39,6 +39,7 @@ { "properties": { "defaultTestProperties": { + "type": "object", "required": [ "locale" ] @@ -50,6 +51,7 @@ "tests": { "type": "array", "items": { + "type": "object", "required": [ "locale" ] @@ -64,6 +66,7 @@ { "properties": { "defaultTestProperties": { + "type": "object", "required": [ "src" ] @@ -75,6 +78,7 @@ "tests": { "type": "array", "items": { + "type": "object", "required": [ "src" ] @@ -307,19 +311,21 @@ "required": [ "type" ], - "not": { - "required": [ - "parts", - "value" - ] - }, "properties": { "type": { - "type": "string" + "enum": [ + "datetime", + "number", + "string", + "test" + ] }, "locale": { "type": "string" }, + "id": { + "type": "string" + }, "parts": { "type": "array", "items": { @@ -391,6 +397,7 @@ } }, "anyExp": { + "type": "object", "anyOf": [ { "required": [ From 51b2c154c2de32d57b2ae4acfef8848ddb5e3268 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Wed, 26 Mar 2025 01:29:17 +0200 Subject: [PATCH 3/3] Use relative reference for $schema --- test/tests/bidi.json | 1 + test/tests/data-model-errors.json | 2 +- test/tests/fallback.json | 2 +- test/tests/functions/currency.json | 2 +- test/tests/functions/date.json | 2 +- test/tests/functions/datetime.json | 2 +- test/tests/functions/integer.json | 2 +- test/tests/functions/math.json | 2 +- test/tests/functions/number.json | 2 +- test/tests/functions/string.json | 2 +- test/tests/functions/time.json | 2 +- test/tests/pattern-selection.json | 2 +- test/tests/syntax-errors.json | 2 +- test/tests/syntax.json | 2 +- test/tests/u-options.json | 2 +- 15 files changed, 15 insertions(+), 14 deletions(-) diff --git a/test/tests/bidi.json b/test/tests/bidi.json index 2d650a3e34..21dc534599 100644 --- a/test/tests/bidi.json +++ b/test/tests/bidi.json @@ -1,4 +1,5 @@ { + "$schema": "../schemas/v0/tests.schema.json", "scenario": "Bidi support", "description": "Tests for correct parsing of messages with bidirectional marks and isolates", "defaultTestProperties": { diff --git a/test/tests/data-model-errors.json b/test/tests/data-model-errors.json index f1f54cabe7..c7ba4fb33c 100644 --- a/test/tests/data-model-errors.json +++ b/test/tests/data-model-errors.json @@ -1,5 +1,5 @@ { - "$schema": "https://raw.githubusercontent.com/unicode-org/message-format-wg/main/test/schemas/v0/tests.schema.json", + "$schema": "../schemas/v0/tests.schema.json", "scenario": "Data model errors", "defaultTestProperties": { "locale": "en-US" diff --git a/test/tests/fallback.json b/test/tests/fallback.json index 0a6ae32587..abf062e1c3 100644 --- a/test/tests/fallback.json +++ b/test/tests/fallback.json @@ -1,5 +1,5 @@ { - "$schema": "https://raw.githubusercontent.com/unicode-org/message-format-wg/main/test/schemas/v0/tests.schema.json", + "$schema": "../schemas/v0/tests.schema.json", "scenario": "Fallback", "description": "Test cases for fallback behaviour.", "defaultTestProperties": { diff --git a/test/tests/functions/currency.json b/test/tests/functions/currency.json index b844fa69ea..ea1d8aee62 100644 --- a/test/tests/functions/currency.json +++ b/test/tests/functions/currency.json @@ -1,5 +1,5 @@ { - "$schema": "https://raw.githubusercontent.com/unicode-org/message-format-wg/main/test/schemas/v0/tests.schema.json", + "$schema": "../../schemas/v0/tests.schema.json", "scenario": "Currency function", "description": "The built-in formatter and selector for currencies.", "defaultTestProperties": { diff --git a/test/tests/functions/date.json b/test/tests/functions/date.json index 625eb9712e..c20b69a1bf 100644 --- a/test/tests/functions/date.json +++ b/test/tests/functions/date.json @@ -1,5 +1,5 @@ { - "$schema": "https://raw.githubusercontent.com/unicode-org/message-format-wg/main/test/schemas/v0/tests.schema.json", + "$schema": "../../schemas/v0/tests.schema.json", "scenario": "Date function", "description": "The built-in formatter for dates.", "defaultTestProperties": { diff --git a/test/tests/functions/datetime.json b/test/tests/functions/datetime.json index d8e8b6dad9..1d45518290 100644 --- a/test/tests/functions/datetime.json +++ b/test/tests/functions/datetime.json @@ -1,5 +1,5 @@ { - "$schema": "https://raw.githubusercontent.com/unicode-org/message-format-wg/main/test/schemas/v0/tests.schema.json", + "$schema": "../../schemas/v0/tests.schema.json", "scenario": "Datetime function", "description": "The built-in formatter for datetimes.", "defaultTestProperties": { diff --git a/test/tests/functions/integer.json b/test/tests/functions/integer.json index f2d344c951..fa95511f80 100644 --- a/test/tests/functions/integer.json +++ b/test/tests/functions/integer.json @@ -1,5 +1,5 @@ { - "$schema": "https://raw.githubusercontent.com/unicode-org/message-format-wg/main/test/schemas/v0/tests.schema.json", + "$schema": "../../schemas/v0/tests.schema.json", "scenario": "Integer function", "description": "The built-in formatter for integers.", "defaultTestProperties": { diff --git a/test/tests/functions/math.json b/test/tests/functions/math.json index 8041e4ac37..2353d6e206 100644 --- a/test/tests/functions/math.json +++ b/test/tests/functions/math.json @@ -1,5 +1,5 @@ { - "$schema": "https://raw.githubusercontent.com/unicode-org/message-format-wg/main/test/schemas/v0/tests.schema.json", + "$schema": "../../schemas/v0/tests.schema.json", "scenario": "Math function", "description": "The built-in formatter and selector for addition and subtraction.", "defaultTestProperties": { diff --git a/test/tests/functions/number.json b/test/tests/functions/number.json index e98d179246..4c4c809c65 100644 --- a/test/tests/functions/number.json +++ b/test/tests/functions/number.json @@ -1,5 +1,5 @@ { - "$schema": "https://raw.githubusercontent.com/unicode-org/message-format-wg/main/test/schemas/v0/tests.schema.json", + "$schema": "../../schemas/v0/tests.schema.json", "scenario": "Number function", "description": "The built-in formatter for numbers.", "defaultTestProperties": { diff --git a/test/tests/functions/string.json b/test/tests/functions/string.json index 06d0255ce5..67507cf645 100644 --- a/test/tests/functions/string.json +++ b/test/tests/functions/string.json @@ -1,5 +1,5 @@ { - "$schema": "https://raw.githubusercontent.com/unicode-org/message-format-wg/main/test/schemas/v0/tests.schema.json", + "$schema": "../../schemas/v0/tests.schema.json", "scenario": "String function", "description": "The built-in formatter for strings.", "defaultTestProperties": { diff --git a/test/tests/functions/time.json b/test/tests/functions/time.json index 1f6cf22931..56aab3e3fb 100644 --- a/test/tests/functions/time.json +++ b/test/tests/functions/time.json @@ -1,5 +1,5 @@ { - "$schema": "https://raw.githubusercontent.com/unicode-org/message-format-wg/main/test/schemas/v0/tests.schema.json", + "$schema": "../../schemas/v0/tests.schema.json", "scenario": "Time function", "description": "The built-in formatter for times.", "defaultTestProperties": { diff --git a/test/tests/pattern-selection.json b/test/tests/pattern-selection.json index 29dc146c19..69d8cb0639 100644 --- a/test/tests/pattern-selection.json +++ b/test/tests/pattern-selection.json @@ -1,5 +1,5 @@ { - "$schema": "https://raw.githubusercontent.com/unicode-org/message-format-wg/main/test/schemas/v0/tests.schema.json", + "$schema": "../schemas/v0/tests.schema.json", "scenario": "Pattern selection", "description": "Tests for pattern selection", "defaultTestProperties": { diff --git a/test/tests/syntax-errors.json b/test/tests/syntax-errors.json index b2e5ffc6d4..12f41826a4 100644 --- a/test/tests/syntax-errors.json +++ b/test/tests/syntax-errors.json @@ -1,5 +1,5 @@ { - "$schema": "https://raw.githubusercontent.com/unicode-org/message-format-wg/main/test/schemas/v0/tests.schema.json", + "$schema": "../schemas/v0/tests.schema.json", "scenario": "Syntax errors", "description": "Strings that produce syntax errors when parsed.", "defaultTestProperties": { diff --git a/test/tests/syntax.json b/test/tests/syntax.json index 1e8e3048a4..9bc93cb5ea 100644 --- a/test/tests/syntax.json +++ b/test/tests/syntax.json @@ -1,5 +1,5 @@ { - "$schema": "https://raw.githubusercontent.com/unicode-org/message-format-wg/main/test/schemas/v0/tests.schema.json", + "$schema": "../schemas/v0/tests.schema.json", "scenario": "Syntax", "description": "Test cases that do not depend on any registry definitions.", "defaultTestProperties": { diff --git a/test/tests/u-options.json b/test/tests/u-options.json index 815f3d9e58..3cba72ec1d 100644 --- a/test/tests/u-options.json +++ b/test/tests/u-options.json @@ -1,5 +1,5 @@ { - "$schema": "https://raw.githubusercontent.com/unicode-org/message-format-wg/main/test/schemas/v0/tests.schema.json", + "$schema": "../schemas/v0/tests.schema.json", "scenario": "u: Options", "description": "Common options affecting the function context", "defaultTestProperties": {