summaryrefslogtreecommitdiffstats
path: root/editor/libeditor/tests/spellcheck.js
blob: b6a15866282653bba54f8a1125b929b79b86d6d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function isSpellingCheckOk(aEditor, aMisspelledWords, aTodo = false) {
  var selcon = aEditor.selectionController;
  var sel = selcon.getSelection(selcon.SELECTION_SPELLCHECK);
  var numWords = sel.rangeCount;

  if (aTodo) {
    todo_is(
      numWords,
      aMisspelledWords.length,
      "Correct number of misspellings and words."
    );
  } else {
    is(
      numWords,
      aMisspelledWords.length,
      "Correct number of misspellings and words."
    );
  }

  if (numWords !== aMisspelledWords.length) {
    return false;
  }

  for (var i = 0; i < numWords; ++i) {
    var word = String(sel.getRangeAt(i));
    if (aTodo) {
      todo_is(word, aMisspelledWords[i], "Misspelling is what we think it is.");
    } else {
      is(word, aMisspelledWords[i], "Misspelling is what we think it is.");
    }
    if (word !== aMisspelledWords[i]) {
      return false;
    }
  }
  return true;
}