ui::testing::TestSpellChecker¶
Header: winui/testing/TestSpellChecker.hpp.
Derives from ui::SpellChecker.
Deterministic, in-process SpellChecker for headless tests. It uses no system dictionary, only the words the test declared misspelled.
Every change (a new misspelling, a settings flip, add/ignore/autocorrect) bumps generation(), which tells a synced control to check again. Always reports "en-US" while available. Words are runs of letters, digits, underscores and apostrophes, matched with exact case.
Example:
ui::testing::HeadlessTextMeasurer measurer;
ui::TextBoxControl tb{"Ths is a tset"};
const ui::Size size = tb.measure({200.0f, ui::Unbounded}, measurer, ui::Theme::default_light());
tb.arrange({100.0f, 100.0f, 200.0f, size.height});
ui::testing::set_focused(tb, true);
ui::testing::TestSpellChecker checker;
checker.add_misspelling("Ths", {"This"});
checker.add_misspelling("tset", {"test"});
tb.sync_spell_checker(checker);
tb.tick(ui::Duration{0}); // checking happens on the next tick, never inside the sync
REQUIRE(tb.spelling_errors().size() == 2);
REQUIRE(checker.check_count() == 1);
REQUIRE(checker.suggest("Ths") == std::vector<std::string>{"This"});
add_misspelling¶
Declares word (exact case) misspelled, with the list suggest() returns for it.
set_available¶
Simulates a missing or present system dictionary. While unavailable, checks find nothing and language() is empty. Default true.
set_highlight_enabled¶
Flips the user's "highlight misspelled words" setting (default true).
set_autocorrect_enabled¶
Flips the user's "autocorrect misspelled words" setting (default true).
check_count¶
How many times check() ran, available or not, so a test can show a control didn't check again.
added¶
Words passed to add_to_dictionary(), in order.
ignored¶
Words passed to ignore_for_session(), in order.
available¶
The set_available() state.
language¶
"en-US" while available, empty otherwise.
highlight_enabled¶
The set_highlight_enabled() state.
autocorrect_enabled¶
The set_autocorrect_enabled() state.
generation¶
Starts at 1 and bumps on every change of the checker's state.
check¶
Reports each declared misspelling (SpellingAction::Suggest) or autocorrection (SpellingAction::Replace) in text, as byte offsets; added or ignored words are skipped. Words are runs of letters, digits, underscores and apostrophes, matched with exact case. This doesn't reproduce how the system checker splits words.
suggest¶
The suggestions declared with add_misspelling() for word, or empty.
add_to_dictionary¶
Accepts word from now on and records it in added().
ignore_for_session¶
Accepts word from now on and records it in ignored().
add_autocorrection¶
Makes check() report from as a Replace error carrying to; wins over a misspelling.