Beispiel #1
0
    bool AddWordToDictionary(EnchantDict* dict, const std::string& word)
    {
        if(dict == NULL)
        {
            return false;
        }

        if(IsWordInDictionary(dict, word))
        {
            return true;
        }

        // prefer adding it to the session so it will get automatically removed
        if(dict->add_to_session)
        {
            (*dict->add_to_session) (dict, word.c_str(), word.length());
            if(IsWordInDictionary(word))
            {
                return true;
            }
        }

        if(dict->add_to_personal)
        {
            _addedWordsByDict.insert(std::pair<EnchantDict*, std::string>(dict,word));
            (*dict->add_to_personal) (dict, word.c_str(), word.length());
            if(IsWordInDictionary(word))
            {
                return true;
            }
        }

        return false;
    }
TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
             EnchantDictionaryAdd_IsPermanent)
{
    enchant_dict_add(_dict, "hello", -1);
    CHECK(IsWordInDictionary("hello"));

    ReloadTestDictionary();

    CHECK(IsWordInDictionary("hello"));
}
Beispiel #3
0
TEST_FIXTURE(DictionaryCheck_TestFixture, 
             IsWordInDictionary_SuccessfulCheckWithComposedAndDecomposed)
{
    EnchantDict* dict = GetDictionary("fr_FR");
    if(dict && dict->check)
    {
        CHECK( IsWordInDictionary(dict, Convert(L"Fran\x00e7" L"ais")) ); //NFC latin small letter c with cedilla
        CHECK( IsWordInDictionary(dict, Convert(L"Franc\x0327" L"ais")) ); //NFD combining cedilla
    }
    ReleaseDictionary(dict);
}
Beispiel #4
0
TEST_FIXTURE(DictionaryCheck_TestFixture, 
             IsWordInDictionary_AddedDecomposed_SuccessfulCheckWithComposedAndDecomposed)
{
    if(_dict && _dict->check)
    {
      if(AddWordToDictionary(Convert(L"fiance\x0301" L"deletethis"))) // u0301 = Combining acute accent
      {
          CHECK( IsWordInDictionary(Convert(L"fianc\x00e9" L"deletethis")) ); //NFC
          CHECK( IsWordInDictionary(Convert(L"fiance\x0301" L"deletethis")) ); //NFD
      }
    }
}
Beispiel #5
0
TEST_FIXTURE(DictionaryCheck_TestFixture, 
             IsWordInDictionary_Addedlower_MixedCaseNotSuccessful)
{
    if(_dict && _dict->check)
    {
      if(AddWordToDictionary("zyxz"))
      {
          CHECK( IsWordInDictionary("ZYXZ") );
          CHECK(!IsWordInDictionary("ZYxz") );
          CHECK( IsWordInDictionary("Zyxz") );
          CHECK( IsWordInDictionary("zyxz") );
          CHECK(!IsWordInDictionary("zYxz") );
      }
    }
}
Beispiel #6
0
/////////////////////////////////////////////////////////////////////////////////////////////////
// Capitalization
TEST_FIXTURE(DictionaryCheck_TestFixture, 
             IsWordInDictionary_AddedAllCaps_OnlyAllCapsSuccessful)
{
    if(_dict && _dict->check)
    {
      if(AddWordToDictionary("ZYX"))
      {
          CHECK( IsWordInDictionary("ZYX") );
          CHECK(!IsWordInDictionary("ZYx") );
          CHECK(!IsWordInDictionary("Zyx") );
          CHECK(!IsWordInDictionary("zyx") );
          CHECK(!IsWordInDictionary("zYx") );
      }
    }
}
Beispiel #7
0
TEST_FIXTURE(DictionaryCheck_TestFixture, 
             IsWordInDictionary_AddedTitle_lowerCaseAndMixedCaseNotSuccessful)
{
    if(_dict && _dict->check)
    {
      if(AddWordToDictionary("Zxyz"))
      {

          CHECK( IsWordInDictionary("ZXYZ") );
          CHECK(!IsWordInDictionary("ZXyz") );
          CHECK( IsWordInDictionary("Zxyz") );
          CHECK(!IsWordInDictionary("zxyz") );
          CHECK(!IsWordInDictionary("zXyz") );
      }
   }
}
TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture,
             EnchantDictionaryAddToSession_WordExistsInExclude_AddedToSessionNotRemovedFromExcludeFile)
{
    enchant_dict_remove(_dict, "personal", -1);

    enchant_dict_add_to_session(_dict, "personal", -1);
    CHECK(IsWordInDictionary("personal"));
    CHECK(ExcludeFileHasContents());
}
/////////////////////////////////////////////////////////////////////////////
// Test Normal Operation
TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
             EnchantDictionaryAdd_WordExistsInDictionary)
{
    enchant_dict_add(_dict, "hello", -1);
    CHECK(IsWordInDictionary("hello"));
}
Beispiel #10
0
wxString HunspellInterface::CheckSpelling(wxString strText)
{
  if (m_pHunspell == NULL)
    return wxEmptyString;

  int nDiff = 0;

  strText += _T(" ");

  wxString strDelimiters = _T(" \t\r\n.,?!@#$%^&*()-=_+[]{}\\|;:\"<>/~0123456789");
  wxStringTokenizer tkz(strText, strDelimiters);
  while ( tkz.HasMoreTokens() )
  {
    wxString token = tkz.GetNextToken();
    int TokenStart = tkz.GetPosition() - token.Length() - 1;
    TokenStart += nDiff;  // Take into account any changes to the size of the strText

    // process token here
    if (!IsWordInDictionary(token))
    {
      // If this word is in the always ignore list, then just move on
      if (m_AlwaysIgnoreList.Index(token) != wxNOT_FOUND)
        continue;

/* dealt with by IsWordInDictionary - JACS
       // If this word is in the personal dictionary, then just move on
       if (m_PersonalDictionary.IsWordInDictionary(token))
         continue;
*/

      bool bReplaceFromMap = false;
      StringToStringMap::iterator WordFinder = m_AlwaysReplaceMap.find(token);
      if (WordFinder != m_AlwaysReplaceMap.end())
        bReplaceFromMap = true;

      int nUserReturnValue = 0;

      if (!bReplaceFromMap)
      {
        // Define the context of the word
        DefineContext(strText, TokenStart, token.Length());

        // Print out the misspelling and get a replasment from the user
        // Present the dialog so the user can tell us what to do with this word
        nUserReturnValue = GetUserCorrection(token);  //Show function will show the dialog and not return until the user makes a decision
      }

      if (nUserReturnValue == wxSpellCheckUserInterface::ACTION_CLOSE)
      {
        break;
      }
      else if ((nUserReturnValue == wxSpellCheckUserInterface::ACTION_REPLACE) || bReplaceFromMap)
      {
        wxString strReplacementText = (bReplaceFromMap) ? (*WordFinder).second : m_pSpellUserInterface->GetReplacementText();
        // Increase/Decreate the character difference so that the next loop is on track
        nDiff += strReplacementText.Length() - token.Length();
        // Replace the misspelled word with the replacement */
        strText.replace(TokenStart, token.Length(), strReplacementText);
      }
    }
  }

  strText = strText.Left(strText.Len() - 1);

  return strText;
}
Beispiel #11
0
 bool IsWordInDictionary(const std::string& word)
 {
     return IsWordInDictionary(_dict, word);
 }