From fbb2a56eafb1a6d95e593e25aca132946dd32a58 Mon Sep 17 00:00:00 2001 From: Jia Sui Date: Mon, 31 Aug 2026 15:35:03 +0800 Subject: [PATCH] style: apply clang-format to the new autocorrect tests --- server/src/config/ime_config.cpp | 62 +++++++++------------ server/src/session/engine_input_session.cpp | 3 +- server/tests/src/test_quanpin_scheme.cpp | 57 ++++++++----------- 3 files changed, 50 insertions(+), 72 deletions(-) diff --git a/server/src/config/ime_config.cpp b/server/src/config/ime_config.cpp index 4999e624..361ba3e6 100644 --- a/server/src/config/ime_config.cpp +++ b/server/src/config/ime_config.cpp @@ -182,8 +182,7 @@ class ConfigFileLock SchemeType ParseScheme(const std::string &value); -template -bool TomlFlexibleBool(const Node &node, bool fallback) +template bool TomlFlexibleBool(const Node &node, bool fallback) { if (const auto value = node.template value()) return *value; @@ -670,10 +669,9 @@ bool LoadImeConfig() g_floating_toolbar_enabled = tbl["general"]["floating_toolbar"].value_or(true); // Read the old candidate-only key as a migration fallback. New writes // use the unified key. - g_diagnostic_log_enabled.store( - tbl["general"]["diagnostic_log"].value_or( - tbl["general"]["candidate_window_diagnostic_log"].value_or(false)), - std::memory_order_relaxed); + g_diagnostic_log_enabled.store(tbl["general"]["diagnostic_log"].value_or( + tbl["general"]["candidate_window_diagnostic_log"].value_or(false)), + std::memory_order_relaxed); g_tsf_diagnostic_log_enabled.store(tbl["general"]["tsf_diagnostic_log"].value_or(false), std::memory_order_relaxed); g_floating_toolbar_items.fullwidth = tbl["general"]["floating_toolbar_fullwidth"].value_or(true); @@ -822,8 +820,8 @@ bool LoadImeConfig() for (const auto provider : VoiceInput::AsrProviders()) { const std::string id(provider); - g_voice_input.asr_tokens[id] = VoiceInput::UsableToken( - tbl["voice_input"][VoiceInput::AsrTokenSlotKey(id)].value_or(std::string())); + g_voice_input.asr_tokens[id] = + VoiceInput::UsableToken(tbl["voice_input"][VoiceInput::AsrTokenSlotKey(id)].value_or(std::string())); } { const std::string provider = VoiceInput::NormalizeProviderId(g_voice_input.asr_provider); @@ -849,8 +847,7 @@ bool LoadImeConfig() g_voice_input.doubao_enable_itn = tbl["voice_input"]["doubao_enable_itn"].value_or(true); g_voice_input.doubao_enable_punc = tbl["voice_input"]["doubao_enable_punc"].value_or(true); g_voice_input.doubao_enable_ddc = tbl["voice_input"]["doubao_enable_ddc"].value_or(false); - g_voice_input.doubao_boosting_table_id = - tbl["voice_input"]["doubao_boosting_table_id"].value_or(std::string()); + g_voice_input.doubao_boosting_table_id = tbl["voice_input"]["doubao_boosting_table_id"].value_or(std::string()); g_voice_input.asr_model = tbl["voice_input"]["asr_model"].value_or(std::string()); g_voice_input.polish_provider = tbl["voice_input"]["polish_provider"].value_or(std::string("siliconflow")); g_voice_input.polish_token = tbl["voice_input"]["polish_token"].value_or(std::string()); @@ -858,8 +855,8 @@ bool LoadImeConfig() for (const auto provider : VoiceInput::PolishProviders()) { const std::string id(provider); - g_voice_input.polish_tokens[id] = VoiceInput::UsableToken( - tbl["voice_input"][VoiceInput::PolishTokenSlotKey(id)].value_or(std::string())); + g_voice_input.polish_tokens[id] = + VoiceInput::UsableToken(tbl["voice_input"][VoiceInput::PolishTokenSlotKey(id)].value_or(std::string())); } { const std::string provider = VoiceInput::NormalizeProviderId(g_voice_input.polish_provider); @@ -885,14 +882,11 @@ bool LoadImeConfig() { g_voice_input.polish_prompt_id = "cleanup"; } - g_voice_input.polish_prompt_custom_1 = - tbl["voice_input"]["polish_prompt_custom_1"].value_or(std::string()); + g_voice_input.polish_prompt_custom_1 = tbl["voice_input"]["polish_prompt_custom_1"].value_or(std::string()); if (g_voice_input.polish_prompt_custom_1.empty()) g_voice_input.polish_prompt_custom_1 = g_voice_input.polish_prompt; - g_voice_input.polish_prompt_custom_2 = - tbl["voice_input"]["polish_prompt_custom_2"].value_or(std::string()); - g_voice_input.polish_prompt_custom_3 = - tbl["voice_input"]["polish_prompt_custom_3"].value_or(std::string()); + g_voice_input.polish_prompt_custom_2 = tbl["voice_input"]["polish_prompt_custom_2"].value_or(std::string()); + g_voice_input.polish_prompt_custom_3 = tbl["voice_input"]["polish_prompt_custom_3"].value_or(std::string()); g_voice_input.language = tbl["voice_input"]["language"].value_or(std::string("zh-cn")); // notification_sound is retained as a fallback for configs written by older versions. const bool legacy_notification_sound = tbl["voice_input"]["notification_sound"].value_or(true); @@ -908,8 +902,8 @@ bool LoadImeConfig() g_voice_input.commit_mode = "tsf"; } g_ai_assistant.enabled = tbl["ai_assistant"]["enabled"].value_or(false); - g_ai_assistant.provider = VoiceInput::NormalizeProviderId( - tbl["ai_assistant"]["provider"].value_or(std::string("deepseek"))); + g_ai_assistant.provider = + VoiceInput::NormalizeProviderId(tbl["ai_assistant"]["provider"].value_or(std::string("deepseek"))); if (AiAssistantTokenSlotKey(g_ai_assistant.provider).empty()) g_ai_assistant.provider = "deepseek"; g_ai_assistant.token = tbl["ai_assistant"]["token"].value_or(std::string()); @@ -917,8 +911,8 @@ bool LoadImeConfig() for (const auto provider : AiAssistantProviders()) { const std::string id(provider); - g_ai_assistant.tokens[id] = VoiceInput::UsableToken( - tbl["ai_assistant"][AiAssistantTokenSlotKey(id)].value_or(std::string())); + g_ai_assistant.tokens[id] = + VoiceInput::UsableToken(tbl["ai_assistant"][AiAssistantTokenSlotKey(id)].value_or(std::string())); } { std::string &stored = g_ai_assistant.tokens[g_ai_assistant.provider]; @@ -936,25 +930,21 @@ bool LoadImeConfig() if (g_ai_assistant.prompt_id != "custom_1" && g_ai_assistant.prompt_id != "custom_2" && g_ai_assistant.prompt_id != "custom_3") g_ai_assistant.prompt_id = "custom_1"; - g_ai_assistant.prompt_custom_1 = - tbl["ai_assistant"]["prompt_custom_1"].value_or(std::string()); + g_ai_assistant.prompt_custom_1 = tbl["ai_assistant"]["prompt_custom_1"].value_or(std::string()); if (g_ai_assistant.prompt_custom_1.empty()) g_ai_assistant.prompt_custom_1 = legacy_ai_prompt; - g_ai_assistant.prompt_custom_2 = - tbl["ai_assistant"]["prompt_custom_2"].value_or(std::string()); - g_ai_assistant.prompt_custom_3 = - tbl["ai_assistant"]["prompt_custom_3"].value_or(std::string()); - g_ai_assistant.prompt = g_ai_assistant.prompt_id == "custom_2" ? g_ai_assistant.prompt_custom_2 - : g_ai_assistant.prompt_id == "custom_3" ? g_ai_assistant.prompt_custom_3 - : g_ai_assistant.prompt_custom_1; + g_ai_assistant.prompt_custom_2 = tbl["ai_assistant"]["prompt_custom_2"].value_or(std::string()); + g_ai_assistant.prompt_custom_3 = tbl["ai_assistant"]["prompt_custom_3"].value_or(std::string()); + g_ai_assistant.prompt = g_ai_assistant.prompt_id == "custom_2" ? g_ai_assistant.prompt_custom_2 + : g_ai_assistant.prompt_id == "custom_3" ? g_ai_assistant.prompt_custom_3 + : g_ai_assistant.prompt_custom_1; g_tencent_tmt.enabled = tbl["tencent_tmt"]["enabled"].value_or(true); g_tencent_tmt.secret_id = tbl["tencent_tmt"]["secret_id"].value_or(std::string()); g_tencent_tmt.secret_key = tbl["tencent_tmt"]["secret_key"].value_or(std::string()); g_tencent_tmt.region = tbl["tencent_tmt"]["region"].value_or(std::string("ap-guangzhou")); if (g_tencent_tmt.region.empty()) g_tencent_tmt.region = "ap-guangzhou"; - g_tencent_tmt.target_language = - tbl["tencent_tmt"]["target_language"].value_or(std::string("en")); + g_tencent_tmt.target_language = tbl["tencent_tmt"]["target_language"].value_or(std::string("en")); if (g_tencent_tmt.target_language != "en" && g_tencent_tmt.target_language != "fr" && g_tencent_tmt.target_language != "ja" && g_tencent_tmt.target_language != "es" && g_tencent_tmt.target_language != "ru") @@ -2922,9 +2912,9 @@ bool SetConfiguredAiAssistantString(const std::string &key, const std::string &v g_ai_assistant.prompt_custom_1 = value; if (key == "prompt" || key == "prompt_id" || key.rfind("prompt_custom_", 0) == 0) { - g_ai_assistant.prompt = g_ai_assistant.prompt_id == "custom_2" ? g_ai_assistant.prompt_custom_2 - : g_ai_assistant.prompt_id == "custom_3" ? g_ai_assistant.prompt_custom_3 - : g_ai_assistant.prompt_custom_1; + g_ai_assistant.prompt = g_ai_assistant.prompt_id == "custom_2" ? g_ai_assistant.prompt_custom_2 + : g_ai_assistant.prompt_id == "custom_3" ? g_ai_assistant.prompt_custom_3 + : g_ai_assistant.prompt_custom_1; } if (key == "provider") { diff --git a/server/src/session/engine_input_session.cpp b/server/src/session/engine_input_session.cpp index 49407c49..9c00e971 100644 --- a/server/src/session/engine_input_session.cpp +++ b/server/src/session/engine_input_session.cpp @@ -284,8 +284,7 @@ std::string EngineInputSession::get_pinyin_segmentation_with_cases() const } if (is_japanese()) { - return request().raw_input_with_cases.empty() ? request().raw_input - : request().raw_input_with_cases; + return request().raw_input_with_cases.empty() ? request().raw_input : request().raw_input_with_cases; } if (is_shuangpin() && GetConfiguredShuangpinPreeditMode() == "shuangpin") { diff --git a/server/tests/src/test_quanpin_scheme.cpp b/server/tests/src/test_quanpin_scheme.cpp index dec5f985..5b2b6ef6 100644 --- a/server/tests/src/test_quanpin_scheme.cpp +++ b/server/tests/src/test_quanpin_scheme.cpp @@ -56,7 +56,7 @@ std::filesystem::path CreatePinyinCacheDatabase() } return path; } -} +} // namespace TEST_CASE(QuanpinSchemeSpaceDoesNotResetComposition) { @@ -106,11 +106,7 @@ TEST_CASE(QuanpinSchemeTrailingApostropheIsPreservedInPreeditSegmentation) TEST_CASE(HelpcodeSchemaSelectionLoadsAllSupportedSchemas) { const std::vector> schemas{ - {"lantian", "(KK)"}, - {"ziranma", "(KA)"}, - {"shouyou2_0", "(KV)"}, - {"shouyouplus", "(KE)"}, - {"xiaohe", "(KK)"}, + {"lantian", "(KK)"}, {"ziranma", "(KA)"}, {"shouyou2_0", "(KV)"}, {"shouyouplus", "(KE)"}, {"xiaohe", "(KK)"}, }; for (const auto &[schema, expected] : schemas) @@ -143,9 +139,9 @@ TEST_CASE(QuanpinCandidateCacheKeepsManualSegmentationBoundariesDistinct) { QuanpinDictionary dictionary; const std::string automatic_only_candidate = "__automatic_fan_gan__"; - REQUIRE_EQ(dictionary.insert_word_to_series_cache( - "fangan", automatic_only_candidate, CandidateSource::CloudSuggestion), - QuanpinDictionary::OK); + REQUIRE_EQ( + dictionary.insert_word_to_series_cache("fangan", automatic_only_candidate, CandidateSource::CloudSuggestion), + QuanpinDictionary::OK); const auto automatic_candidates = dictionary.query("fangan", "fan'gan"); REQUIRE(std::any_of(automatic_candidates.begin(), automatic_candidates.end(), @@ -245,19 +241,17 @@ TEST_CASE(QuanpinCandidateCacheDetectsExternalDictionaryWrites) { QuanpinDictionary dictionary(db_path.string()); const auto before = dictionary.query("aoshike", "ao'shi'ke"); - REQUIRE(std::none_of(before.begin(), before.end(), - [](const WordItem &item) { return item.word == "澳鳾科"; })); + REQUIRE(std::none_of(before.begin(), before.end(), [](const WordItem &item) { return item.word == "澳鳾科"; })); sqlite3 *writer = nullptr; REQUIRE_EQ(sqlite3_open(db_path.string().c_str(), &writer), SQLITE_OK); - REQUIRE_EQ(sqlite3_exec(writer, - "INSERT INTO tbl_3_a VALUES('ao''shi''ke','ask','澳鳾科',1)", - nullptr, nullptr, nullptr), SQLITE_OK); + REQUIRE_EQ(sqlite3_exec(writer, "INSERT INTO tbl_3_a VALUES('ao''shi''ke','ask','澳鳾科',1)", nullptr, nullptr, + nullptr), + SQLITE_OK); sqlite3_close(writer); const auto after = dictionary.query("aoshike", "ao'shi'ke"); - REQUIRE(std::any_of(after.begin(), after.end(), - [](const WordItem &item) { return item.word == "澳鳾科"; })); + REQUIRE(std::any_of(after.begin(), after.end(), [](const WordItem &item) { return item.word == "澳鳾科"; })); } std::filesystem::remove(db_path); } @@ -424,8 +418,8 @@ TEST_CASE(QuanpinAutocorrectTableHasNoCollisionsWithLegalPinyin) { const std::string wrong(entry.wrong); REQUIRE(!wrong.empty()); - REQUIRE(!legal.count(wrong)); // a key must never shadow a legal syllable - REQUIRE(legal.count(entry.correct)); // the correction must be a legal syllable + REQUIRE(!legal.count(wrong)); // a key must never shadow a legal syllable + REQUIRE(legal.count(entry.correct)); // the correction must be a legal syllable REQUIRE(wrong_keys.insert(wrong).second); // keys must be unique } REQUIRE(wrong_keys.size() > 1000); @@ -474,8 +468,7 @@ TEST_CASE(QuanpinAutocorrectCutRejectsInputsOutOfScope) TEST_CASE(QuanpinAutocorrectCutRespectsEdgeBudget) { - REQUIRE_EQ(quanpin::join_segments(quanpin::autocorrect_cut("sahngsahngsahng")), - std::string("shang'shang'shang")); + REQUIRE_EQ(quanpin::join_segments(quanpin::autocorrect_cut("sahngsahngsahng")), std::string("shang'shang'shang")); } namespace @@ -489,13 +482,12 @@ std::filesystem::path CreateAutocorrectDatabase() { throw std::runtime_error("Failed to create temporary autocorrect database."); } - const char *sql = - "CREATE TABLE tbl_1_s(key TEXT,jp TEXT,value TEXT,weight INTEGER);" - "CREATE TABLE tbl_2_s(key TEXT,jp TEXT,value TEXT,weight INTEGER);" - "CREATE TABLE tbl_4_s(key TEXT,jp TEXT,value TEXT,weight INTEGER);" - "INSERT INTO tbl_1_s VALUES('shang','s','上',100);" - "INSERT INTO tbl_2_s VALUES('shang''zhi','sz','上至',100);" - "INSERT INTO tbl_4_s VALUES('sa''huang''na''ge','shng','撒谎那个',1000);"; + const char *sql = "CREATE TABLE tbl_1_s(key TEXT,jp TEXT,value TEXT,weight INTEGER);" + "CREATE TABLE tbl_2_s(key TEXT,jp TEXT,value TEXT,weight INTEGER);" + "CREATE TABLE tbl_4_s(key TEXT,jp TEXT,value TEXT,weight INTEGER);" + "INSERT INTO tbl_1_s VALUES('shang','s','上',100);" + "INSERT INTO tbl_2_s VALUES('shang''zhi','sz','上至',100);" + "INSERT INTO tbl_4_s VALUES('sa''huang''na''ge','shng','撒谎那个',1000);"; const int result = sqlite3_exec(db, sql, nullptr, nullptr, nullptr); sqlite3_close(db); if (result != SQLITE_OK) @@ -552,8 +544,7 @@ TEST_CASE(QuanpinDictionaryAutocorrectDisabledKeepsLegacyBehavior) const auto candidates = dictionary.query("sahng", "sa'h'n'g", false); REQUIRE(!candidates.empty()); - REQUIRE(std::none_of(candidates.begin(), candidates.end(), - [](const WordItem &item) { return item.word == "上"; })); + REQUIRE(std::none_of(candidates.begin(), candidates.end(), [](const WordItem &item) { return item.word == "上"; })); REQUIRE(std::any_of(candidates.begin(), candidates.end(), [](const WordItem &item) { return item.word == "撒谎那个"; })); } @@ -569,8 +560,7 @@ TEST_CASE(QuanpinDictionaryAutocorrectLeavesLegalInputsUntouched) const auto plain = dictionary.query("shang", "shang", true); REQUIRE(!plain.empty()); REQUIRE_EQ(plain.front().word, std::string("上")); - REQUIRE(std::none_of(plain.begin(), plain.end(), - [](const WordItem &item) { return item.word == "撒谎那个"; })); + REQUIRE(std::none_of(plain.begin(), plain.end(), [](const WordItem &item) { return item.word == "撒谎那个"; })); const auto manual = dictionary.query("xi'an", "xi'an", true); const auto manual_off = dictionary.query("xi'an", "xi'an", false); @@ -622,7 +612,7 @@ HelpcodeSample FindSplitBucketHelpcode() } return {}; } -} +} // namespace // Mirrors typing a helpcode that filters out the candidates above the AI // suggestion: the suggestion has to move up with them instead of staying pinned @@ -638,8 +628,7 @@ TEST_CASE(SingleHelpcodeReorderKeepsAiSuggestionAheadOfLaterCandidates) WordItem("py", sample.first_matched_b, 8, CandidateSource::Database), }; - const auto result = - HelpcodeUtils::reorder_candidates_with_single_helpcode(base, std::string(1, sample.help_code)); + const auto result = HelpcodeUtils::reorder_candidates_with_single_helpcode(base, std::string(1, sample.help_code)); REQUIRE_EQ(result.size(), base.size()); REQUIRE(result[0].source == CandidateSource::AiSuggestion);