Skip to content

Commit d06033b

Browse files
eemeliaphillips
andauthored
Add a JSON test suite (#604)
* Move test/* -> test/xml/ * Add test/json/ as a copy of packages/mf2-messageformat/src/__fixtures/ from messageformat/messageformat@11c95da * Add test/json/README.md * Apply suggestions from code review Co-authored-by: Addison Phillips <[email protected]> * Drop the previous XML tests, move test/json/* to just test/ --------- Co-authored-by: Addison Phillips <[email protected]>
1 parent d8e790e commit d06033b

10 files changed

+525
-350
lines changed

test/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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)
2+
and are here relicensed by their original author (Eemeli Aro) under the Unicode License.
3+
4+
These test files are intended to be useful for testing multiple different message processors in different ways:
5+
6+
- `syntax-errors.json` — An array of strings that should produce a Syntax Error or a Data Model Error when parsed.
7+
8+
- `test-core.json` — An array of test cases that do not depend on any registry definitions.
9+
Each test may include some of the following fields:
10+
- `src: string` (required) — The MF2 syntax source.
11+
- `exp: string` (required) — The expected result of formatting the message to a string.
12+
- `locale: string` — The locale to use for formatting. Defaults to 'en-US'.
13+
- `params: Record<string, string | number | null | undefined>` — Parameters to pass in to the formatter for resolving external variables.
14+
- `parts: object[]` — The expected result of formatting the message to parts.
15+
- `cleanSrc: string` — A normalixed form of `src`, for testing stringifiers.
16+
- `errors: { type: string }[]` — The runtime errors expected to be emitted when formatting the message.
17+
- `only: boolean` — Normally not set. A flag to use during development to only run one or more specific tests.
18+
19+
- `test-function.json` — An object with string keys and arrays of test cases as values,
20+
using the same definition as for `test-core.json`.
21+
The keys each correspond to a function that is used in the tests.
22+
23+
TypeScript `.d.ts` files are included for `test-core.json` and `test-function.json` with the above definition.
24+
25+
Some examples of test harnesses using these tests, from the source repository:
26+
- [CST parse/stringify tests](https://github.com/messageformat/messageformat/blob/11c95dab2b25db8454e49ff4daadb817e1d5b770/packages/mf2-messageformat/src/cst/cst.test.ts)
27+
- [Data model stringify tests](https://github.com/messageformat/messageformat/blob/11c95dab2b25db8454e49ff4daadb817e1d5b770/packages/mf2-messageformat/src/data-model/stringify.test.ts)
28+
- [Formatting tests](https://github.com/messageformat/messageformat/blob/11c95dab2b25db8454e49ff4daadb817e1d5b770/packages/mf2-messageformat/src/messageformat.test.ts)

test/format/en_US.xml

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

test/format/es_MX.xml

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

test/format/ru_RU.xml

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

0 commit comments

Comments
 (0)