|
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) |
2 | 2 | and are here relicensed by their original author (Eemeli Aro) under the Unicode License. |
3 | 3 |
|
4 | 4 | These test files are intended to be useful for testing multiple different message processors in different ways: |
5 | 5 |
|
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. |
33 | 16 |
|
34 | 17 | Some examples of test harnesses using these tests, from the source repository: |
| 18 | + |
35 | 19 | - [CST parse/stringify tests](https://github.com/messageformat/messageformat/blob/11c95dab2b25db8454e49ff4daadb817e1d5b770/packages/mf2-messageformat/src/cst/cst.test.ts) |
36 | 20 | - [Data model stringify tests](https://github.com/messageformat/messageformat/blob/11c95dab2b25db8454e49ff4daadb817e1d5b770/packages/mf2-messageformat/src/data-model/stringify.test.ts) |
37 | 21 | - [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. |
0 commit comments