test_bug378839.js (1852B)
1 /* Tests getting properties from string bundles 2 */ 3 4 const name_file = "file"; 5 const value_file = "File"; 6 7 const name_loyal = "loyal"; 8 const value_loyal = "\u5fe0\u5fc3"; // tests escaped Unicode 9 10 const name_trout = "trout"; 11 const value_trout = "\u9cdf\u9b5a"; // tests UTF-8 12 13 const name_edit = "edit"; 14 const value_edit = "Edit"; // tests literal leading spaces are stripped 15 16 const name_view = "view"; 17 const value_view = "View "; // tests literal trailing spaces are not stripped 18 19 const name_go = "go"; 20 const value_go = " Go"; // tests escaped leading spaces are not stripped 21 22 const name_message = "message"; 23 const value_message = "Message "; // tests escaped trailing spaces are not stripped 24 25 const name_hello = "hello"; 26 const var_hello = "World"; 27 const value_hello = "Hello World"; // tests formatStringFromName with parameter 28 29 function run_test() { 30 var StringBundle = Services.strings; 31 var bundleURI = Services.io.newFileURI(do_get_file("strres.properties")); 32 33 var bundle = StringBundle.createBundle(bundleURI.spec); 34 35 var bundle_file = bundle.GetStringFromName(name_file); 36 Assert.equal(bundle_file, value_file); 37 38 var bundle_loyal = bundle.GetStringFromName(name_loyal); 39 Assert.equal(bundle_loyal, value_loyal); 40 41 var bundle_trout = bundle.GetStringFromName(name_trout); 42 Assert.equal(bundle_trout, value_trout); 43 44 var bundle_edit = bundle.GetStringFromName(name_edit); 45 Assert.equal(bundle_edit, value_edit); 46 47 var bundle_view = bundle.GetStringFromName(name_view); 48 Assert.equal(bundle_view, value_view); 49 50 var bundle_go = bundle.GetStringFromName(name_go); 51 Assert.equal(bundle_go, value_go); 52 53 var bundle_message = bundle.GetStringFromName(name_message); 54 Assert.equal(bundle_message, value_message); 55 56 var bundle_hello = bundle.formatStringFromName(name_hello, [var_hello]); 57 Assert.equal(bundle_hello, value_hello); 58 }