Skip to content

文字列検索の今の動きをテストで固定する - #2869

Merged
berryzplus merged 1 commit into
sakura-editor:masterfrom
hpmy-dev:feature/search_string_tests
Nov 17, 2026
Merged

berryzplus merged 1 commit into
sakura-editor:masterfrom
hpmy-dev:feature/search_string_tests

Conversation

@hpmy-dev

Copy link
Copy Markdown
Contributor

refs #2865

文字列検索(CSearchAgent::SearchString()・CSearchStringPattern::SetPattern())を作り直す前に、今の動きをテストで固定します。#2865 の対応 1 です。

テストを足すだけで、製品コードは変えていません。

変更内容

test-csearchagent.cpp にテストを 13 件足します。Grep・Grep 置換が使う CLineMatchFinder を通して SearchString() を呼びます。

今の SearchString() にはループが 2 つあるので(「区別しない、または 6 文字以上」と「区別する、かつ 5 文字以下」)、短い検索語と長い検索語の組で両方を通します。

テスト 固定する動き
StringMatchCaseShortKey 区別する・5 文字以下。行の先頭・途中・行末
StringMatchCaseLongKey 区別する・6 文字以上。同上
StringIgnoreCaseShortAndLongKey 区別しない。検索語と行のどちらが大文字でも見つかる
StringMatchCaseRejectsDifferentCase 区別する。大文字小文字が違う所は見つからない
StringKeyLongerThanLineOrEmpty 検索語が行より長い・行が空・検索語が空
StringStartNearLineEnd 探し始める位置から検索語が収まらない
StringSingleCharKey 検索語が 1 文字
StringCharsSharingSkipTableSlot 読み飛ばす幅の表で同じ場所を使う文字(「あ」と「乂」)
StringLineWithoutTerminator 行の後ろに終端の NUL が無い
SetPatternAgainChangesCase 設定し直すと、区別する・しないが切り替わる
SetPatternAgainChangesKind 設定し直すと、文字列・正規表現・単語単位が切り替わる
SetPatternRemembersKeyWhenCompileFails 正規表現のコンパイルに失敗しても、検索語と条件を覚えている
CompileRegexpTest.EmptyReplacePattern 空の置換後文字列を引き継ぐ

StringLineWithoutTerminator は、後で「行の 1 つ先を読まない」形に直したときに、結果が変わらないことを見るためのものです。
今のコードは一致しなかった候補の 1 つ先の文字を読むので、長い文字列の前半を行として渡し、読む先が文字列リテラルの中に収まるようにしています。

テスト

  • Win32 Debug: CLineMatchFinderTest.*・CompileRegexpTest.* の 31 件が成功(足した 13 件を含む)

@github-actions

Copy link
Copy Markdown

Test Results

2 044 tests  +13   2 044 ✅ +13   11m 15s ⏱️ - 1m 0s
  176 suites ± 0       0 💤 ± 0 
    1 files   ± 0       0 ❌ ± 0 

Results for commit b4b0e6b. ± Comparison against base commit ff6be3d.

@sonarqubecloud

Copy link
Copy Markdown

@berryzplus berryzplus left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

対応ありがとうございます。

ASSERT_THAT(SetKey(L"aBc", false, false, false), IsTrue());
EXPECT_THAT(FindAll(L"ABC xabCx Abc"), ElementsAre(0, 3, 5, 3, 10, 3));
ASSERT_THAT(SetKey(L"aBcDeF", false, false, false), IsTrue());
EXPECT_THAT(FindAll(L"ABCDEF xabcdefx AbCdEf"), ElementsAre(0, 6, 8, 6, 16, 6));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

コピペで作ってると思うんですが
ASSERT_ 失敗したときテストケース実行は終了する
EXPECT_ 失敗してもテストケースは続行する
という違いがあるので、あとでニャーニャー言う民が出るかもです。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ご確認ありがとうございます。
次の対応で、修正してしまいます。

@berryzplus
berryzplus merged commit 975d815 into sakura-editor:master Nov 17, 2026
17 checks passed
@hpmy-dev
hpmy-dev deleted the feature/search_string_tests branch November 19, 2026 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants