michael@0: /* Tests getting properties from string bundles michael@0: */ michael@0: michael@0: const name_file = "file"; michael@0: const value_file = "File"; michael@0: michael@0: const name_loyal = "loyal"; michael@0: const value_loyal = "\u5fe0\u5fc3"; // tests escaped Unicode michael@0: michael@0: const name_trout = "trout"; michael@0: const value_trout = "\u9cdf\u9b5a"; // tests UTF-8 michael@0: michael@0: const name_edit = "edit"; michael@0: const value_edit = "Edit"; // tests literal leading spaces are stripped michael@0: michael@0: const name_view = "view"; michael@0: const value_view = "View"; // tests literal trailing spaces are stripped michael@0: michael@0: const name_go = "go"; michael@0: const value_go = " Go"; // tests escaped leading spaces are not stripped michael@0: michael@0: const name_message = "message"; michael@0: const value_message = "Message "; // tests escaped trailing spaces are not stripped michael@0: michael@0: const name_hello = "hello"; michael@0: const var_hello = "World"; michael@0: const value_hello = "Hello World"; // tests formatStringFromName with parameter michael@0: michael@0: michael@0: function run_test() { michael@0: var StringBundle = michael@0: Components.classes["@mozilla.org/intl/stringbundle;1"] michael@0: .getService(Components.interfaces.nsIStringBundleService); michael@0: var ios = Components.classes["@mozilla.org/network/io-service;1"] michael@0: .getService(Components.interfaces.nsIIOService); michael@0: var bundleURI = ios.newFileURI(do_get_file("strres.properties")); michael@0: michael@0: var bundle = StringBundle.createBundle(bundleURI.spec); michael@0: michael@0: var bundle_file = bundle.GetStringFromName(name_file); michael@0: do_check_eq(bundle_file, value_file); michael@0: michael@0: var bundle_loyal = bundle.GetStringFromName(name_loyal); michael@0: do_check_eq(bundle_loyal, value_loyal); michael@0: michael@0: var bundle_trout = bundle.GetStringFromName(name_trout); michael@0: do_check_eq(bundle_trout, value_trout); michael@0: michael@0: var bundle_edit = bundle.GetStringFromName(name_edit); michael@0: do_check_eq(bundle_edit, value_edit); michael@0: michael@0: var bundle_view = bundle.GetStringFromName(name_view); michael@0: do_check_eq(bundle_view, value_view); michael@0: michael@0: var bundle_go = bundle.GetStringFromName(name_go); michael@0: do_check_eq(bundle_go, value_go); michael@0: michael@0: var bundle_message = bundle.GetStringFromName(name_message); michael@0: do_check_eq(bundle_message, value_message); michael@0: michael@0: var bundle_hello = bundle.formatStringFromName(name_hello, [var_hello], 1); michael@0: do_check_eq(bundle_hello, value_hello); michael@0: } michael@0: