Release v0.6.10: preserve typing during correction and add personal dictionaries
This commit is contained in:
@@ -241,6 +241,37 @@ int main(int argc, char **argv)
|
||||
require(corrector.memoryBytes() < 3 * 1024 * 1024, "two dictionaries fit within 3 MiB");
|
||||
require(!ks::autoCorrectionAllowed(nullptr, autoSettings), "missing focused editor fails closed");
|
||||
ks::AutoCorrector missing;
|
||||
{
|
||||
ks::AutoCorrector supplemental;
|
||||
auto options = autoSettings;
|
||||
options.autoLanguages = {L"en", L"uk", L"ru"};
|
||||
options.cycle = {L"en", L"uk", L"ru"};
|
||||
supplemental.configure(L"dictionaries", options.autoLanguages);
|
||||
auto release = supplemental.suggest(L"релыз ", 1, layouts, options);
|
||||
require(release && release->text == L"реліз " && release->target == 2,
|
||||
"supplemental Ukrainian release word corrects from Russian layout");
|
||||
require(!supplemental.suggest(L"реліз ", 2, layouts, options),
|
||||
"correct Ukrainian release word stays unchanged");
|
||||
require(!supplemental.suggest(L"релиз ", 1, layouts, options),
|
||||
"valid Russian release word stays unchanged");
|
||||
options.autoMaxRank = 50000;
|
||||
require(!supplemental.suggest(L"релыз ", 1, layouts, options),
|
||||
"supplemental vocabulary respects explicit frequency limit");
|
||||
options.autoWords[L"uk"] = {L"релізик"};
|
||||
options.autoMaxRank = 1;
|
||||
auto custom = supplemental.suggest(L"релызик ", 1, layouts, options);
|
||||
require(custom && custom->text == L"релізик " && custom->target == 2,
|
||||
"personal word enables correction without editing dictionary files");
|
||||
require(!supplemental.suggest(L"релізик ", 2, layouts, options),
|
||||
"personal word is protected from correction");
|
||||
options.autoNever = {L"релызик"};
|
||||
require(!supplemental.suggest(L"релызик ", 1, layouts, options),
|
||||
"never-correct list takes precedence over personal word");
|
||||
options.autoNever.clear();
|
||||
options.cycle = {L"en", L"ru"};
|
||||
require(!supplemental.suggest(L"релызик ", 1, layouts, options),
|
||||
"personal dictionary respects disabled target layouts");
|
||||
}
|
||||
rejects([&] { missing.configure(L"missing-dictionaries", {L"en"}); }, "missing dictionary rejected");
|
||||
require(ks::convertTo(L"ghbdtn", layouts, 1, 0) == L"привет", "hint conversion");
|
||||
require(ks::convertTo(L"привет", layouts, 1, 1) == L"привет", "same source is unchanged");
|
||||
@@ -335,6 +366,25 @@ int main(int argc, char **argv)
|
||||
auto temp = std::filesystem::temp_directory_path() /
|
||||
(L"KSwitcher-tests-" + std::to_wstring(GetCurrentProcessId()));
|
||||
std::filesystem::create_directories(temp);
|
||||
{
|
||||
auto folder = temp / L"dictionaries";
|
||||
std::filesystem::create_directories(folder);
|
||||
auto put = [&](const wchar_t *name, const std::wstring &text)
|
||||
{
|
||||
auto data = ks::utf8(text);
|
||||
ks::atomicWrite(folder / name, ks::Bytes(data.begin(), data.end()));
|
||||
};
|
||||
put(L"en.txt", L"zoo\t3\nhello\t99\nhello\t1\n");
|
||||
put(L"uk.txt", L"дім\t3\n");
|
||||
ks::AutoCorrector edited;
|
||||
edited.configure(folder, {L"en", L"uk"});
|
||||
auto options = ks::Settings{};
|
||||
options.cycle = {L"en", L"uk"};
|
||||
options.autoMaxRank = 1;
|
||||
auto correction = edited.suggest(L"руддщ ", 2, layouts, options);
|
||||
require(correction && correction->text == L"hello ",
|
||||
"unsorted dictionaries and duplicates load using lowest duplicate rank");
|
||||
}
|
||||
ks::Pixels pixels{2, 1, {10, 20, 30, 255, 40, 50, 60, 255}};
|
||||
ks::Clip firstImage{{ks::imageDib(pixels), {0, L"Ole Private Data", {1, 2, 3}}}};
|
||||
auto thumbnail = ks::decodeImage(firstImage, 1, 1);
|
||||
@@ -384,11 +434,16 @@ int main(int argc, char **argv)
|
||||
settings.autoPrefixChars = L"(#";
|
||||
settings.autoSuffixChars = L");%";
|
||||
settings.autoNever = {L"myWord"};
|
||||
settings.autoWords = {{L"uk", {L"релізик"}}, {L"en", {L"kswitcher"}}};
|
||||
settings.autoExcluded = {L"Code.exe"};
|
||||
settings.cycle = {L"en", L"uk"};
|
||||
settings.snippets = {{L";address", L"Line 1\r\n{cursor}Line 2"}};
|
||||
ks::saveSettings(temp / L"settings.json", settings);
|
||||
auto restored = ks::loadSettings(temp / L"settings.json", {});
|
||||
require(restored.autoWords == settings.autoWords, "personal dictionaries survive settings roundtrip");
|
||||
auto invalidWords = settings;
|
||||
invalidWords.autoWords[L"uk"] = {L"hello"};
|
||||
rejects([&] { ks::validateSettings(invalidWords); }, "personal dictionary rejects wrong language letters");
|
||||
require(ks::encodeSettings(ks::decodeSettings(ks::encodeSettings(settings), {})) == ks::encodeSettings(settings),
|
||||
"configurator snapshot survives serialization without changing the concurrency token");
|
||||
rejects([&] { ks::decodeSettings(ks::Bytes{'{', '}'}, {}); },
|
||||
|
||||
Reference in New Issue
Block a user