Skip to content

Commit

Permalink
ICU-22927 Duplicate (back) the MF2 test data between icu4c and icu4j
Browse files Browse the repository at this point in the history
The C++ and Java implementations are done by two different people different companies.
With different time constraints and availability.
The spec is still not final (although it is close), and the implementations are
still quite a bit behind.
Sharing these test files slows down development, by forcing any C++ and Java changes
to happen in the same time.

There are other components that share test files that are not shared yet,
even if they are more stable. So I don't know why we would force this on MF2 only.

This is temporary, and the data files will be de-duplicated again at a later time,
when the two implementations are more stable.
That de-duplication will include other shared files, and in a slightly different structure
(we have a doc and a discution on this topic).
  • Loading branch information
mihnita committed Nov 13, 2024
1 parent 0b9eb9c commit 8b28c38
Show file tree
Hide file tree
Showing 34 changed files with 3,855 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,20 +200,5 @@ private static Path getTestFile(Class<?> cls, String fileName) throws URISyntaxE
URI getPath = cls.getClassLoader().getResource(packageName).toURI();
Path filePath = Paths.get(getPath);
Path json = Paths.get(fileName);
// First, check the top level of the source directory,
// in case we're in a source tarball
Path icuTestdataInSourceDir = filePath.resolve("../../../../../../../../../../../testdata/message2/").normalize();
Path icuTestdataDir = icuTestdataInSourceDir;
if (!Files.isDirectory(icuTestdataInSourceDir)) {
// If that doesn't exist, check one directory higher, in case we're
// in a checked-out repo
Path icuTestdataInRepo = Paths.get("../").resolve(icuTestdataInSourceDir).normalize();
if (!Files.isDirectory(icuTestdataInRepo)) {
throw new java.io.FileNotFoundException("Test data directory does not exist: tried "
+ icuTestdataInSourceDir + " and "
+ icuTestdataInRepo);
}
icuTestdataDir = icuTestdataInSourceDir;
}
return icuTestdataDir.resolve(json);
return filePath.resolve(json);
}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
© 2024 and later: Unicode, Inc. and others.
License & terms of use: http://www.unicode.org/copyright.html

The format of the JSON files in this directory and subdirectories
follow the test schema defined in the Conformance repository:

https://github.com/unicode-org/conformance/blob/main/schema/message_fmt2/testgen_schema.json

