Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/
3 */
5 const Cc = Components.classes;
6 const Ci = Components.interfaces;
8 const tests = [
9 ["affixes", "iso-8859-1"],
10 ["condition", "iso-8859-1"],
11 ["condition_utf", "UTF-8"],
12 ["base", "iso-8859-1"],
13 ["base_utf", "UTF-8"],
14 ["allcaps", "iso-8859-1"],
15 ["allcaps_utf", "UTF-8"],
16 ["allcaps2", "iso-8859-1"],
17 ["allcaps3", "iso-8859-1"],
18 ["keepcase", "iso-8859-1"],
19 ["i58202", "iso-8859-1"],
20 ["map", "iso-8859-1"],
21 ["rep", "iso-8859-1"],
22 ["sug", "iso-8859-1"],
23 ["sugutf", "UTF-8"],
24 ["phone", "iso-8859-1"],
25 ["flag", "iso-8859-1"],
26 ["flaglong", "iso-8859-1"],
27 ["flagnum", "iso-8859-1"],
28 ["flagutf8", "UTF-8"],
29 ["slash", "iso-8859-1"],
30 ["forbiddenword", "iso-8859-1"],
31 ["nosuggest", "iso-8859-1"],
32 ["alias", "iso-8859-1"],
33 ["alias2", "iso-8859-1"],
34 ["alias3", "iso-8859-1"],
35 ["breakdefault", "iso-8859-1"],
36 ["break", "UTF-8"],
37 ["needaffix", "iso-8859-1"],
38 ["needaffix2", "iso-8859-1"],
39 ["needaffix3", "iso-8859-1"],
40 ["needaffix4", "iso-8859-1"],
41 ["needaffix5", "iso-8859-1"],
42 ["circumfix", "iso-8859-1"],
43 ["fogemorpheme", "iso-8859-1"],
44 ["onlyincompound", "iso-8859-1"],
45 ["complexprefixes", "iso-8859-1"],
46 ["complexprefixes2", "iso-8859-1"],
47 ["complexprefixesutf", "UTF-8"],
48 ["conditionalprefix", "iso-8859-1"],
49 ["zeroaffix", "iso-8859-1"],
50 ["utf8", "UTF-8"],
51 ["utf8_bom", "UTF-8", {1: "todo"}],
52 ["utf8_bom2", "UTF-8", {1: "todo"}],
53 ["utf8_nonbmp", "UTF-8", {1: "todo", 2: "todo", 3: "todo", 4: "todo"}],
54 ["compoundflag", "iso-8859-1"],
55 ["compoundrule", "iso-8859-1"],
56 ["compoundrule2", "iso-8859-1"],
57 ["compoundrule3", "iso-8859-1"],
58 ["compoundrule4", "iso-8859-1"],
59 ["compoundrule5", "UTF-8"],
60 ["compoundrule6", "iso-8859-1"],
61 ["compoundrule7", "iso-8859-1"],
62 ["compoundrule8", "iso-8859-1"],
63 ["compoundaffix", "iso-8859-1"],
64 ["compoundaffix2", "iso-8859-1"],
65 ["compoundaffix3", "iso-8859-1"],
66 ["checkcompounddup", "iso-8859-1"],
67 ["checkcompoundtriple", "iso-8859-1"],
68 ["simplifiedtriple", "iso-8859-1"],
69 ["checkcompoundrep", "iso-8859-1"],
70 ["checkcompoundcase2", "iso-8859-1"],
71 ["checkcompoundcaseutf", "UTF-8"],
72 ["checkcompoundpattern", "iso-8859-1"],
73 ["checkcompoundpattern2", "iso-8859-1"],
74 ["checkcompoundpattern3", "iso-8859-1"],
75 ["checkcompoundpattern4", "iso-8859-1"],
76 ["utfcompound", "UTF-8"],
77 ["checksharps", "iso-8859-1"],
78 ["checksharpsutf", "UTF-8"],
79 ["germancompounding", "iso-8859-1"],
80 ["germancompoundingold", "iso-8859-1"],
81 ["i35725", "iso-8859-1"],
82 ["i53643", "iso-8859-1"],
83 ["i54633", "iso-8859-1"],
84 ["i54980", "iso-8859-1", {1: "todo", 3: "todo"}],
85 ["maputf", "UTF-8"],
86 ["reputf", "UTF-8"],
87 ["ignore", "iso-8859-1"],
88 ["ignoreutf", "UTF-8",
89 {1: "todo", 2: "todo", 3: "todo", 4: "todo", 5: "todo", 6: "todo",
90 7: "todo", 8: "todo"}],
91 ["1592880", "iso-8859-1"],
92 ["1695964", "iso-8859-1"],
93 ["1463589", "iso-8859-1"],
94 ["1463589_utf", "UTF-8"],
95 ["IJ", "iso-8859-1"],
96 ["i68568", "iso-8859-1"],
97 ["i68568utf", "UTF-8"],
98 ["1706659", "iso-8859-1"],
99 ["digits_in_words", "iso-8859-1"],
100 // ["colons_in_words", "iso-8859-1"], Suggestion test only
101 ["ngram_utf_fix", "UTF-8"],
102 ["morph", "us-ascii",
103 {11: "todo", 12: "todo", 13: "todo", 14: "todo", 15: "todo", 16: "todo",
104 17: "todo", 18: "todo", 19: "todo", 20: "todo", 21: "todo", 22: "todo",
105 23: "todo", 24: "todo", 25: "todo", 26: "todo", 27: "todo"}],
106 ["1975530", "UTF-8"],
107 ["fullstrip", "iso-8859-1"],
108 ["iconv", "UTF-8"],
109 ["oconv", "UTF-8"],
110 ["encoding", "iso-8859-1", {1: "todo", 3: "todo"}],
111 ["korean", "UTF-8"],
112 ["opentaal_forbiddenword1", "UTF-8"],
113 ["opentaal_forbiddenword2", "UTF-8"],
114 ["opentaal_keepcase", "UTF-8"],
115 ["arabic", "UTF-8"],
116 ["2970240", "iso-8859-1"],
117 ["2970242", "iso-8859-1"],
118 ["breakoff", "iso-8859-1"],
119 ["opentaal_cpdpat", "iso-8859-1"],
120 ["opentaal_cpdpat2", "iso-8859-1"],
121 ["2999225", "iso-8859-1"],
122 ["onlyincompound2", "iso-8859-1"],
123 ["forceucase", "iso-8859-1"],
124 ["warn", "iso-8859-1"]
125 ];
127 function do_get_file_by_line(file, charset) {
128 dump("getting file by line for file " + file.path + "\n");
129 dump("using charset " + charset +"\n");
130 let fis = Cc["@mozilla.org/network/file-input-stream;1"].
131 createInstance(Ci.nsIFileInputStream);
132 fis.init(file, 0x1 /* READONLY */,
133 0444, Ci.nsIFileInputStream.CLOSE_ON_EOF);
135 let lis = Cc["@mozilla.org/intl/converter-input-stream;1"].
136 createInstance(Ci.nsIConverterInputStream);
137 lis.init(fis, charset, 1024, 0);
138 lis.QueryInterface(Ci.nsIUnicharLineInputStream);
140 var val = {};
141 while (lis.readLine(val)) {
142 yield val.value;
143 val = {};
144 }
145 }
147 function do_run_test(checker, name, charset, todo_good, todo_bad) {
148 dump("\n\n\n\n");
149 dump("running test for " + name + "\n");
150 if (!checker) {
151 do_throw("Need spell checker here!");
152 }
154 let good = do_get_file("data/" + name + ".good", true);
155 let bad = do_get_file("data/" + name + ".wrong", true);
156 let sug = do_get_file("data/" + name + ".sug", true);
158 dump("Need some expected output\n")
159 do_check_true(good.exists() || bad.exists() || sug.exists());
161 dump("Setting dictionary to " + name + "\n");
162 checker.dictionary = name;
164 if (good.exists()) {
165 var good_counter = 0;
166 for (val in do_get_file_by_line(good, charset)) {
167 let todo = false;
168 good_counter++;
169 if (todo_good && todo_good[good_counter]) {
170 todo = true;
171 dump("TODO\n");
172 }
174 dump("Expect word " + val + " is spelled correctly\n");
175 if (todo) {
176 todo_check_true(checker.check(val));
177 } else {
178 do_check_true(checker.check(val));
179 }
180 }
181 }
183 if (bad.exists()) {
184 var bad_counter = 0;
185 for (val in do_get_file_by_line(bad, charset)) {
186 let todo = false;
187 bad_counter++;
188 if (todo_bad && todo_bad[bad_counter]) {
189 todo = true;
190 dump("TODO\n");
191 }
193 dump("Expect word " + val + " is spelled wrong\n");
194 if (todo) {
195 todo_check_false(checker.check(val));
196 } else {
197 do_check_false(checker.check(val));
198 }
199 }
200 }
202 // XXXkhuey test suggestions
203 }
205 function run_test() {
206 let spellChecker = Cc["@mozilla.org/spellchecker/engine;1"].
207 getService(Ci.mozISpellCheckingEngine);
209 do_check_true(!!spellChecker, "Should have a spell checker");
210 spellChecker.QueryInterface(Ci.mozISpellCheckingEngine);
211 let testdir = do_get_file("data/", false);
212 spellChecker.loadDictionariesFromDir(testdir);
214 function do_run_test_closure(test) {
215 [name, charset, todo_good, todo_bad] = test;
216 do_run_test(spellChecker, name, charset, todo_good, todo_bad);
217 }
219 tests.forEach(do_run_test_closure);
220 }