Skip to content

Commit fee2242

Browse files
committed
Add test for custom selector; fix & enable custom SUM() test
1 parent c5c44b8 commit fee2242

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

fluent-bundle/test/functions_runtime_test.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import ftl from "@fluent/dedent";
55

66
import { FluentBundle } from "../esm/bundle.js";
77
import { FluentResource } from "../esm/resource.js";
8+
import { FluentNumber } from "../esm/types.js";
89

910
suite("Runtime-specific functions", function () {
1011
let bundle, args, errs;
@@ -19,13 +20,20 @@ suite("Runtime-specific functions", function () {
1920
useIsolating: false,
2021
functions: {
2122
CONCAT: (args, kwargs) => args.reduce((a, b) => `${a}${b}`, ""),
22-
SUM: (args, kwargs) => args.reduce((a, b) => a + b, 0),
23+
SUM: (args, kwargs) =>
24+
new FluentNumber(args.reduce((a, b) => a + b, 0)),
25+
PLATFORM: () => "windows",
2326
},
2427
});
2528
bundle.addResource(
2629
new FluentResource(ftl`
2730
foo = { CONCAT("Foo", "Bar") }
2831
bar = { SUM(1, 2) }
32+
pref =
33+
{ PLATFORM() ->
34+
[windows] Options
35+
*[other] Preferences
36+
}
2937
`)
3038
);
3139
});
@@ -37,9 +45,14 @@ suite("Runtime-specific functions", function () {
3745
assert.strictEqual(errs.length, 0);
3846
});
3947

40-
// XXX When they are passed as variables, convert JS types to FTL types
41-
// https://bugzil.la/1307116
42-
test.skip("works for numbers", function () {
48+
test("works for selectors", function () {
49+
const msg = bundle.getMessage("pref");
50+
const val = bundle.formatPattern(msg.value, args, errs);
51+
assert.strictEqual(val, "Options");
52+
assert.strictEqual(errs.length, 0);
53+
});
54+
55+
test("works for numbers", function () {
4356
const msg = bundle.getMessage("bar");
4457
const val = bundle.formatPattern(msg.value, args, errs);
4558
assert.strictEqual(val, "3");

0 commit comments

Comments
 (0)