mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-08 06:53:45 +00:00
Update spec tests to current version from message-format-wg - Update parser for changed name-start grammar rule - Validate number literals in :number implementation (since parser no longer does this) - Disallow `:number`/`:integer` select option set from variable See https://github.com/unicode-org/message-format-wg/pull/1016 As part of this, un-skip tests where the `bad-option` error is expected, and implement validating digit size options (pending PR https://github.com/unicode-org/icu/pull/2973 is intended to do this more fully)
340 lines
7.7 KiB
JSON
340 lines
7.7 KiB
JSON
{
|
|
"$schema": "https://raw.githubusercontent.com/unicode-org/message-format-wg/main/test/schemas/v0/tests.schema.json",
|
|
"scenario": "Number function",
|
|
"description": "The built-in formatter for numbers.",
|
|
"defaultTestProperties": {
|
|
"bidiIsolation": "none",
|
|
"locale": "en-US"
|
|
},
|
|
"tests": [
|
|
{
|
|
"src": "hello {4.2 :number}",
|
|
"exp": "hello 4.2"
|
|
},
|
|
{
|
|
"src": "hello {-4.20 :number}",
|
|
"exp": "hello -4.2"
|
|
},
|
|
{
|
|
"src": "hello {0.42 :number}",
|
|
"exp": "hello 0.42"
|
|
},
|
|
{
|
|
"src": "hello {|0.42e+1| :number}",
|
|
"exp": "hello 4.2"
|
|
},
|
|
{
|
|
"src": "hello {00 :number}",
|
|
"exp": "hello {|00|}",
|
|
"expErrors": [
|
|
{
|
|
"type": "bad-operand"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"src": "hello {042 :number}",
|
|
"exp": "hello {|042|}",
|
|
"expErrors": [
|
|
{
|
|
"type": "bad-operand"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"src": "hello {1. :number}",
|
|
"exp": "hello {|1.|}",
|
|
"expErrors": [
|
|
{
|
|
"type": "bad-operand"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"src": "hello {1e :number}",
|
|
"exp": "hello {|1e|}",
|
|
"expErrors": [
|
|
{
|
|
"type": "bad-operand"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"src": "hello {1E :number}",
|
|
"exp": "hello {|1E|}",
|
|
"expErrors": [
|
|
{
|
|
"type": "bad-operand"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"src": "hello {1.e :number}",
|
|
"exp": "hello {|1.e|}",
|
|
"expErrors": [
|
|
{
|
|
"type": "bad-operand"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"src": "hello {1.2e :number}",
|
|
"exp": "hello {|1.2e|}",
|
|
"expErrors": [
|
|
{
|
|
"type": "bad-operand"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"src": "hello {1.e3 :number}",
|
|
"exp": "hello {|1.e3|}",
|
|
"expErrors": [
|
|
{
|
|
"type": "bad-operand"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"src": "hello {1e+ :number}",
|
|
"exp": "hello {|1e+|}",
|
|
"expErrors": [
|
|
{
|
|
"type": "bad-operand"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"src": "hello {1e- :number}",
|
|
"exp": "hello {|1e-|}",
|
|
"expErrors": [
|
|
{
|
|
"type": "bad-operand"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"src": "hello {1.0e2.0 :number}",
|
|
"exp": "hello {|1.0e2.0|}",
|
|
"expErrors": [
|
|
{
|
|
"type": "bad-operand"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"src": "hello {foo :number}",
|
|
"exp": "hello {|foo|}",
|
|
"expErrors": [
|
|
{
|
|
"type": "bad-operand"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"src": "invalid number literal {|.1| :number}",
|
|
"exp": "invalid number literal {|.1|}",
|
|
"expErrors": [
|
|
{
|
|
"type": "bad-operand"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"src": "invalid number literal {|1.| :number}",
|
|
"exp": "invalid number literal {|1.|}",
|
|
"expErrors": [
|
|
{
|
|
"type": "bad-operand"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"src": "invalid number literal {|01| :number}",
|
|
"exp": "invalid number literal {|01|}",
|
|
"expErrors": [
|
|
{
|
|
"type": "bad-operand"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"src": "invalid number literal {|+1| :number}",
|
|
"exp": "invalid number literal {|+1|}",
|
|
"expErrors": [
|
|
{
|
|
"type": "bad-operand"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"src": "invalid number literal {|0x1| :number}",
|
|
"exp": "invalid number literal {|0x1|}",
|
|
"expErrors": [
|
|
{
|
|
"type": "bad-operand"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"src": "hello {:number}",
|
|
"exp": "hello {:number}",
|
|
"expErrors": [
|
|
{
|
|
"type": "bad-operand"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"src": "hello {4.2 :number minimumFractionDigits=2}",
|
|
"exp": "hello 4.20"
|
|
},
|
|
{
|
|
"src": "hello {|4.2| :number minimumFractionDigits=|2|}",
|
|
"exp": "hello 4.20"
|
|
},
|
|
{
|
|
"src": "hello {4.2 :number minimumFractionDigits=$foo}",
|
|
"params": [
|
|
{
|
|
"name": "foo",
|
|
"value": 2
|
|
}
|
|
],
|
|
"exp": "hello 4.20"
|
|
},
|
|
{
|
|
"src": "hello {|4.2| :number minimumFractionDigits=$foo}",
|
|
"params": [
|
|
{
|
|
"name": "foo",
|
|
"value": "2"
|
|
}
|
|
],
|
|
"exp": "hello 4.20"
|
|
},
|
|
{
|
|
"src": ".local $foo = {$bar :number} {{bar {$foo}}}",
|
|
"params": [
|
|
{
|
|
"name": "bar",
|
|
"value": 4.2
|
|
}
|
|
],
|
|
"exp": "bar 4.2"
|
|
},
|
|
{
|
|
"src": ".local $foo = {$bar :number minimumFractionDigits=2} {{bar {$foo}}}",
|
|
"params": [
|
|
{
|
|
"name": "bar",
|
|
"value": 4.2
|
|
}
|
|
],
|
|
"exp": "bar 4.20"
|
|
},
|
|
{
|
|
"src": ".local $foo = {$bar :number minimumFractionDigits=foo} {{bar {$foo}}}",
|
|
"params": [{ "name": "bar", "value": 4.2 }],
|
|
"expErrors": [{ "type": "bad-option" }]
|
|
},
|
|
{
|
|
"src": ".local $foo = {$bar :number} {{bar {$foo}}}",
|
|
"params": [{ "name": "bar", "value": "foo" }],
|
|
"exp": "bar {$foo}",
|
|
"expErrors": [{ "type": "bad-operand" }]
|
|
},
|
|
{
|
|
"src": ".input {$foo :number} {{bar {$foo}}}",
|
|
"params": [
|
|
{
|
|
"name": "foo",
|
|
"value": 4.2
|
|
}
|
|
],
|
|
"exp": "bar 4.2"
|
|
},
|
|
{
|
|
"src": ".input {$foo :number minimumFractionDigits=2} {{bar {$foo}}}",
|
|
"params": [
|
|
{
|
|
"name": "foo",
|
|
"value": 4.2
|
|
}
|
|
],
|
|
"exp": "bar 4.20"
|
|
},
|
|
{
|
|
"src": ".input {$foo :number minimumFractionDigits=foo} {{bar {$foo}}}",
|
|
"params": [{ "name": "foo", "value": 4.2 }],
|
|
"expErrors": [{ "type": "bad-option" }]
|
|
},
|
|
{
|
|
"src": ".input {$foo :number} {{bar {$foo}}}",
|
|
"params": [
|
|
{
|
|
"name": "foo",
|
|
"value": "foo"
|
|
}
|
|
],
|
|
"exp": "bar {$foo}",
|
|
"expErrors": [
|
|
{
|
|
"type": "bad-operand"
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"description": "formatting with select=literal has no effect",
|
|
"src": "literal select {1 :number select=exact}",
|
|
"exp": "literal select 1"
|
|
},
|
|
{
|
|
"description": "select=$var with local literal value causes error but no fallback",
|
|
"src": ".local $bad = {exact} {{variable select {1 :number select=$bad}}}",
|
|
"exp": "variable select 1",
|
|
"expErrors": [{ "type": "bad-option" }]
|
|
},
|
|
{
|
|
"description": "select=$var with external string value is not allowed",
|
|
"src": "variable select {1 :number select=$bad}",
|
|
"params": [{ "name": "bad", "value": "exact" }],
|
|
"exp": "variable select 1",
|
|
"expErrors": [{ "type": "bad-option" }]
|
|
},
|
|
{
|
|
"description": "select=literal works",
|
|
"src": ".local $sel = {1 :number select=exact} .match $sel 1 {{literal select {$sel}}} * {{OTHER}}",
|
|
"exp": "literal select 1"
|
|
},
|
|
{
|
|
"description": "having select=literal as a selector operand is not allowed",
|
|
"src": ".local $sel = {1 :number select=exact} .local $bad = {$sel :number} .match $bad 1 {{ONE}} * {{operand select {$bad}}}",
|
|
"exp": "operand select 1",
|
|
"expErrors": [{ "type": "bad-option" }, { "type": "bad-selector" }]
|
|
},
|
|
{
|
|
"description": "with select=$var, * is always selected but its formatting is unaffected",
|
|
"src": ".local $sel = {1 :number select=$bad} .match $sel 1 {{ONE}} * {{variable select {$sel}}}",
|
|
"params": [{ "name": "bad", "value": "exact" }],
|
|
"exp": "variable select 1",
|
|
"expErrors": [{ "type": "bad-option" }, { "type": "bad-selector" }]
|
|
},
|
|
{
|
|
"src": "{42 :number @foo @bar=13}",
|
|
"exp": "42",
|
|
"expParts": [
|
|
{
|
|
"type": "number",
|
|
"source": "|42|",
|
|
"parts": [
|
|
{
|
|
"type": "integer",
|
|
"value": "42"
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|