test_hunspell.js (6941B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ 3 */ 4 5 const tests = [ 6 ["affixes", "iso-8859-1"], 7 ["condition", "iso-8859-1"], 8 ["condition-utf", "UTF-8"], 9 ["base", "iso-8859-1"], 10 ["base-utf", "UTF-8"], 11 ["allcaps", "iso-8859-1"], 12 ["allcaps-utf", "UTF-8"], 13 ["allcaps2", "iso-8859-1"], 14 ["allcaps3", "iso-8859-1"], 15 ["keepcase", "iso-8859-1"], 16 ["i58202", "iso-8859-1"], 17 ["map", "iso-8859-1"], 18 ["rep", "iso-8859-1"], 19 ["sug", "iso-8859-1"], 20 ["sugutf", "UTF-8"], 21 ["phone", "iso-8859-1"], 22 ["flag", "iso-8859-1"], 23 ["flaglong", "iso-8859-1"], 24 ["flagnum", "iso-8859-1"], 25 ["flagutf8", "UTF-8"], 26 ["slash", "iso-8859-1"], 27 ["forbiddenword", "iso-8859-1"], 28 ["nosuggest", "iso-8859-1"], 29 ["alias", "iso-8859-1"], 30 ["alias2", "iso-8859-1"], 31 ["alias3", "iso-8859-1"], 32 ["breakdefault", "iso-8859-1"], 33 ["break", "UTF-8"], 34 ["needaffix", "iso-8859-1"], 35 ["needaffix2", "iso-8859-1"], 36 ["needaffix3", "iso-8859-1"], 37 ["needaffix4", "iso-8859-1"], 38 ["needaffix5", "iso-8859-1"], 39 ["circumfix", "iso-8859-1"], 40 ["fogemorpheme", "iso-8859-1"], 41 ["onlyincompound", "iso-8859-1"], 42 ["complexprefixes", "iso-8859-1"], 43 ["complexprefixes2", "iso-8859-1"], 44 ["complexprefixesutf", "UTF-8"], 45 ["conditionalprefix", "iso-8859-1"], 46 ["zeroaffix", "iso-8859-1"], 47 ["utf8", "UTF-8"], 48 ["utf8-bom", "UTF-8", { 1: "todo" }], 49 ["utf8-bom2", "UTF-8", { 1: "todo" }], 50 ["utf8-nonbmp", "UTF-8", { 1: "todo", 2: "todo", 3: "todo", 4: "todo" }], 51 ["compoundflag", "iso-8859-1"], 52 ["compoundrule", "iso-8859-1"], 53 ["compoundrule2", "iso-8859-1"], 54 ["compoundrule3", "iso-8859-1"], 55 ["compoundrule4", "iso-8859-1"], 56 ["compoundrule5", "UTF-8"], 57 ["compoundrule6", "iso-8859-1"], 58 ["compoundrule7", "iso-8859-1"], 59 ["compoundrule8", "iso-8859-1"], 60 ["compoundaffix", "iso-8859-1"], 61 ["compoundaffix2", "iso-8859-1"], 62 ["compoundaffix3", "iso-8859-1"], 63 ["checkcompounddup", "iso-8859-1"], 64 ["checkcompoundtriple", "iso-8859-1"], 65 ["simplifiedtriple", "iso-8859-1"], 66 ["checkcompoundrep", "iso-8859-1"], 67 ["checkcompoundcase2", "iso-8859-1"], 68 ["checkcompoundcaseutf", "UTF-8"], 69 ["checkcompoundpattern", "iso-8859-1"], 70 ["checkcompoundpattern2", "iso-8859-1"], 71 ["checkcompoundpattern3", "iso-8859-1"], 72 ["checkcompoundpattern4", "iso-8859-1"], 73 ["utfcompound", "UTF-8"], 74 ["checksharps", "iso-8859-1"], 75 ["checksharpsutf", "UTF-8"], 76 ["germancompounding", "iso-8859-1"], 77 ["germancompoundingold", "iso-8859-1"], 78 ["i35725", "iso-8859-1"], 79 ["i53643", "iso-8859-1"], 80 ["i54633", "iso-8859-1"], 81 ["i54980", "iso-8859-1", { 1: "todo", 3: "todo" }], 82 ["maputf", "UTF-8"], 83 ["reputf", "UTF-8"], 84 ["ignore", "iso-8859-1"], 85 [ 86 "ignoreutf", 87 "UTF-8", 88 { 89 1: "todo", 90 2: "todo", 91 3: "todo", 92 4: "todo", 93 5: "todo", 94 6: "todo", 95 7: "todo", 96 8: "todo", 97 }, 98 ], 99 ["1592880", "iso-8859-1"], 100 ["1695964", "iso-8859-1"], 101 ["1463589", "iso-8859-1"], 102 ["1463589-utf", "UTF-8"], 103 ["IJ", "iso-8859-1"], 104 ["i68568", "iso-8859-1"], 105 ["i68568utf", "UTF-8"], 106 ["1706659", "iso-8859-1"], 107 ["digits-in-words", "iso-8859-1"], 108 // ["colons-in-words", "iso-8859-1"], Suggestion test only 109 ["ngram-utf-fix", "UTF-8"], 110 [ 111 "morph", 112 "us-ascii", 113 { 114 11: "todo", 115 12: "todo", 116 13: "todo", 117 14: "todo", 118 15: "todo", 119 16: "todo", 120 17: "todo", 121 18: "todo", 122 19: "todo", 123 20: "todo", 124 21: "todo", 125 22: "todo", 126 23: "todo", 127 24: "todo", 128 25: "todo", 129 26: "todo", 130 27: "todo", 131 }, 132 ], 133 ["1975530", "UTF-8"], 134 ["fullstrip", "iso-8859-1"], 135 ["iconv", "UTF-8"], 136 ["oconv", "UTF-8"], 137 ["encoding", "iso-8859-1", { 1: "todo", 3: "todo" }], 138 ["korean", "UTF-8"], 139 ["opentaal-forbiddenword1", "UTF-8"], 140 ["opentaal-forbiddenword2", "UTF-8"], 141 ["opentaal-keepcase", "UTF-8"], 142 ["arabic", "UTF-8"], 143 ["2970240", "iso-8859-1"], 144 ["2970242", "iso-8859-1"], 145 ["breakoff", "iso-8859-1"], 146 ["opentaal-cpdpat", "iso-8859-1"], 147 ["opentaal-cpdpat2", "iso-8859-1"], 148 ["2999225", "iso-8859-1"], 149 ["onlyincompound2", "iso-8859-1"], 150 ["forceucase", "iso-8859-1"], 151 ["warn", "iso-8859-1"], 152 ]; 153 154 // eslint-disable-next-line no-shadow 155 function* do_get_file_by_line(file, charset) { 156 dump("getting file by line for file " + file.path + "\n"); 157 dump("using charset1" + charset + "\n"); 158 let fis = Cc["@mozilla.org/network/file-input-stream;1"].createInstance( 159 Ci.nsIFileInputStream 160 ); 161 fis.init(file, 0x1 /* READONLY */, 0o444, Ci.nsIFileInputStream.CLOSE_ON_EOF); 162 163 let lis = Cc["@mozilla.org/intl/converter-input-stream;1"].createInstance( 164 Ci.nsIConverterInputStream 165 ); 166 lis.init(fis, charset, 1024, 0); 167 lis.QueryInterface(Ci.nsIUnicharLineInputStream); 168 169 let val = {}; 170 while (lis.readLine(val)) { 171 yield val.value; 172 val = {}; 173 } 174 } 175 176 function do_run_test(checker, name, charset, todo_good, todo_bad) { 177 dump("\n\n\n\n"); 178 dump("running test for " + name + "\n"); 179 if (!checker) { 180 do_throw("Need spell checker here!"); 181 } 182 183 let good = do_get_file("data/" + name + ".good", true); 184 let bad = do_get_file("data/" + name + ".wrong", true); 185 let sug = do_get_file("data/" + name + ".sug", true); 186 187 dump("Need some expected output\n"); 188 Assert.ok(good.exists() || bad.exists() || sug.exists()); 189 190 dump("Setting dictionary to " + name + "\n"); 191 checker.dictionaries = [name]; 192 193 if (good.exists()) { 194 var good_counter = 0; 195 for (const val of do_get_file_by_line(good, charset)) { 196 let todo = false; 197 good_counter++; 198 if (todo_good && todo_good[good_counter]) { 199 todo = true; 200 dump("TODO\n"); 201 } 202 203 dump("Expect word " + val + " is spelled correctly\n"); 204 if (todo) { 205 todo_check_true(checker.check(val)); 206 } else { 207 Assert.ok(checker.check(val)); 208 } 209 } 210 } 211 212 if (bad.exists()) { 213 var bad_counter = 0; 214 for (const val of do_get_file_by_line(bad, charset)) { 215 let todo = false; 216 bad_counter++; 217 if (todo_bad && todo_bad[bad_counter]) { 218 todo = true; 219 dump("TODO\n"); 220 } 221 222 dump("Expect word " + val + " is spelled wrong\n"); 223 if (todo) { 224 todo_check_false(checker.check(val)); 225 } else { 226 Assert.ok(!checker.check(val)); 227 } 228 } 229 } 230 231 // XXXkhuey test suggestions 232 } 233 234 function run_test() { 235 let spellChecker = Cc["@mozilla.org/spellchecker/engine;1"].getService( 236 Ci.mozISpellCheckingEngine 237 ); 238 239 Assert.ok(!!spellChecker, "Should have a spell checker"); 240 spellChecker.QueryInterface(Ci.mozISpellCheckingEngine); 241 let testdir = do_get_file("data/", false); 242 spellChecker.loadDictionariesFromDir(testdir); 243 244 function do_run_test_closure(test) { 245 let [name, charset, todo_good, todo_bad] = test; 246 do_run_test(spellChecker, name, charset, todo_good, todo_bad); 247 } 248 249 tests.forEach(do_run_test_closure); 250 }