michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: michael@0: const tests = [ michael@0: ["affixes", "iso-8859-1"], michael@0: ["condition", "iso-8859-1"], michael@0: ["condition_utf", "UTF-8"], michael@0: ["base", "iso-8859-1"], michael@0: ["base_utf", "UTF-8"], michael@0: ["allcaps", "iso-8859-1"], michael@0: ["allcaps_utf", "UTF-8"], michael@0: ["allcaps2", "iso-8859-1"], michael@0: ["allcaps3", "iso-8859-1"], michael@0: ["keepcase", "iso-8859-1"], michael@0: ["i58202", "iso-8859-1"], michael@0: ["map", "iso-8859-1"], michael@0: ["rep", "iso-8859-1"], michael@0: ["sug", "iso-8859-1"], michael@0: ["sugutf", "UTF-8"], michael@0: ["phone", "iso-8859-1"], michael@0: ["flag", "iso-8859-1"], michael@0: ["flaglong", "iso-8859-1"], michael@0: ["flagnum", "iso-8859-1"], michael@0: ["flagutf8", "UTF-8"], michael@0: ["slash", "iso-8859-1"], michael@0: ["forbiddenword", "iso-8859-1"], michael@0: ["nosuggest", "iso-8859-1"], michael@0: ["alias", "iso-8859-1"], michael@0: ["alias2", "iso-8859-1"], michael@0: ["alias3", "iso-8859-1"], michael@0: ["breakdefault", "iso-8859-1"], michael@0: ["break", "UTF-8"], michael@0: ["needaffix", "iso-8859-1"], michael@0: ["needaffix2", "iso-8859-1"], michael@0: ["needaffix3", "iso-8859-1"], michael@0: ["needaffix4", "iso-8859-1"], michael@0: ["needaffix5", "iso-8859-1"], michael@0: ["circumfix", "iso-8859-1"], michael@0: ["fogemorpheme", "iso-8859-1"], michael@0: ["onlyincompound", "iso-8859-1"], michael@0: ["complexprefixes", "iso-8859-1"], michael@0: ["complexprefixes2", "iso-8859-1"], michael@0: ["complexprefixesutf", "UTF-8"], michael@0: ["conditionalprefix", "iso-8859-1"], michael@0: ["zeroaffix", "iso-8859-1"], michael@0: ["utf8", "UTF-8"], michael@0: ["utf8_bom", "UTF-8", {1: "todo"}], michael@0: ["utf8_bom2", "UTF-8", {1: "todo"}], michael@0: ["utf8_nonbmp", "UTF-8", {1: "todo", 2: "todo", 3: "todo", 4: "todo"}], michael@0: ["compoundflag", "iso-8859-1"], michael@0: ["compoundrule", "iso-8859-1"], michael@0: ["compoundrule2", "iso-8859-1"], michael@0: ["compoundrule3", "iso-8859-1"], michael@0: ["compoundrule4", "iso-8859-1"], michael@0: ["compoundrule5", "UTF-8"], michael@0: ["compoundrule6", "iso-8859-1"], michael@0: ["compoundrule7", "iso-8859-1"], michael@0: ["compoundrule8", "iso-8859-1"], michael@0: ["compoundaffix", "iso-8859-1"], michael@0: ["compoundaffix2", "iso-8859-1"], michael@0: ["compoundaffix3", "iso-8859-1"], michael@0: ["checkcompounddup", "iso-8859-1"], michael@0: ["checkcompoundtriple", "iso-8859-1"], michael@0: ["simplifiedtriple", "iso-8859-1"], michael@0: ["checkcompoundrep", "iso-8859-1"], michael@0: ["checkcompoundcase2", "iso-8859-1"], michael@0: ["checkcompoundcaseutf", "UTF-8"], michael@0: ["checkcompoundpattern", "iso-8859-1"], michael@0: ["checkcompoundpattern2", "iso-8859-1"], michael@0: ["checkcompoundpattern3", "iso-8859-1"], michael@0: ["checkcompoundpattern4", "iso-8859-1"], michael@0: ["utfcompound", "UTF-8"], michael@0: ["checksharps", "iso-8859-1"], michael@0: ["checksharpsutf", "UTF-8"], michael@0: ["germancompounding", "iso-8859-1"], michael@0: ["germancompoundingold", "iso-8859-1"], michael@0: ["i35725", "iso-8859-1"], michael@0: ["i53643", "iso-8859-1"], michael@0: ["i54633", "iso-8859-1"], michael@0: ["i54980", "iso-8859-1", {1: "todo", 3: "todo"}], michael@0: ["maputf", "UTF-8"], michael@0: ["reputf", "UTF-8"], michael@0: ["ignore", "iso-8859-1"], michael@0: ["ignoreutf", "UTF-8", michael@0: {1: "todo", 2: "todo", 3: "todo", 4: "todo", 5: "todo", 6: "todo", michael@0: 7: "todo", 8: "todo"}], michael@0: ["1592880", "iso-8859-1"], michael@0: ["1695964", "iso-8859-1"], michael@0: ["1463589", "iso-8859-1"], michael@0: ["1463589_utf", "UTF-8"], michael@0: ["IJ", "iso-8859-1"], michael@0: ["i68568", "iso-8859-1"], michael@0: ["i68568utf", "UTF-8"], michael@0: ["1706659", "iso-8859-1"], michael@0: ["digits_in_words", "iso-8859-1"], michael@0: // ["colons_in_words", "iso-8859-1"], Suggestion test only michael@0: ["ngram_utf_fix", "UTF-8"], michael@0: ["morph", "us-ascii", michael@0: {11: "todo", 12: "todo", 13: "todo", 14: "todo", 15: "todo", 16: "todo", michael@0: 17: "todo", 18: "todo", 19: "todo", 20: "todo", 21: "todo", 22: "todo", michael@0: 23: "todo", 24: "todo", 25: "todo", 26: "todo", 27: "todo"}], michael@0: ["1975530", "UTF-8"], michael@0: ["fullstrip", "iso-8859-1"], michael@0: ["iconv", "UTF-8"], michael@0: ["oconv", "UTF-8"], michael@0: ["encoding", "iso-8859-1", {1: "todo", 3: "todo"}], michael@0: ["korean", "UTF-8"], michael@0: ["opentaal_forbiddenword1", "UTF-8"], michael@0: ["opentaal_forbiddenword2", "UTF-8"], michael@0: ["opentaal_keepcase", "UTF-8"], michael@0: ["arabic", "UTF-8"], michael@0: ["2970240", "iso-8859-1"], michael@0: ["2970242", "iso-8859-1"], michael@0: ["breakoff", "iso-8859-1"], michael@0: ["opentaal_cpdpat", "iso-8859-1"], michael@0: ["opentaal_cpdpat2", "iso-8859-1"], michael@0: ["2999225", "iso-8859-1"], michael@0: ["onlyincompound2", "iso-8859-1"], michael@0: ["forceucase", "iso-8859-1"], michael@0: ["warn", "iso-8859-1"] michael@0: ]; michael@0: michael@0: function do_get_file_by_line(file, charset) { michael@0: dump("getting file by line for file " + file.path + "\n"); michael@0: dump("using charset " + charset +"\n"); michael@0: let fis = Cc["@mozilla.org/network/file-input-stream;1"]. michael@0: createInstance(Ci.nsIFileInputStream); michael@0: fis.init(file, 0x1 /* READONLY */, michael@0: 0444, Ci.nsIFileInputStream.CLOSE_ON_EOF); michael@0: michael@0: let lis = Cc["@mozilla.org/intl/converter-input-stream;1"]. michael@0: createInstance(Ci.nsIConverterInputStream); michael@0: lis.init(fis, charset, 1024, 0); michael@0: lis.QueryInterface(Ci.nsIUnicharLineInputStream); michael@0: michael@0: var val = {}; michael@0: while (lis.readLine(val)) { michael@0: yield val.value; michael@0: val = {}; michael@0: } michael@0: } michael@0: michael@0: function do_run_test(checker, name, charset, todo_good, todo_bad) { michael@0: dump("\n\n\n\n"); michael@0: dump("running test for " + name + "\n"); michael@0: if (!checker) { michael@0: do_throw("Need spell checker here!"); michael@0: } michael@0: michael@0: let good = do_get_file("data/" + name + ".good", true); michael@0: let bad = do_get_file("data/" + name + ".wrong", true); michael@0: let sug = do_get_file("data/" + name + ".sug", true); michael@0: michael@0: dump("Need some expected output\n") michael@0: do_check_true(good.exists() || bad.exists() || sug.exists()); michael@0: michael@0: dump("Setting dictionary to " + name + "\n"); michael@0: checker.dictionary = name; michael@0: michael@0: if (good.exists()) { michael@0: var good_counter = 0; michael@0: for (val in do_get_file_by_line(good, charset)) { michael@0: let todo = false; michael@0: good_counter++; michael@0: if (todo_good && todo_good[good_counter]) { michael@0: todo = true; michael@0: dump("TODO\n"); michael@0: } michael@0: michael@0: dump("Expect word " + val + " is spelled correctly\n"); michael@0: if (todo) { michael@0: todo_check_true(checker.check(val)); michael@0: } else { michael@0: do_check_true(checker.check(val)); michael@0: } michael@0: } michael@0: } michael@0: michael@0: if (bad.exists()) { michael@0: var bad_counter = 0; michael@0: for (val in do_get_file_by_line(bad, charset)) { michael@0: let todo = false; michael@0: bad_counter++; michael@0: if (todo_bad && todo_bad[bad_counter]) { michael@0: todo = true; michael@0: dump("TODO\n"); michael@0: } michael@0: michael@0: dump("Expect word " + val + " is spelled wrong\n"); michael@0: if (todo) { michael@0: todo_check_false(checker.check(val)); michael@0: } else { michael@0: do_check_false(checker.check(val)); michael@0: } michael@0: } michael@0: } michael@0: michael@0: // XXXkhuey test suggestions michael@0: } michael@0: michael@0: function run_test() { michael@0: let spellChecker = Cc["@mozilla.org/spellchecker/engine;1"]. michael@0: getService(Ci.mozISpellCheckingEngine); michael@0: michael@0: do_check_true(!!spellChecker, "Should have a spell checker"); michael@0: spellChecker.QueryInterface(Ci.mozISpellCheckingEngine); michael@0: let testdir = do_get_file("data/", false); michael@0: spellChecker.loadDictionariesFromDir(testdir); michael@0: michael@0: function do_run_test_closure(test) { michael@0: [name, charset, todo_good, todo_bad] = test; michael@0: do_run_test(spellChecker, name, charset, todo_good, todo_bad); michael@0: } michael@0: michael@0: tests.forEach(do_run_test_closure); michael@0: }