summaryrefslogtreecommitdiffstats
path: root/intl/l10n/test/mochitest/localization/test_formatValues.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /intl/l10n/test/mochitest/localization/test_formatValues.html
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'intl/l10n/test/mochitest/localization/test_formatValues.html')
-rw-r--r--intl/l10n/test/mochitest/localization/test_formatValues.html85
1 files changed, 85 insertions, 0 deletions
diff --git a/intl/l10n/test/mochitest/localization/test_formatValues.html b/intl/l10n/test/mochitest/localization/test_formatValues.html
new file mode 100644
index 0000000000..819d418b2e
--- /dev/null
+++ b/intl/l10n/test/mochitest/localization/test_formatValues.html
@@ -0,0 +1,85 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Test Localization.prototype.formatValues API</title>
+ <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
+ <script type="application/javascript">
+ "use strict";
+ const mockSource = L10nFileSource.createMock("test", "app", ["en-US"], "/localization/{locale}/", [
+ {
+ path: "/localization/en-US/mock.ftl",
+ source: `
+key1 = Value
+key2 = Value { $user }
+key3 = Value { $count }
+`
+ }
+ ]);
+ let registry = new L10nRegistry({
+ bundleOptions: {
+ useIsolating: false
+ }
+ });
+ registry.registerSources([mockSource]);
+
+ (async () => {
+ SimpleTest.waitForExplicitFinish();
+
+ const loc = new Localization(
+ ['mock.ftl'],
+ false,
+ registry,
+ );
+
+ {
+ // Simple mix works.
+ let vals = await loc.formatValues([
+ {id: "key1"},
+ {id: "key2", args: { user: "Amy"}},
+ {id: "key3", args: { count: -32.12 }},
+ ]);
+ is(vals[0], "Value");
+ is(vals[1], "Value Amy");
+ is(vals[2], "Value -32.12");
+ }
+
+ {
+ // Missing arguments cause exception in automation.
+ try {
+ let vals = await loc.formatValues([
+ {id: "key1"},
+ {id: "key2"},
+ {id: "key3", args: { count: -32.12 }},
+ ]);
+ ok(false, "Missing argument didn't cause an exception.");
+ } catch (e) {
+ is(e.message,
+ "[fluent][resolver] errors in en-US/key2: Resolver error: Unknown variable: $user",
+ "Missing key causes an exception.");
+ }
+ }
+
+ {
+ // Missing keys cause exception in automation.
+ try {
+ let vals = await loc.formatValues([
+ { id: "key1" },
+ { id: "key4", args: { count: -32.12 } },
+ ]);
+ ok(false, "Missing key didn't cause an exception.");
+ } catch (e) {
+ is(e.message,
+ "[fluent] Missing message in locale en-US: key4",
+ "Missing key causes an exception.");
+ }
+ }
+
+ SimpleTest.finish();
+ })();
+ </script>
+</head>
+<body>
+</body>
+</html>