-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: extract icu-messageformat-parser test cases into their own tes…
…t case files (#3763) Co-authored-by: long.ho <long.ho@cloudkitchens.com>
- Loading branch information
1 parent
ac722ed
commit 2ce29a2
Showing
114 changed files
with
7,099 additions
and
7,160 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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,36 @@ | ||
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files") | ||
load("//tools:index.bzl", "generate_src_file") | ||
load("@npm//:defs.bzl", "npm_link_all_packages") | ||
|
||
npm_link_all_packages(name = "node_modules") | ||
|
||
TEST_CASES = glob(["test_cases/*"]) | ||
|
||
# [ts_script( | ||
# name = "gen_parser_test_%s" % f.split("/")[-1], | ||
# outs = ["%s.tmp" % f.split("/")[-1]], | ||
# args = [ | ||
# "--input", | ||
# f | ||
# ], | ||
# data = [ | ||
# ":node_modules/@formatjs/icu-messageformat-parser", | ||
# "//:node_modules/lodash", | ||
# f | ||
# ], | ||
# entry_point = "run-parser.ts", | ||
# ) for f in TEST_CASES] | ||
|
||
[generate_src_file( | ||
name = "gen_parser_test_%s" % f.split("/")[-1], | ||
src = f, | ||
data = [ | ||
":node_modules/@formatjs/icu-messageformat-parser", | ||
"//:node_modules/lodash", | ||
f | ||
], | ||
args = [ | ||
"--input %s/%s" % (package_name(),f), | ||
], | ||
entry_point = "run-parser.ts", | ||
) for f in TEST_CASES] |
5 changes: 5 additions & 0 deletions
5
packages/icu-messageformat-parser/integration-tests/package.json
This file contains 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,5 @@ | ||
{ | ||
"dependencies": { | ||
"@formatjs/icu-messageformat-parser": "workspace:*" | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
packages/icu-messageformat-parser/integration-tests/run-parser.ts
This file contains 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,38 @@ | ||
import {_Parser} from '@formatjs/icu-messageformat-parser' | ||
import fs from 'fs' | ||
import minimist from 'minimist' | ||
|
||
interface Args extends minimist.ParsedArgs { | ||
input: string | ||
out: string | ||
} | ||
|
||
function run({input, out}: Args) { | ||
console.log(__dirname) | ||
const sections = fs.readFileSync(input, 'utf-8').split('\n---\n') | ||
const message = sections[0] | ||
const snapshotOptions = JSON.parse(sections[1]) | ||
const options = {...snapshotOptions} | ||
// Note: allow locale to be specified via an identifier. | ||
if (options.locale) { | ||
options.locale = new Intl.Locale(options.locale) | ||
} | ||
|
||
const parsed = new _Parser(message, options).parse() | ||
|
||
// If the mismatch is intentional, use `UPDATE_SNAPSHOT=1` env var | ||
// with bazel run to update the snapshot. | ||
fs.writeFileSync( | ||
out, | ||
[ | ||
message, | ||
JSON.stringify(snapshotOptions, null, 2), | ||
JSON.stringify(parsed, null, 2), | ||
].join('\n---\n'), | ||
'utf-8' | ||
) | ||
} | ||
|
||
if (require.main === module) { | ||
run(minimist<Args>(process.argv.slice(2))) | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/icu-messageformat-parser/integration-tests/test_cases/basic_argument_1
This file contains 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,25 @@ | ||
{a} | ||
--- | ||
{} | ||
--- | ||
{ | ||
"val": [ | ||
{ | ||
"type": 1, | ||
"value": "a", | ||
"location": { | ||
"start": { | ||
"offset": 0, | ||
"line": 1, | ||
"column": 1 | ||
}, | ||
"end": { | ||
"offset": 3, | ||
"line": 1, | ||
"column": 4 | ||
} | ||
} | ||
} | ||
], | ||
"err": null | ||
} |
58 changes: 58 additions & 0 deletions
58
packages/icu-messageformat-parser/integration-tests/test_cases/basic_argument_2
This file contains 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,58 @@ | ||
a {b} | ||
c | ||
--- | ||
{} | ||
--- | ||
{ | ||
"val": [ | ||
{ | ||
"type": 0, | ||
"value": "a ", | ||
"location": { | ||
"start": { | ||
"offset": 0, | ||
"line": 1, | ||
"column": 1 | ||
}, | ||
"end": { | ||
"offset": 2, | ||
"line": 1, | ||
"column": 3 | ||
} | ||
} | ||
}, | ||
{ | ||
"type": 1, | ||
"value": "b", | ||
"location": { | ||
"start": { | ||
"offset": 2, | ||
"line": 1, | ||
"column": 3 | ||
}, | ||
"end": { | ||
"offset": 5, | ||
"line": 1, | ||
"column": 6 | ||
} | ||
} | ||
}, | ||
{ | ||
"type": 0, | ||
"value": " \nc", | ||
"location": { | ||
"start": { | ||
"offset": 5, | ||
"line": 1, | ||
"column": 6 | ||
}, | ||
"end": { | ||
"offset": 8, | ||
"line": 2, | ||
"column": 2 | ||
} | ||
} | ||
} | ||
], | ||
"err": null | ||
} |
42 changes: 42 additions & 0 deletions
42
packages/icu-messageformat-parser/integration-tests/test_cases/date_arg_skeleton_1
This file contains 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,42 @@ | ||
{0, date, ::yyyy.MM.dd G 'at' HH:mm:ss vvvv} | ||
--- | ||
{} | ||
--- | ||
{ | ||
"val": [ | ||
{ | ||
"type": 3, | ||
"value": "0", | ||
"location": { | ||
"start": { | ||
"offset": 0, | ||
"line": 1, | ||
"column": 1 | ||
}, | ||
"end": { | ||
"offset": 44, | ||
"line": 1, | ||
"column": 45 | ||
} | ||
}, | ||
"style": { | ||
"type": 1, | ||
"pattern": "yyyy.MM.dd G 'at' HH:mm:ss vvvv", | ||
"location": { | ||
"start": { | ||
"offset": 10, | ||
"line": 1, | ||
"column": 11 | ||
}, | ||
"end": { | ||
"offset": 43, | ||
"line": 1, | ||
"column": 44 | ||
} | ||
}, | ||
"parsedOptions": {} | ||
} | ||
} | ||
], | ||
"err": null | ||
} |
42 changes: 42 additions & 0 deletions
42
packages/icu-messageformat-parser/integration-tests/test_cases/date_arg_skeleton_2
This file contains 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,42 @@ | ||
{0, date, ::EEE, MMM d, ''yy} | ||
--- | ||
{} | ||
--- | ||
{ | ||
"val": [ | ||
{ | ||
"type": 3, | ||
"value": "0", | ||
"location": { | ||
"start": { | ||
"offset": 0, | ||
"line": 1, | ||
"column": 1 | ||
}, | ||
"end": { | ||
"offset": 29, | ||
"line": 1, | ||
"column": 30 | ||
} | ||
}, | ||
"style": { | ||
"type": 1, | ||
"pattern": "EEE, MMM d, ''yy", | ||
"location": { | ||
"start": { | ||
"offset": 10, | ||
"line": 1, | ||
"column": 11 | ||
}, | ||
"end": { | ||
"offset": 28, | ||
"line": 1, | ||
"column": 29 | ||
} | ||
}, | ||
"parsedOptions": {} | ||
} | ||
} | ||
], | ||
"err": null | ||
} |
42 changes: 42 additions & 0 deletions
42
packages/icu-messageformat-parser/integration-tests/test_cases/date_arg_skeleton_3
This file contains 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,42 @@ | ||
{0, date, ::h:mm a} | ||
--- | ||
{} | ||
--- | ||
{ | ||
"val": [ | ||
{ | ||
"type": 3, | ||
"value": "0", | ||
"location": { | ||
"start": { | ||
"offset": 0, | ||
"line": 1, | ||
"column": 1 | ||
}, | ||
"end": { | ||
"offset": 19, | ||
"line": 1, | ||
"column": 20 | ||
} | ||
}, | ||
"style": { | ||
"type": 1, | ||
"pattern": "h:mm a", | ||
"location": { | ||
"start": { | ||
"offset": 10, | ||
"line": 1, | ||
"column": 11 | ||
}, | ||
"end": { | ||
"offset": 18, | ||
"line": 1, | ||
"column": 19 | ||
} | ||
}, | ||
"parsedOptions": {} | ||
} | ||
} | ||
], | ||
"err": null | ||
} |
49 changes: 49 additions & 0 deletions
49
...es/icu-messageformat-parser/integration-tests/test_cases/date_arg_skeleton_with_capital_J
This file contains 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,49 @@ | ||
{0, date, ::J} | ||
--- | ||
{ | ||
"locale": "und-u-hc-h12", | ||
"shouldParseSkeletons": true, | ||
"requiresOtherClause": true | ||
} | ||
--- | ||
{ | ||
"val": [ | ||
{ | ||
"type": 3, | ||
"value": "0", | ||
"location": { | ||
"start": { | ||
"offset": 0, | ||
"line": 1, | ||
"column": 1 | ||
}, | ||
"end": { | ||
"offset": 14, | ||
"line": 1, | ||
"column": 15 | ||
} | ||
}, | ||
"style": { | ||
"type": 1, | ||
"pattern": "H", | ||
"location": { | ||
"start": { | ||
"offset": 10, | ||
"line": 1, | ||
"column": 11 | ||
}, | ||
"end": { | ||
"offset": 13, | ||
"line": 1, | ||
"column": 14 | ||
} | ||
}, | ||
"parsedOptions": { | ||
"hourCycle": "h23", | ||
"hour": "numeric" | ||
} | ||
} | ||
} | ||
], | ||
"err": null | ||
} |
Oops, something went wrong.