forked from unicode-org/message-format-wg
-
Notifications
You must be signed in to change notification settings - Fork 0
Validate test cases against provided schema #1
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
Closed
echeran
wants to merge
24
commits into
mradbourne:validate-tests
from
echeran:test-schema-validation
Closed
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
5195793
Add new test schema
mradbourne 21e7ee2
Remove ordinal and plural tests as per https://github.com/unicode-org…
mradbourne 677590c
Improve data-model-errors description
mradbourne 6a7214f
Make `scenario` property optional
mradbourne f5fa711
Schema refactor and typo fix
mradbourne 92c06e3
Minor schema refactors
mradbourne 3a5136b
Remove redundant `type` properties from params
mradbourne ba74af9
Version test schema
mradbourne f406915
Rename core to syntax
mradbourne 7c4353e
Add array types to `src` and `expCleanSrc` for readability
mradbourne ff5f34c
Add formatted-parts schema
mradbourne d97a41f
Simplify expParts
mradbourne 5481531
Make `name` property required in `var`
mradbourne 8e816db
Fix indentation
mradbourne 0727525
Update README and description
mradbourne b9fb07b
Update error types
mradbourne e5f4058
Remove testType property
mradbourne 1242ac7
Allow additional properties in message expression part
mradbourne 8481e37
Remove array version of `src`
mradbourne 3ca3ff6
Disallow presence of both `parts` and `value` in expression part
mradbourne 1ba5f56
Change literal from number to string in test
mradbourne 1ddd4ee
Add missing additionalProperties:false
mradbourne 1c6032c
Change incorrect string literal part to integer expression
mradbourne dcd9eec
Validate test cases against provided schema
echeran File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| name: Validate test data | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
| branches: '**' | ||
|
|
||
| jobs: | ||
| run_all: | ||
| name: Validate tests for specific schema version | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout repo | ||
| uses: actions/checkout@v4 | ||
| - name: Validate tests for schema v0.0.1 | ||
| run: | | ||
| cd test | ||
| python3 validate.py --schema-dir ./schemas/v0-0-1/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With something like this, we don't need to define a custom validator script:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of reusing a tool and not having to write a script. But having to enumerate each nested directory is annoying. Also, do we want a command to automatically figure out our latest schema version? The
ajvtool only takes a hard coded schema version.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, the
**segment in the glob pattern takes care of nested directories, so that's not an issue. The only issue is whether we want to have this CI job automatically take the latest schema version, or if we want to manually maintain the CI job to reflect the latest schema every time we change it.