intl/strres/tests/unit/test_bug378839.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/strres/tests/unit/test_bug378839.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,64 @@
     1.4 +/* Tests getting properties from string bundles
     1.5 + */
     1.6 +
     1.7 +const name_file = "file";
     1.8 +const value_file = "File";
     1.9 +
    1.10 +const name_loyal = "loyal";
    1.11 +const value_loyal = "\u5fe0\u5fc3"; // tests escaped Unicode
    1.12 +
    1.13 +const name_trout = "trout";
    1.14 +const value_trout = "\u9cdf\u9b5a"; // tests UTF-8
    1.15 +
    1.16 +const name_edit = "edit";
    1.17 +const value_edit = "Edit"; // tests literal leading spaces are stripped
    1.18 +
    1.19 +const name_view = "view";
    1.20 +const value_view = "View"; // tests literal trailing spaces are stripped
    1.21 +
    1.22 +const name_go = "go";
    1.23 +const value_go = " Go"; // tests escaped leading spaces are not stripped
    1.24 +
    1.25 +const name_message = "message";
    1.26 +const value_message = "Message "; // tests escaped trailing spaces are not stripped
    1.27 +
    1.28 +const name_hello = "hello";
    1.29 +const var_hello = "World";
    1.30 +const value_hello = "Hello World"; // tests formatStringFromName with parameter
    1.31 +
    1.32 +
    1.33 +function run_test() {
    1.34 +    var StringBundle = 
    1.35 +	Components.classes["@mozilla.org/intl/stringbundle;1"]
    1.36 +	 .getService(Components.interfaces.nsIStringBundleService);
    1.37 +    var ios = Components.classes["@mozilla.org/network/io-service;1"]
    1.38 +	 .getService(Components.interfaces.nsIIOService);
    1.39 +    var bundleURI = ios.newFileURI(do_get_file("strres.properties"));
    1.40 +
    1.41 +    var bundle = StringBundle.createBundle(bundleURI.spec);
    1.42 +
    1.43 +    var bundle_file = bundle.GetStringFromName(name_file);
    1.44 +    do_check_eq(bundle_file, value_file);
    1.45 +
    1.46 +    var bundle_loyal = bundle.GetStringFromName(name_loyal);
    1.47 +    do_check_eq(bundle_loyal, value_loyal);
    1.48 +
    1.49 +    var bundle_trout = bundle.GetStringFromName(name_trout);
    1.50 +    do_check_eq(bundle_trout, value_trout);
    1.51 +
    1.52 +    var bundle_edit = bundle.GetStringFromName(name_edit);
    1.53 +    do_check_eq(bundle_edit, value_edit);
    1.54 +
    1.55 +    var bundle_view = bundle.GetStringFromName(name_view);
    1.56 +    do_check_eq(bundle_view, value_view);
    1.57 +
    1.58 +    var bundle_go = bundle.GetStringFromName(name_go);
    1.59 +    do_check_eq(bundle_go, value_go);
    1.60 +
    1.61 +    var bundle_message = bundle.GetStringFromName(name_message);
    1.62 +    do_check_eq(bundle_message, value_message);
    1.63 +
    1.64 +    var bundle_hello = bundle.formatStringFromName(name_hello, [var_hello], 1);
    1.65 +    do_check_eq(bundle_hello, value_hello);
    1.66 +}
    1.67 +    

mercurial