Skip to content

Commit

Permalink
Add test for custom selector; fix & enable custom SUM() test
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed Apr 3, 2024
1 parent c5c44b8 commit fee2242
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions fluent-bundle/test/functions_runtime_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ftl from "@fluent/dedent";

import { FluentBundle } from "../esm/bundle.js";
import { FluentResource } from "../esm/resource.js";
import { FluentNumber } from "../esm/types.js";

suite("Runtime-specific functions", function () {
let bundle, args, errs;
Expand All @@ -19,13 +20,20 @@ suite("Runtime-specific functions", function () {
useIsolating: false,
functions: {
CONCAT: (args, kwargs) => args.reduce((a, b) => `${a}${b}`, ""),
SUM: (args, kwargs) => args.reduce((a, b) => a + b, 0),
SUM: (args, kwargs) =>
new FluentNumber(args.reduce((a, b) => a + b, 0)),
PLATFORM: () => "windows",
},
});
bundle.addResource(
new FluentResource(ftl`
foo = { CONCAT("Foo", "Bar") }
bar = { SUM(1, 2) }
pref =
{ PLATFORM() ->
[windows] Options
*[other] Preferences
}
`)
);
});
Expand All @@ -37,9 +45,14 @@ suite("Runtime-specific functions", function () {
assert.strictEqual(errs.length, 0);
});

// XXX When they are passed as variables, convert JS types to FTL types
// https://bugzil.la/1307116
test.skip("works for numbers", function () {
test("works for selectors", function () {
const msg = bundle.getMessage("pref");
const val = bundle.formatPattern(msg.value, args, errs);
assert.strictEqual(val, "Options");
assert.strictEqual(errs.length, 0);
});

test("works for numbers", function () {
const msg = bundle.getMessage("bar");
const val = bundle.formatPattern(msg.value, args, errs);
assert.strictEqual(val, "3");
Expand Down

0 comments on commit fee2242

Please sign in to comment.