コード例 #1
0
TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
             EnchantDictionaryAdd_WordExistsInPersonal_StillCallsProvider)
{
    enchant_dict_add(_dict, "personal", -1);
    addToPersonalCalled=false;
    wordToAdd = std::string();

    enchant_dict_add(_dict, "personal", -1);
    CHECK(addToPersonalCalled);
    CHECK_EQUAL(std::string("personal"), wordToAdd);
}
コード例 #2
0
TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
             EnchantDictionaryAdd_InBrokerPwl)
{
    enchant_dict_add(_pwl, "personal", -1);
    CHECK(!addToPersonalCalled);
    CHECK(!PersonalWordListFileHasContents());
}
コード例 #3
0
TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
             EnchantDictionaryAdd_PassedOnToProvider_LenSpecified)
{
    enchant_dict_add(_dict, "hellodisregard me", 5);
    CHECK(addToPersonalCalled);
    CHECK_EQUAL(std::string("hello"), wordToAdd);
}
コード例 #4
0
TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
             EnchantDictionaryAdd_PassedOnToProvider_LenComputed)
{
    enchant_dict_add(_dict, "hello", -1);
    CHECK(addToPersonalCalled);
    CHECK_EQUAL(std::string("hello"), wordToAdd);
}
コード例 #5
0
TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
             EnchantDictionaryAdd_WordAddedToEnchantPwlFile)
{
    CHECK(!PersonalWordListFileHasContents());
    enchant_dict_add(_dict, "hello", -1);
    CHECK(PersonalWordListFileHasContents());
}
コード例 #6
0
TEST_FIXTURE(EnchantDictionaryIsAdded_TestFixture, 
             EnchantDictionaryIsAdded_OnBrokerPwl_Added_1)
{
    enchant_dict_add(_pwl, "hello", -1);

    CHECK_EQUAL(1, enchant_dict_is_added(_pwl, "hello", -1));
}
コード例 #7
0
TEST_FIXTURE(EnchantDictionaryAdd_TestFixture, 
             EnchantDictionaryAdd_HasPreviousError_ErrorCleared)
{
    SetErrorOnMockDictionary("something bad happened");

    enchant_dict_add(_dict, "hello", -1);
    CHECK_EQUAL((void*)NULL, (void*)enchant_dict_get_error(_dict));
}
コード例 #8
0
TEST_FIXTURE(EnchantDictionaryCheck_TestFixture,
             EnchantDictionaryCheck_WordExistsInPersonal_0_DoesNotCallProvider)
{
    enchant_dict_add(_dict, "personal", -1);

    CHECK_EQUAL(0, enchant_dict_check(_dict, "personal", -1));
    CHECK(!dictCheckCalled);
}
コード例 #9
0
TEST_FIXTURE(EnchantDictionarySuggest_TestFixture,
             EnchantDictionarySuggest_InBrokerPwlSession)
{
    enchant_dict_add(_pwl, "hello", -1);
    _suggestions = enchant_dict_suggest(_pwl, "helo", -1, NULL);
    CHECK(_suggestions);
    CHECK(!dictSuggestCalled);
}
コード例 #10
0
TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
             EnchantDictionaryAdd_WordExistsInExclude_RemovedFromExcludeAddedToPersonal)
{
    enchant_dict_remove(_dict, "personal", -1);
    CHECK(ExcludeFileHasContents());
    enchant_dict_add(_dict, "personal", -1);
    CHECK(!ExcludeFileHasContents());
    CHECK(PersonalWordListFileHasContents());
}
コード例 #11
0
TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
             EnchantDictionaryAdd_IsPermanent)
{
    enchant_dict_add(_dict, "hello", -1);
    CHECK(IsWordInDictionary("hello"));

    ReloadTestDictionary();

    CHECK(IsWordInDictionary("hello"));
}
コード例 #12
0
TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
             EnchantDictionaryAdd_WordExistsInSession_StillCallsProvider)
{
    enchant_dict_add_to_session(_dict, "session", -1);
    CHECK(!addToPersonalCalled);

    enchant_dict_add(_dict, "session", -1);
    CHECK(addToPersonalCalled);
    CHECK_EQUAL(std::string("session"), wordToAdd);
}
コード例 #13
0
TEST_FIXTURE(EnchantDictionarySuggest_TestFixture,
             EnchantDictionarySuggest_DuplicateSuggestionsFromPersonal_notIncluded)
{
    size_t cSuggestions;

    enchant_dict_add(_dict, "aelo", -1);
    _suggestions = enchant_dict_suggest(_dict, "helo", -1, &cSuggestions);
    CHECK(_suggestions);
    CHECK_EQUAL(4, cSuggestions);

    std::vector<std::string> suggestions;
    if(_suggestions != NULL){
        suggestions.insert(suggestions.begin(), _suggestions, _suggestions+cSuggestions);
    }

    CHECK_ARRAY_EQUAL(GetExpectedSuggestions("helo"), suggestions, std::min((size_t)4,cSuggestions));
}
コード例 #14
0
TEST_FIXTURE(EnchantDictionarySuggest_TestFixture,
             EnchantDictionarySuggest_SuggestionsFromPersonal_addedToEnd)
{
    size_t cSuggestions;
    enchant_dict_add(_dict, "hello", -1);
    _suggestions = enchant_dict_suggest(_dict, "helo", -1, &cSuggestions);
    CHECK(_suggestions);
    CHECK_EQUAL(5, cSuggestions);

    std::vector<std::string> suggestions;
    if(_suggestions != NULL){
        suggestions.insert(suggestions.begin(), _suggestions, _suggestions+cSuggestions);
    }

    std::vector<std::string> expected = GetExpectedSuggestions("helo");
    expected.push_back("hello");

    CHECK_ARRAY_EQUAL(expected, suggestions, std::min((size_t)5,cSuggestions));
}
コード例 #15
0
ファイル: enchant-ispell.c プロジェクト: TingPing/enchant
static int
parse_file (FILE * in, FILE * out, IspellMode_t mode, int countLines, gchar *dictionary)
{
	EnchantBroker * broker;
	EnchantDict * dict;
	
	GString * str, * word = NULL;
	GSList * tokens, *token_ptr;
	gchar * lang;
	size_t pos, lineCount = 0;

	gboolean was_last_line = FALSE, corrected_something = FALSE, terse_mode = FALSE;

	if (mode == MODE_A)
		print_version (out);

	if (dictionary) {
		lang = convert_language_code (dictionary);
	}
	else {
	        lang = enchant_get_user_language();
		if(!lang)
			return 1;
 	}

	/* Enchant will get rid of useless trailing garbage like de_DE@euro or de_DE.ISO-8859-15 */
	
	broker = enchant_broker_init ();
	dict = enchant_broker_request_dict (broker, lang);

	if (!dict) {
		fprintf (stderr, "Couldn't create a dictionary for %s\n", lang);
		g_free (lang);
		enchant_broker_free (broker);
		return 1;
	}

	g_free (lang);

	str = g_string_new (NULL);
	
	while (!was_last_line) {
		gboolean mode_A_no_command = FALSE;
		was_last_line = consume_line (in, str);

		if (countLines)
			lineCount++;

		if (str->len) {
			corrected_something = FALSE;

			if (mode == MODE_A) {
				switch (*str->str) {
				case '&': /* Insert uncapitalised in personal word list */
					if (str->len > 1) {
						gunichar c = g_utf8_get_char_validated(str->str + 1, str->len);
						if (c > 0) {
							str = g_string_erase(str, 1, g_utf8_next_char(str->str + 1) - (str->str + 1));
							g_string_insert_unichar(str, 1, g_unichar_tolower(c));
						}
					}
					/* FALLTHROUGH */
				case '*': /* Insert in personal word list */
					if (str->len == 1)
						goto empty_word;
					enchant_dict_add(dict, str->str + 1, -1);
					break;
				case '@': /* Accept for this session */
					if (str->len == 1)
						goto empty_word;
					enchant_dict_add_to_session(dict, str->str + 1, -1);
					break;

				case '%': /* Exit terse mode */
					terse_mode = FALSE;
					break;
				case '!': /* Enter terse mode */
					terse_mode = TRUE;
					break;

				/* Ignore these commands */
				case '#': /* Save personal word list (enchant does this automatically) */
				case '+': /* LaTeX mode */
				case '-': /* nroff mode [default] */
				case '~': /* change string character type (enchant is fixed to UTF-8) */
				case '`': /* Enter verbose-correction mode */
					break;

				case '$': /* Save correction for rest of session [aspell extension] */
					{ /* Syntax: $$ra <MISSPELLED>,<REPLACEMENT> */
						gchar *prefix = "$$ra ";
						if (g_str_has_prefix(str->str, prefix)) {
							gchar *comma = g_utf8_strchr(str->str, -1, (gunichar)',');
							char *mis = str->str + strlen(prefix);
							char *cor = comma + 1;
							ssize_t mis_len = comma - mis;
							ssize_t cor_len = strlen(str->str) - (cor - str->str);
							enchant_dict_store_replacement(dict, mis, mis_len, cor, cor_len);
						}
					}
					break;

				case '^': /* ^ is used as prefix to prevent interpretation of original
					     first character as a command */
					/* FALLTHROUGH */
				default: /* A word or words to check */
					mode_A_no_command = TRUE;
					break;

				empty_word:
					fprintf (out, "Error: The word \"\" is invalid. Empty string.\n");
				}
			}

			if (mode != MODE_A || mode_A_no_command) {
				token_ptr = tokens = tokenize_line (str);
				if (tokens == NULL)
					putc('\n', out);
				while (tokens != NULL) {
					corrected_something = TRUE;

					word = (GString *)tokens->data;
					tokens = tokens->next;
					pos = GPOINTER_TO_INT(tokens->data);
					tokens = tokens->next;

					if (mode == MODE_A)
						do_mode_a (out, dict, word, pos, lineCount, terse_mode);
					else if (mode == MODE_L)
						do_mode_l (out, dict, word, lineCount);

					g_string_free(word, TRUE);
				}
				if (token_ptr)
					g_slist_free (token_ptr);
			}
		} 
		
		if (mode == MODE_A && corrected_something) {
			fwrite ("\n", 1, 1, out);
		}
		g_string_truncate (str, 0);
		fflush (out);
	}

	enchant_broker_free_dict (broker, dict);
	enchant_broker_free (broker);

	g_string_free (str, TRUE);

	return 0;
}
コード例 #16
0
void
weechat_aspell_command_add_word (struct t_gui_buffer *buffer, const char *dict,
                                 const char *word)
{
    struct t_aspell_speller_buffer *ptr_speller_buffer;
#ifdef USE_ENCHANT
    EnchantDict *new_speller, *ptr_speller;
#else
    AspellSpeller *new_speller, *ptr_speller;
#endif

    new_speller = NULL;

    if (dict)
    {
        ptr_speller = weechat_hashtable_get (weechat_aspell_spellers, dict);
        if (!ptr_speller)
        {
            if (!weechat_aspell_speller_dict_supported (dict))
            {
                weechat_printf (NULL,
                                _("%s: error: dictionary \"%s\" is not "
                                  "available on your system"),
                                ASPELL_PLUGIN_NAME, dict);
                return;
            }
            new_speller = weechat_aspell_speller_new (dict);
            if (!new_speller)
                return;
            ptr_speller = new_speller;
        }
    }
    else
    {
        ptr_speller_buffer = weechat_hashtable_get (weechat_aspell_speller_buffer,
                                                    buffer);
        if (!ptr_speller_buffer)
            ptr_speller_buffer = weechat_aspell_speller_buffer_new (buffer);
        if (!ptr_speller_buffer)
            goto error;
        if (!ptr_speller_buffer->spellers || !ptr_speller_buffer->spellers[0])
        {
            weechat_printf (NULL,
                            _("%s%s: no dictionary on this buffer for "
                              "adding word"),
                            weechat_prefix ("error"),
                            ASPELL_PLUGIN_NAME);
            return;
        }
        else if (ptr_speller_buffer->spellers[1])
        {
            weechat_printf (NULL,
                            _("%s%s: many dictionaries are defined for "
                              "this buffer, please specify dictionary"),
                            weechat_prefix ("error"),
                            ASPELL_PLUGIN_NAME);
            return;
        }
        ptr_speller = ptr_speller_buffer->spellers[0];
    }

#ifdef USE_ENCHANT
    enchant_dict_add (ptr_speller, word, strlen (word));
#else
    if (aspell_speller_add_to_personal (ptr_speller,
                                        word,
                                        strlen (word)) == 1)
    {
        weechat_printf (NULL,
                        _("%s: word \"%s\" added to personal dictionary"),
                        ASPELL_PLUGIN_NAME, word);
    }
    else
        goto error;
#endif

    goto end;

error:
    weechat_printf (NULL,
                    _("%s%s: failed to add word to personal "
                      "dictionary"),
                    weechat_prefix ("error"), ASPELL_PLUGIN_NAME);

end:
    if (new_speller)
        weechat_hashtable_remove (weechat_aspell_spellers, dict);
}
コード例 #17
0
TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
             EnchantDictionaryAdd_WordExistsInSession)
{
    enchant_dict_add(_dict, "hello", -1);
    CHECK(IsWordInSession("hello"));
}
コード例 #18
0
TEST_FIXTURE(EnchantDictionaryAddToPersonalNotImplemented_TestFixture,
             EnchantDictionaryAddToPersonalNotImplemented_NotPassedOnToProvider)
{
    enchant_dict_add(_dict, "hello", -1);
    CHECK(!addToPersonalCalled);
}
コード例 #19
0
TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
             EnchantDictionaryAdd_InvalidUtf8Word_NotAdded)
{
    enchant_dict_add(_dict, "\xa5\xf1\x08", -1);
    CHECK(!addToPersonalCalled);
}
コード例 #20
0
TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
             EnchantDictionaryAdd_WordSize0_NotAdded)
{
    enchant_dict_add(_dict, "hello", 0);
    CHECK(!addToPersonalCalled);
}
コード例 #21
0
TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
             EnchantDictionaryAdd_EmptyWord_NotAdded)
{
    enchant_dict_add(_dict, "", -1);
    CHECK(!addToPersonalCalled);
}
コード例 #22
0
/////////////////////////////////////////////////////////////////////////////
// Test Error Conditions
TEST_FIXTURE(EnchantDictionaryAdd_TestFixture,
             EnchantDictionaryAdd_NullDictionary_NotAdded)
{
    enchant_dict_add(NULL, "hello", -1);
    CHECK(!addToPersonalCalled);
}
コード例 #23
0
TEST_FIXTURE(EnchantDictionaryCheck_TestFixture,
             EnchantDictionaryCheck_WordDoesExists_InBrokerPwl_0)
{
    enchant_dict_add(_pwl, "personal", -1);
    CHECK_EQUAL(0, enchant_dict_check(_pwl, "personal", -1));
}