test_messagecontext.js (1524B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 function run_test() { 5 test_methods_presence(FluentBundle); 6 test_methods_calling(FluentBundle, FluentResource); 7 test_number_options(FluentBundle, FluentResource); 8 9 ok(true); 10 } 11 12 function test_methods_presence(FluentBundle) { 13 const bundle = new FluentBundle(["en-US", "pl"]); 14 equal(typeof bundle.addResource, "function"); 15 equal(typeof bundle.formatPattern, "function"); 16 } 17 18 function test_methods_calling(FluentBundle, FluentResource) { 19 const bundle = new FluentBundle(["en-US", "pl"], { 20 useIsolating: false, 21 }); 22 bundle.addResource(new FluentResource("key = Value")); 23 24 const msg = bundle.getMessage("key"); 25 equal(bundle.formatPattern(msg.value), "Value"); 26 27 bundle.addResource(new FluentResource("key2 = Hello { $name }")); 28 29 const msg2 = bundle.getMessage("key2"); 30 equal(bundle.formatPattern(msg2.value, { name: "Amy" }), "Hello Amy"); 31 ok(true); 32 } 33 34 function test_number_options(FluentBundle, FluentResource) { 35 const bundle = new FluentBundle(["en-US", "pl"], { 36 useIsolating: false, 37 }); 38 bundle.addResource(new FluentResource(` 39 key = { NUMBER(0.53, style: "percent") } { NUMBER(0.12, style: "percent", minimumFractionDigits: 0) } 40 { NUMBER(-2.5, style: "percent") } { NUMBER(2.91, style: "percent") } { NUMBER("wrong", style: "percent") } 41 `)); 42 43 const msg = bundle.getMessage("key"); 44 equal(bundle.formatPattern(msg.value), "53.00% 12%\n-250.0% 291.00% "); 45 46 ok(true); 47 }