TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture,
             EnchantDictionaryAddToSession_WordExistsInSession_StillCallsProvider)
{
    enchant_dict_add_to_session(_dict, "session", -1);
    addToSessionCalled=false;
    wordToAdd = std::string();

    enchant_dict_add_to_session(_dict, "session", -1);
    CHECK(addToSessionCalled);
    CHECK_EQUAL(std::string("session"), wordToAdd);
}
TEST_FIXTURE(EnchantDictionaryIsAdded_TestFixture, 
             EnchantDictionaryIsAdded_OnBrokerPwl_AddedToSession_1)
{
    enchant_dict_add_to_session(_pwl, "hello", -1);

    CHECK_EQUAL(1, enchant_dict_is_added(_pwl, "hello", -1));
}
TEST_FIXTURE(EnchantDictionaryCheck_TestFixture,
             EnchantDictionaryCheck_WordExistsInSession_0_DoesNotCallProvider)
{
    enchant_dict_add_to_session(_dict, "session", -1);
    CHECK_EQUAL(0, enchant_dict_check(_dict, "session", -1));
    CHECK(!dictCheckCalled);
}
Beispiel #4
0
void sc_speller_add_word_to_session(const gchar *word)
{
	g_return_if_fail(sc_speller_dict != NULL);
	g_return_if_fail(word != NULL);

	enchant_dict_add_to_session(sc_speller_dict, word, -1);
}
TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture,
             EnchantDictionaryAddToSession_InBrokerSession)
{
    enchant_dict_add_to_session(_pwl, "personal", -1);
    CHECK(!addToSessionCalled);
    CHECK(!PersonalWordListFileHasContents());
}
TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture,
             EnchantDictionaryAddToSession_PassedOnToProvider_LenSpecified)
{
    enchant_dict_add_to_session(_dict, "hellodisregard me", 5);
    CHECK(addToSessionCalled);
    CHECK_EQUAL(std::string("hello"), wordToAdd);
}
TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture, 
             EnchantDictionaryAddToSession_HasPreviousError_ErrorCleared)
{
    SetErrorOnMockDictionary("something bad happened");

    enchant_dict_add_to_session(_dict, "hello", -1);
    CHECK_EQUAL((void*)NULL, (void*)enchant_dict_get_error(_dict));
}
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());
}
void EditorClient::ignoreWordInSpellDocument(const String& text)
{
    GSList* dicts = webkit_web_settings_get_enchant_dicts(m_webView);

    for (; dicts; dicts = dicts->next) {
        EnchantDict* dict = static_cast<EnchantDict*>(dicts->data);

        enchant_dict_add_to_session(dict, text.utf8().data(), -1);
    }
}
TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture,
             EnchantDictionaryAddToSession_IsNotPermanent)
{
    enchant_dict_add_to_session(_dict, "hello", -1);
    CHECK(IsWordInSession("hello"));

    ReloadTestDictionary();

    CHECK(!IsWordInSession("hello"));
}
void EditorClient::ignoreWordInSpellDocument(const String& text)
{
    GSList* langs = webkit_web_settings_get_spell_languages(m_webView);

    for (; langs; langs = langs->next) {
        SpellLanguage* lang = static_cast<SpellLanguage*>(langs->data);

        enchant_dict_add_to_session(lang->speller, text.utf8().data(), -1);
    }
}
TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture,
             EnchantDictionaryAddToSession_WordExistsInPersonal_StillCallsProvider)
{
    enchant_dict_add(_dict, "personal", -1);
    CHECK(!addToSessionCalled);

    enchant_dict_add_to_session(_dict, "personal", -1);
    CHECK(addToSessionCalled);
    CHECK_EQUAL(std::string("personal"), wordToAdd);
}
Beispiel #13
0
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;
}
/////////////////////////////////////////////////////////////////////////////
// Test Normal Operation
TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture,
             EnchantDictionaryAddToSession_WordNotAddedToEnchantPwlFile)
{
    enchant_dict_add_to_session(_dict, "hello", -1);
    CHECK(!PersonalWordListFileHasContents());
}
TEST_FIXTURE(EnchantDictionaryAddToSessionNotImplemented_TestFixture,
             EnchantDictionaryAddToSessionNotImplemented_NotPassedOnToProvider)
{
    enchant_dict_add_to_session(_dict, "hello", -1);
    CHECK(!addToSessionCalled);
}
TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture,
             EnchantDictionaryAddToSession_InvalidUtf8Word_NotAdded)
{
    enchant_dict_add_to_session(_dict, "\xa5\xf1\x08", -1);
    CHECK(!addToSessionCalled);
}
TEST_FIXTURE(EnchantDictionaryCheck_TestFixture,
             EnchantDictionaryCheck_WordDoesExists_InBrokerPwlSession_0)
{
    enchant_dict_add_to_session(_pwl, "session", -1);
    CHECK_EQUAL(0, enchant_dict_check(_pwl, "session", -1));
}
TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture,
             EnchantDictionaryAddToSession_EmptyWord_NotAdded)
{
    enchant_dict_add_to_session(_dict, "", -1);
    CHECK(!addToSessionCalled);
}
/////////////////////////////////////////////////////////////////////////////
// Test Error Conditions
TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture,
             EnchantDictionaryAddToSession_NullDictionary_NotAdded)
{
    enchant_dict_add_to_session(NULL, "hello", -1);
    CHECK(!addToSessionCalled);
}
TEST_FIXTURE(EnchantDictionaryAddToSession_TestFixture,
             EnchantDictionaryAddToSession_WordSize0_NotAdded)
{
    enchant_dict_add_to_session(_dict, "hello", 0);
    CHECK(!addToSessionCalled);
}
TEST_FIXTURE(EnchantDictionaryAddToSessionNotImplemented_TestFixture,
             EnchantDictionaryAddToSessionNotImplemented_WordAddedToSession)
{
    enchant_dict_add_to_session(_dict, "hello", -1);
    CHECK(IsWordInSession("hello"));
}