Beispiel #1
0
        public void OurDictionaryIsPrivate()
        {
            var dictId = MakeEmptyFooDictionary();
            var dict   = SpellingHelper.GetSpellChecker(dictId);

            dict.SetStatus("big", true);
            var otherDict = SpellingHelper.GetSpellChecker("fo");             // try to get one with a shorter name

            Assert.That(otherDict, Is.Null);
        }
Beispiel #2
0
        public void DictionaryCanHaveNonAsciId()
        {
            var dictId = MakeEmptyDictionary("ab\x1234\x3456");
            var dict   = SpellingHelper.GetSpellChecker(dictId);

            Assert.That(dict.Check("nonsense"), Is.False);
            Assert.That(dict.Check("big"), Is.False);
            dict.SetStatus("big", true);
            Assert.That(dict.Check("big"), Is.True);
        }
Beispiel #3
0
        public void GetSimpleSuggestion()
        {
            MakeEmptyFooDictionary();
            var dict = SpellingHelper.GetSpellChecker("foo");

            dict.SetStatus("bad", true);
            var suggestions = dict.Suggest("badd");

            Assert.That(suggestions.Count, Is.GreaterThanOrEqualTo(1));
            Assert.That(suggestions.First(), Is.EqualTo("bad"));
        }
Beispiel #4
0
        public void AddBaddBeforeStarSpellling()
        {
            MakeEmptyFooDictionary();
            var dict = SpellingHelper.GetSpellChecker("foo");

            dict.SetStatus("spellling", false);
            dict.SetStatus("badd", true);
            SpellingHelper.ClearAllDictionaries();
            dict = SpellingHelper.GetSpellChecker("foo");
            Assert.That(dict.Check("spellling"), Is.False);
            Assert.That(dict.Check("badd"), Is.True);
        }
Beispiel #5
0
        public void ExceptionListIsLoadedForNonVernacularDictionary()
        {
            MakeNonPrivateBlahDictionary();
            var filePath = SpellingHelper.GetDicPath(SpellingHelper.GetSpellingDirectoryPath(), "blah");

            using (var writer = FileUtils.OpenFileForWrite(Path.ChangeExtension(filePath, ".exc"), Encoding.UTF8))
            {
                writer.WriteLine("good");
            }
            var dict = SpellingHelper.GetSpellChecker("blah");

            Assert.That(dict.Check("good"), Is.True);
        }
Beispiel #6
0
        public void OtherDictionaryIsNotPrivate()
        {
            // Create a dictionary file for "blah" that does NOT look like one of ours.
            MakeNonPrivateBlahDictionary();

            var dict = SpellingHelper.GetSpellChecker("blah");

            dict.SetStatus("big", true);
            Assert.That(dict, Is.Not.Null);
            Assert.That(dict.Check("big"), Is.True);
            var otherDict = SpellingHelper.GetSpellChecker("bl");             // try to get one with a shorter name

            Assert.That(otherDict, Is.EqualTo(dict), "getting a prefix of a non-private dictionary should find the non-private dictionary");
        }
Beispiel #7
0
        public void ResetDictionaryAddsAllWords()
        {
            var id   = MakeEmptyFooDictionary();
            var dict = SpellingHelper.GetSpellChecker(id);

            dict.SetStatus("old", true);
            Assert.That(dict.Check("old"), Is.True);

            SpellingHelper.ResetDictionary(id, new[] { "hello", "wo\x0302rld", "this", "is", "a", "test" });
            dict = SpellingHelper.GetSpellChecker(id);

            Assert.That(dict.Check("old"), Is.False);
            Assert.That(dict.Check("hello"), Is.True);
            Assert.That(dict.Check("w\x00f4rld"), Is.True);
            Assert.That(dict.Check("wo\x0302rld"), Is.True);             // decomposed form.
            Assert.That(dict.Check("is"), Is.True);
            Assert.That(dict.Check("a"), Is.True);
            Assert.That(dict.Check("test"), Is.True);
        }
Beispiel #8
0
 public ICheckWord GetChecker(string dictId)
 {
     return(SpellingHelper.GetSpellChecker(dictId));
 }
Beispiel #9
0
        public void BasicSpellingStatus()
        {
            var dictId = MakeEmptyFooDictionary();
            var dict   = SpellingHelper.GetSpellChecker(dictId);

            Assert.That(dict, Is.Not.Null);
            Assert.That(dict.Check("nonsense"), Is.False);
            Assert.That(dict.Check("big"), Is.False);
            dict.SetStatus("big", true);
            Assert.That(dict.Check("big"), Is.True);
            // By default Hunspell fails this test; setting "big" to correct makes "Big" correct too.
            // We override this behavior (in a rather tricky way) for vernacular dictionaries.
            Assert.That(dict.Check("Big"), Is.False);
            dict.SetStatus("Big", false);
            Assert.That(dict.Check("Big"), Is.False);
            Assert.That(dict.Check("big"), Is.True);

            // If we set the upper case version only, that is considered correct, but the LC version is not.
            Assert.That(dict.Check("Bother"), Is.False);
            dict.SetStatus("Bother", true);
            Assert.That(dict.Check("Bother"), Is.True);
            Assert.That(dict.Check("bother"), Is.False);

            // Subsequently explicitly setting the LC version to false is not a problem.
            dict.SetStatus("bother", false);
            Assert.That(dict.Check("Bother"), Is.True);
            Assert.That(dict.Check("bother"), Is.False);

            // Now if we set the UC version false, both are.
            dict.SetStatus("Bother", false);
            Assert.That(dict.Check("Bother"), Is.False);
            Assert.That(dict.Check("bother"), Is.False);

            // Now both are explicitly false. Set the LC one to true.
            dict.SetStatus("bother", true);
            Assert.That(dict.Check("Bother"), Is.False);
            Assert.That(dict.Check("bother"), Is.True);

            // Now make the LC one false again.
            dict.SetStatus("bother", false);
            Assert.That(dict.Check("Bother"), Is.False);
            Assert.That(dict.Check("bother"), Is.False);

            // Now make the UC one true again.
            dict.SetStatus("Bother", true);
            Assert.That(dict.Check("Bother"), Is.True);
            Assert.That(dict.Check("bother"), Is.False);

            // There is a special case in the code when the new word is alphabetically after any we already added.
            dict.SetStatus("world", true);
            Assert.That(dict.Check("world"), Is.True);

            // Check normalization
            dict.SetStatus("w\x00f4rld", true);              // o with cicrumflex (composed)
            Assert.That(dict.Check("w\x00f4rld"), Is.True);
            Assert.That(dict.Check("wo\x0302rld"), Is.True); // decomposed form.
            dict.SetStatus("bo\x0302lt", true);              // set decomposed
            Assert.That(dict.Check("bo\x0302lt"), Is.True);
            Assert.That(dict.Check("b\x00f4lt"), Is.True);   // composed form.


            // Check that results were persisted.
            SpellingHelper.ClearAllDictionaries();
            dict = SpellingHelper.GetSpellChecker(dictId);
            Assert.That(dict.Check("Bother"), Is.True);
            Assert.That(dict.Check("world"), Is.True);
        }