Skip to content

Commit bf0a30f

Browse files
committed
Rename as test:func & test:select, add test:format
1 parent f0b7cf0 commit bf0a30f

File tree

1 file changed

+56
-44
lines changed

1 file changed

+56
-44
lines changed

test/README.md

Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -40,73 +40,85 @@ Some examples of test harnesses using these tests, from the source repository:
4040

4141
As the behaviour of `:number`, `:datetime`, and other default message functions
4242
is dependent on locale-specific data and may vary between implementations,
43-
the following functions are defined for test use only:
43+
the following functions are defined for **test use only**:
4444

45-
### `test:number`
45+
### `test:func`
4646

4747
This function is valid both as a selector and as a formatter.
48-
The only option it recognizes is `fractionDigits`,
48+
The only option it recognizes is `fd`,
4949
all other option values passed to it are ignored.
5050

51-
When resolving a `test:number` expression,
52-
its internal _input_ and _fractionDigits_ values are determined as follows:
53-
1. If the expression argument resolves to a numerical value
51+
When resolving a `test:func` expression,
52+
its _Input_ and _FD_ values are determined as follows:
53+
54+
1. Let _FD_ be `0`.
55+
1. Let _arg_ be the resolved value of the expression argument.
56+
1. If _arg_ is the resolved value of an expression
57+
with a `test:func`, `test:select`, or `test:format` annotation
58+
for which resolution has succeeded, then
59+
1. Let _Input_ be the _Input_ value of _arg_.
60+
1. Set _FD_ to be _FD_ value of _arg_.
61+
1. Else if _arg_ is a numerical value
5462
or a string matching the `number-literal` production, then
55-
1. Let _input_ be the numerical value of the argument.
56-
2. Else,
57-
1. Emit "bad-input" error.
58-
1. Use a fallback representation is used as the resolved value of the expression.
59-
The _fractionDigits_ value is not determined.
60-
3. If the `fractionDigits` option is set, then
61-
1. If its value resolves to a numerical integer value `0`, `1` or `2`,
62-
or their corresponding string representations `'0'`, `'1'`, or `'2'`, then
63-
1. Let _fractionDigits_ be the numerical value of the option.
64-
2. Else,
65-
1. Emit "bad-option" error.
66-
2. Let _fractionDigits_ be `0`.
67-
4. Else,
68-
1. Let _fractionDigits_ be `0`.
69-
70-
When `test:number` is used as a selector,
63+
1. Let _Input_ be the numerical value of _arg_.
64+
1. Else,
65+
1. Emit "bad-input" Resolution Error.
66+
1. Use a fallback representation as the resolved value of the expression.
67+
Further steps of this algorithm are not followed.
68+
1. If the `fd` option is set, then
69+
1. If its value resolves to a numerical integer value `0` or `1`
70+
or their corresponding string representations `'0'` or `'1'`, then
71+
1. Set _FD_ to be the numerical value of the option.
72+
1. Else if its value is not an unresolved value set by [Option Resolution](/spec/formatting.md#option-resolution),
73+
1. Emit "bad-option" Resolution Error.
74+
1. Use a fallback representation as the resolved value of the expression.
75+
76+
When `test:func` is used as a selector,
7177
the behaviour of calling it as the `rv` value of MatchSelectorKeys(`rv`, `keys`)
7278
(see [Resolve Preferences](/spec/formatting.md#resolve-preferences) for more information)
73-
depends on its _input_ and _fractionDigits_ values.
74-
- If the _input_ is `1` and _fractionDigits_ is `0`,
75-
the method will return some slice of the list « `'1'`, `'one'` »,
79+
depends on its _Input_ and _FD_ values.
80+
81+
- If the _Input_ is `1` and _FD_ is `1`,
82+
the method will return some slice of the list « `'1.0'`, `'1'` »,
7683
depending on whether those values are included in `keys`.
77-
- If the _input_ is `1` and _fractionDigits_ is not `0`,
84+
- If the _Input_ is `1` and _FD_ is `0`,
7885
the method will return the list « `'1'` » if `keys` includes `'1'`, or an empty list otherwise.
79-
- If the _input_ is any other value, the method will return an empty list.
86+
- If the _Input_ is any other value, the method will return an empty list.
8087

81-
When an expression with a `test:number` annotation is assigned to a variable by a declaration
82-
and that variable is used as an argument or option value,
83-
its resolved value is the _input_ value.
88+
When an expression with a `test:func` annotation is assigned to a variable by a declaration
89+
and that variable is used as an option value,
90+
its resolved value is the _Input_ value.
8491

85-
When `test:number` is used as a formatter,
86-
a placeholder resolving to a value with a `test:number` expression
92+
When `test:func` is used as a formatter,
93+
a placeholder resolving to a value with a `test:func` expression
8794
is formatted as a concatenation of the following parts:
88-
1. If _input_ is less than `0`, the character `-` U+002D Hyphen-Minus.
89-
2. The truncated absolute integer value of _input_, i.e. floor(abs(_input_)),
95+
96+
1. If _Input_ is less than `0`, the character `-` U+002D Hyphen-Minus.
97+
1. The truncated absolute integer value of _Input_, i.e. floor(abs(_Input_)),
9098
formatted as a sequence of decimal digit caharacters.
91-
3. If _fractionDigits_ is `1`, then
92-
1. The character `.` U+002E Full Stop.
93-
2. The single decimal digit character representing the value floor((abs(_input_) - floor(abs(_input_))) * 10)
94-
4. Else if _fractionDigits_ is `2`, then
99+
1. If _FD_ is `1`, then
95100
1. The character `.` U+002E Full Stop.
96-
2. The two decimal digit character string representing the value floor((abs(_input_) - floor(abs(_input_))) * 100),
97-
with a `0` U+0030 Digit Zero padding at start if the result is less than `10`.
101+
1. The single decimal digit character representing the value floor((abs(_Input_) - floor(abs(_Input_))) \* 10)
98102

99103
If the formatting target is a sequence of parts,
100104
each of the above parts will be emitted separately
101105
rather than being concatenated into a single string.
102106

103-
Note that for purposes of clarity, the formatting of `test:number` does not perform any rounding.
107+
Note that for purposes of clarity, the formatting of `test:func` does not perform any rounding.
104108

105-
### `test:plural`
109+
### `test:select`
106110

107-
This function behaves exactly the same as `test:number`,
111+
This function behaves exactly the same as `test:func`,
108112
except that it cannot be used for formatting.
109113

110-
When `test:plural` is used as a formatter,
114+
When `test:select` is used as a formatter,
111115
a "not-formattable" error is emitted and the placeholder is formatted with
112116
a fallback representation.
117+
118+
### `test:format`
119+
120+
This function behaves exactly the same as `test:func`,
121+
except that it cannot be used for selection.
122+
123+
When `test:format` is used as a selector,
124+
the steps under 2.iii. of [Resolve Selectors](/spec/formatting.md#resolve-selectors) are followed.

0 commit comments

Comments
 (0)