Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new test schema #767

Merged
merged 25 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5195793
Add new test schema
mradbourne Apr 12, 2024
21e7ee2
Remove ordinal and plural tests as per https://github.com/unicode-org…
mradbourne Apr 15, 2024
677590c
Improve data-model-errors description
mradbourne Apr 15, 2024
6a7214f
Make `scenario` property optional
mradbourne Apr 15, 2024
f5fa711
Schema refactor and typo fix
mradbourne Apr 15, 2024
92c06e3
Minor schema refactors
mradbourne Apr 15, 2024
3a5136b
Remove redundant `type` properties from params
mradbourne Apr 15, 2024
ba74af9
Version test schema
mradbourne Apr 16, 2024
f406915
Rename core to syntax
mradbourne Apr 16, 2024
7c4353e
Add array types to `src` and `expCleanSrc` for readability
mradbourne Apr 16, 2024
ff5f34c
Add formatted-parts schema
mradbourne Apr 17, 2024
d97a41f
Simplify expParts
mradbourne Apr 19, 2024
5481531
Make `name` property required in `var`
mradbourne Apr 19, 2024
8e816db
Fix indentation
mradbourne Apr 19, 2024
0727525
Update README and description
mradbourne Apr 19, 2024
b9fb07b
Update error types
mradbourne Apr 22, 2024
e5f4058
Remove testType property
mradbourne Apr 22, 2024
1242ac7
Allow additional properties in message expression part
mradbourne Apr 22, 2024
8481e37
Remove array version of `src`
mradbourne Apr 23, 2024
3ca3ff6
Disallow presence of both `parts` and `value` in expression part
mradbourne Apr 23, 2024
1ba5f56
Change literal from number to string in test
mradbourne Apr 23, 2024
1ddd4ee
Add missing additionalProperties:false
mradbourne Apr 23, 2024
1c6032c
Change incorrect string literal part to integer expression
mradbourne Apr 23, 2024
d901660
Simplify schema versioning
mradbourne Apr 29, 2024
4fc58e8
Remove outdated description
mradbourne Apr 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions test/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"json.schemas": [
{
"fileMatch": [
"tests/**/*.json"
],
"url": "./schemas/v0-0-1/tests.schema.json"
}
]
}
44 changes: 16 additions & 28 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,25 @@
The files in this directory were originally copied from the [messageformat project](https://github.com/messageformat/messageformat/tree/11c95dab2b25db8454e49ff4daadb817e1d5b770/packages/mf2-messageformat/src/__fixtures)
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)
and are here relicensed by their original author (Eemeli Aro) under the Unicode License.

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 when parsed.

- `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 an array of strings that
should produce `error` when processed.
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:
- `src: string` (required) — The MF2 syntax source.
- `exp: string` (required) — The expected result of formatting the message to a string.
- `locale: string` — The locale to use for formatting. Defaults to 'en-US'.
- `params: Record<string, string | number | null | undefined>` — Parameters to pass in to the formatter for resolving external variables.
- `parts: object[]` — The expected result of formatting the message to parts.
- `cleanSrc: string` — A normalixed form of `src`, for testing stringifiers.
- `errors: { type: string }[]` — The runtime errors expected to be emitted when formatting the message.
If `errors` is either absent or empty, the message must be formatted without errors.
- `only: boolean` — Normally not set. A flag to use during development to only run one or more specific tests.

- `test-function.json` — An object with string keys and arrays of test cases as values,
using the same definition as for `test-core.json`.
The keys each correspond to a function that is used in the tests.
Since the behavior of built-in formatters is implementation-specific,
the `exp` field should generally be omitted,
except for error cases.

TypeScript `.d.ts` files are included for `test-core.json` and `test-function.json` with the above definition.
- `syntax.json` — Test cases that do not depend on any registry definitions.

- `syntax-errors.json` — Strings that should produce a Syntax Error when parsed.

- `data-model-errors.json` - Strings that should produce Data Model Error when processed.
Error names are defined in ["MessageFormat 2.0 Errors"](../spec/errors.md) in the spec.

- `functions/` — Test cases that correspond to built-in functions.
The behaviour of the built-in formatters is implementation-specific so the `exp` field is often
omitted and assertions are made on error cases.

Some examples of test harnesses using these tests, from the source repository:

- [CST parse/stringify tests](https://github.com/messageformat/messageformat/blob/11c95dab2b25db8454e49ff4daadb817e1d5b770/packages/mf2-messageformat/src/cst/cst.test.ts)
- [Data model stringify tests](https://github.com/messageformat/messageformat/blob/11c95dab2b25db8454e49ff4daadb817e1d5b770/packages/mf2-messageformat/src/data-model/stringify.test.ts)
- [Formatting tests](https://github.com/messageformat/messageformat/blob/11c95dab2b25db8454e49ff4daadb817e1d5b770/packages/mf2-messageformat/src/messageformat.test.ts)

A JSON schema is included for the test files in this repository. [Semantic-versioned](https://semver.org/) schema files can be found in the [schemas folder](./schemas/).

For users of Visual Studio Code, a [settings file](./.vscode/settings.json) is included that enables schema validation while editing the test files.
32 changes: 0 additions & 32 deletions test/data-model-errors.json

This file was deleted.

Loading