(as of https://github.com/unicode-org/conformance/pull/255 or later).

# JSON notes

In the "params" field, a date parameter can be expressed as:
{ "date": n }
where n is a number representing a Unix timestamp.

In the "params" field, a decimal string parameter can be expressed as:
{ "decimal": s }
where s is a string.

Optional fields, "ignoreJava" and "ignoreCpp" can be used
for tests currently expected to fail in the respective language.
The field may have any value; if it's
present, the test is ignored. (The value can be a comment explaining
why it's expected to fail.)

Tests in the `spec/` subdirectory are taken from https://github.com/unicode-org/message-format-wg/blob/main/test .
If the contents change upstream, then the corresponding tests in CLDR
need to be updated (also see https://unicode-org.atlassian.net/browse/ICU-22812 ).

## ICU4J only

The `cleanSrc` fields is used to represent normalized input (ICU4C has its
own function for normalizing input).

## ICU4C only

Additional "char" and "line" fields may be present with integer values,
used for tests expected to trigger a syntax error.
If present, "char" reflects the expected character offset and "line"
reflects the expected line number in the parse error.
The files with "diagnostics" in the name have these fields filled in.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"scenario": "Selector annotations",
"description": "Tests for indirectly annotated selectors",
"defaultTestProperties": {
"locale": "en-US"
},
"tests": [
{
"src": ".local $one = {|The one| :string}\n .match {$one}\n 1 {{Value is one}}\n * {{Value is not one}}",
"exp": "Value is not one"
},
{
"src": ".local $one = {|The one| :string}\n .local $two = {$one}\n .match {$two}\n 1 {{Value is one}}\n * {{Value is not one}}",
"exp": "Value is not one"
}
]
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"scenario": "Duplicate declaration errors",
"description": "Tests that should trigger a duplicate declaration error",
"defaultTestProperties": {
"locale": "en-US",
"expErrors": [
{
"type": "duplicate-declaration"
}
]
},
"tests": [
{
"src": ".local $foo = {$foo} .local $foo = {42} {{bar {$foo}}}",
"params": [{ "name": "foo", "value": "foo" }],
"exp": "bar 42"
},
{
"src": ".local $foo = {42} .local $foo = {42} {{bar {$foo}}}",
"params": [{ "name": "foo", "value": "foo" }],
"exp": "bar 42"
},
{
"src": ".local $foo = {:unknown} .local $foo = {42} {{bar {$foo}}}",
"params": [{ "name": "foo", "value": "foo" }],
"exp": "bar 42"
},
{
"src": ".local $x = {42} .local $y = {$x} .local $x = {13} {{{$x} {$y}}}",
"exp": "13 42"
},
{
"src": ".local $foo = {$foo} {{bar {$foo}}}",
"params": [{ "name": "foo", "value": "foo" }],
"exp": "bar foo"
},
{
"src": ".local $foo = {$bar} .local $bar = {$baz} {{bar {$foo}}}",
"params": [{ "name": "baz", "value": "foo" }],
"exp": "bar {$bar}"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"scenario": "Valid tests",
"description": "Additional valid tests",
"defaultTestProperties": {
"locale": "en-US"
},
"tests": [
{ "src": "" },
{ "src": "Hello" },
{ "src": "Hello world!" },
{ "src": "Hello \t \n \r \\{ world!" },
{ "src": "Hello world {:datetime}" },
{ "src": "Hello world {foo}" },
{ "src": "Hello {0} world" },
{ "src": "Hello {123} world" },
{ "src": "Hello {-123} world" },
{ "src": "Hello {3.1416} world" },
{ "src": "Hello {-3.1416} world" },
{ "src": "Hello {123E+2} world" },
{ "src": "Hello {123E-2} world" },
{ "src": "Hello {123.456E+2} world" },
{ "src": "Hello {123.456E-2} world" },
{ "src": "Hello {-123.456E+2} world" },
{ "src": "Hello {-123.456E-2} world" },
{ "src": "Hello {-123E+2} world" },
{ "src": "Hello {-123E-2} world" },
{ "src": "Hello world {$exp}" },
{ "src": "Hello world {$exp :datetime}" },
{ "src": "Hello world {|2024-02-27| :datetime}" },
{ "src": "Hello world {$exp :datetime style=long} and more" },
{ "src": "Hello world {$exp :function number=1234} and more" },
{ "src": "Hello world {$exp :function unquoted=left } and more" },
{ "src": "Hello world {$exp :function quoted=|Something| } and more" },
{ "src": "Hello world {$exp :function quoted=|Something with spaces| } and more" },
{ "src": "Hello world {$exp :function quoted=|Something with \\| spaces and \\| escapes| } and more" },
{ "src": "Hello world {$exp :function number=1234 unquoted=left quoted=|Something|}" },
{ "src": "Hello world {$exp :function number=1234 unquoted=left quoted=|Something longer|}" },
{ "src": "Hello world {$exp :function number=1234 unquoted=left quoted=|Something \\| longer|}" },
{ "src": "Hello world {$exp}" },
{ "src": "Hello world {$exp @attr}" },
{ "src": "Hello world {$exp @valid @attr=a @attrb=123 @atrn=|foo bar|}" },
{ "src": "Hello world {$exp :date @valid @attr=aaaa @attrb=123 @atrn=|foo bar|}" },
{ "src": "Hello world {$exp :date year=numeric month=long day=numeric int=12 @valid @attr=a @attrb=123 @atrn=|foo bar|}" },
{ "src": "{{.starting with dot is OK here}}" },
{ "src": "{{Some string pattern \\}, with {$foo} and {$exp :date style=long}!}}" },
{ "src": ".input {$pi :number} {{}}" },
{ "src": ".input {$exp :date} {{}}" },
{ "src": ".local $foo = {$exp} {{}}" },
{ "src": ".local $foo = {$exp :date} {{}}" },
{ "src": ".local $foo = {$exp :date year=numeric month=long day=numeric} {{}}" },
{ "src": ".local $bar = {$foo :date month=medium} {{}}" },
{ "src": ".input {$a :date} .local $exp = {$a :date style=full} {{Your card expires on {$exp}!}}" },
{ "src": ".input {$a :date} .local $b = {$a :date year=numeric month=long day=numeric} .local $c = {$b :date month=medium} {{}}" },
{ "src": ".input {$x :number} {{_}}" },
{ "src": ".local $foo = {|1|} {{_}}" }
]
}
Loading

0 comments on commit 8b28c38

Please sign in to comment.