Skip to content

Commit ed6b1da

Browse files
authored
Add test schema (#767)
1 parent 4c5e301 commit ed6b1da

18 files changed

+1816
-675
lines changed

test/.vscode/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"json.schemas": [
3+
{
4+
"fileMatch": [
5+
"tests/**/*.json"
6+
],
7+
"url": "./schemas/v0/tests.schema.json"
8+
}
9+
]
10+
}

test/README.md

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,25 @@
1-
The files in this directory were originally copied from the [messageformat project](https://github.com/messageformat/messageformat/tree/11c95dab2b25db8454e49ff4daadb817e1d5b770/packages/mf2-messageformat/src/__fixtures)
1+
The tests in the `./tests/` directory were originally copied from the [messageformat project](https://github.com/messageformat/messageformat/tree/11c95dab2b25db8454e49ff4daadb817e1d5b770/packages/mf2-messageformat/src/__fixtures)
22
and are here relicensed by their original author (Eemeli Aro) under the Unicode License.
33

44
These test files are intended to be useful for testing multiple different message processors in different ways:
55

6-
- `syntax-errors.json` — An array of strings that should produce a Syntax Error when parsed.
7-
8-
- `data-model-errors.json` - An object with string keys and arrays of strings as values,
9-
where each key is the name of an error and its value is an array of strings that
10-
should produce `error` when processed.
11-
Error names are defined in ["MessageFormat 2.0 Errors"](../spec/errors.md) in the spec.
12-
13-
- `test-core.json` — An array of test cases that do not depend on any registry definitions.
14-
Each test may include some of the following fields:
15-
- `src: string` (required) — The MF2 syntax source.
16-
- `exp: string` (required) — The expected result of formatting the message to a string.
17-
- `locale: string` — The locale to use for formatting. Defaults to 'en-US'.
18-
- `params: Record<string, string | number | null | undefined>` — Parameters to pass in to the formatter for resolving external variables.
19-
- `parts: object[]` — The expected result of formatting the message to parts.
20-
- `cleanSrc: string` — A normalixed form of `src`, for testing stringifiers.
21-
- `errors: { type: string }[]` — The runtime errors expected to be emitted when formatting the message.
22-
If `errors` is either absent or empty, the message must be formatted without errors.
23-
- `only: boolean` — Normally not set. A flag to use during development to only run one or more specific tests.
24-
25-
- `test-function.json` — An object with string keys and arrays of test cases as values,
26-
using the same definition as for `test-core.json`.
27-
The keys each correspond to a function that is used in the tests.
28-
Since the behavior of built-in formatters is implementation-specific,
29-
the `exp` field should generally be omitted,
30-
except for error cases.
31-
32-
TypeScript `.d.ts` files are included for `test-core.json` and `test-function.json` with the above definition.
6+
- `syntax.json` — Test cases that do not depend on any registry definitions.
7+
8+
- `syntax-errors.json` — Strings that should produce a Syntax Error when parsed.
9+
10+
- `data-model-errors.json` - Strings that should produce Data Model Error when processed.
11+
Error names are defined in ["MessageFormat 2.0 Errors"](../spec/errors.md) in the spec.
12+
13+
- `functions/` — Test cases that correspond to built-in functions.
14+
The behaviour of the built-in formatters is implementation-specific so the `exp` field is often
15+
omitted and assertions are made on error cases.
3316

3417
Some examples of test harnesses using these tests, from the source repository:
18+
3519
- [CST parse/stringify tests](https://github.com/messageformat/messageformat/blob/11c95dab2b25db8454e49ff4daadb817e1d5b770/packages/mf2-messageformat/src/cst/cst.test.ts)
3620
- [Data model stringify tests](https://github.com/messageformat/messageformat/blob/11c95dab2b25db8454e49ff4daadb817e1d5b770/packages/mf2-messageformat/src/data-model/stringify.test.ts)
3721
- [Formatting tests](https://github.com/messageformat/messageformat/blob/11c95dab2b25db8454e49ff4daadb817e1d5b770/packages/mf2-messageformat/src/messageformat.test.ts)
22+
23+
A [JSON schema](./schemas/) is included for the test files in this repository.
24+
25+
For users of Visual Studio Code, a [settings file](./.vscode/settings.json) is included that enables schema validation while editing the test files.

test/data-model-errors.json

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)