|
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 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 |
|
30 function run_test() { |
|
31 var StringBundle = |
|
32 Components.classes["@mozilla.org/intl/stringbundle;1"] |
|
33 .getService(Components.interfaces.nsIStringBundleService); |
|
34 var ios = Components.classes["@mozilla.org/network/io-service;1"] |
|
35 .getService(Components.interfaces.nsIIOService); |
|
36 var bundleURI = ios.newFileURI(do_get_file("strres.properties")); |
|
37 |
|
38 var bundle = StringBundle.createBundle(bundleURI.spec); |
|
39 |
|
40 var bundle_file = bundle.GetStringFromName(name_file); |
|
41 do_check_eq(bundle_file, value_file); |
|
42 |
|
43 var bundle_loyal = bundle.GetStringFromName(name_loyal); |
|
44 do_check_eq(bundle_loyal, value_loyal); |
|
45 |
|
46 var bundle_trout = bundle.GetStringFromName(name_trout); |
|
47 do_check_eq(bundle_trout, value_trout); |
|
48 |
|
49 var bundle_edit = bundle.GetStringFromName(name_edit); |
|
50 do_check_eq(bundle_edit, value_edit); |
|
51 |
|
52 var bundle_view = bundle.GetStringFromName(name_view); |
|
53 do_check_eq(bundle_view, value_view); |
|
54 |
|
55 var bundle_go = bundle.GetStringFromName(name_go); |
|
56 do_check_eq(bundle_go, value_go); |
|
57 |
|
58 var bundle_message = bundle.GetStringFromName(name_message); |
|
59 do_check_eq(bundle_message, value_message); |
|
60 |
|
61 var bundle_hello = bundle.formatStringFromName(name_hello, [var_hello], 1); |
|
62 do_check_eq(bundle_hello, value_hello); |
|
63 } |
|
64 |