Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* Tests getting properties from string bundles |
michael@0 | 2 | */ |
michael@0 | 3 | |
michael@0 | 4 | const name_file = "file"; |
michael@0 | 5 | const value_file = "File"; |
michael@0 | 6 | |
michael@0 | 7 | const name_loyal = "loyal"; |
michael@0 | 8 | const value_loyal = "\u5fe0\u5fc3"; // tests escaped Unicode |
michael@0 | 9 | |
michael@0 | 10 | const name_trout = "trout"; |
michael@0 | 11 | const value_trout = "\u9cdf\u9b5a"; // tests UTF-8 |
michael@0 | 12 | |
michael@0 | 13 | const name_edit = "edit"; |
michael@0 | 14 | const value_edit = "Edit"; // tests literal leading spaces are stripped |
michael@0 | 15 | |
michael@0 | 16 | const name_view = "view"; |
michael@0 | 17 | const value_view = "View"; // tests literal trailing spaces are stripped |
michael@0 | 18 | |
michael@0 | 19 | const name_go = "go"; |
michael@0 | 20 | const value_go = " Go"; // tests escaped leading spaces are not stripped |
michael@0 | 21 | |
michael@0 | 22 | const name_message = "message"; |
michael@0 | 23 | const value_message = "Message "; // tests escaped trailing spaces are not stripped |
michael@0 | 24 | |
michael@0 | 25 | const name_hello = "hello"; |
michael@0 | 26 | const var_hello = "World"; |
michael@0 | 27 | const value_hello = "Hello World"; // tests formatStringFromName with parameter |
michael@0 | 28 | |
michael@0 | 29 | |
michael@0 | 30 | function run_test() { |
michael@0 | 31 | var StringBundle = |
michael@0 | 32 | Components.classes["@mozilla.org/intl/stringbundle;1"] |
michael@0 | 33 | .getService(Components.interfaces.nsIStringBundleService); |
michael@0 | 34 | var ios = Components.classes["@mozilla.org/network/io-service;1"] |
michael@0 | 35 | .getService(Components.interfaces.nsIIOService); |
michael@0 | 36 | var bundleURI = ios.newFileURI(do_get_file("strres.properties")); |
michael@0 | 37 | |
michael@0 | 38 | var bundle = StringBundle.createBundle(bundleURI.spec); |
michael@0 | 39 | |
michael@0 | 40 | var bundle_file = bundle.GetStringFromName(name_file); |
michael@0 | 41 | do_check_eq(bundle_file, value_file); |
michael@0 | 42 | |
michael@0 | 43 | var bundle_loyal = bundle.GetStringFromName(name_loyal); |
michael@0 | 44 | do_check_eq(bundle_loyal, value_loyal); |
michael@0 | 45 | |
michael@0 | 46 | var bundle_trout = bundle.GetStringFromName(name_trout); |
michael@0 | 47 | do_check_eq(bundle_trout, value_trout); |
michael@0 | 48 | |
michael@0 | 49 | var bundle_edit = bundle.GetStringFromName(name_edit); |
michael@0 | 50 | do_check_eq(bundle_edit, value_edit); |
michael@0 | 51 | |
michael@0 | 52 | var bundle_view = bundle.GetStringFromName(name_view); |
michael@0 | 53 | do_check_eq(bundle_view, value_view); |
michael@0 | 54 | |
michael@0 | 55 | var bundle_go = bundle.GetStringFromName(name_go); |
michael@0 | 56 | do_check_eq(bundle_go, value_go); |
michael@0 | 57 | |
michael@0 | 58 | var bundle_message = bundle.GetStringFromName(name_message); |
michael@0 | 59 | do_check_eq(bundle_message, value_message); |
michael@0 | 60 | |
michael@0 | 61 | var bundle_hello = bundle.formatStringFromName(name_hello, [var_hello], 1); |
michael@0 | 62 | do_check_eq(bundle_hello, value_hello); |
michael@0 | 63 | } |
michael@0 | 64 |