Skip to content

Commit 0360008

Browse files
committed
Update tests to use -OldText instead of -Contains for Update-MatchInFile
1 parent 08396a9 commit 0360008

10 files changed

+62
-62
lines changed

Tests/Integration/BlankLineSeparation.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Blank Line Separation Tests
1+
# Blank Line Separation Tests
22
# コンテキスト行とサマリ行の間に空行が挿入されることをテストする
33

44
#Requires -Modules @{ ModuleName="Pester"; ModuleVersion="5.0.0" }
@@ -119,7 +119,7 @@ Describe "Blank Line Separation Between Context and Summary" {
119119
}
120120

121121
It "マッチ置換時、コンテキストとサマリの間に空行がある" {
122-
$output = Update-MatchInFile -Path $script:testFile -Contains "old value" -Replacement "new value" 6>&1 | Out-String
122+
$output = Update-MatchInFile -Path $script:testFile -OldText "old value" -Replacement "new value" 6>&1 | Out-String
123123

124124
$lines = $output -split "`r?`n"
125125

Tests/Integration/Cmdlets/Show-TextFile.Advanced.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Describe "Show-TextFile - Context Display and ANSI Highlighting Tests" {
1+
Describe "Show-TextFile - Context Display and ANSI Highlighting Tests" {
22
BeforeAll {
33
$script:testFile = [System.IO.Path]::GetTempFileName()
44
}
@@ -255,7 +255,7 @@ Describe "LineRange - Negative Values Support (End of File)" {
255255
Context "Update-MatchInFile での負の LineRange" {
256256
It "-LineRange 5,-1 で5行目から最後までの範囲で置換" {
257257
Set-Content -Path $script:testFile -Value $script:content -Encoding UTF8
258-
Update-MatchInFile -Path $script:testFile -LineRange 5,-1 -Contains "Line" -Replacement "Row"
258+
Update-MatchInFile -Path $script:testFile -LineRange 5,-1 -OldText "Line" -Replacement "Row"
259259
$result = Get-Content $script:testFile
260260

261261
# 1-4行目は変更なし

Tests/Integration/Cmdlets/Update-MatchInFile.AdditionalEdgeCases.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Describe "Update-MatchInFile - Additional Edge Cases" {
6868
$testFile = Join-Path $script:testDir "newline-contains.txt"
6969
Set-Content -Path $testFile -Value @("Line 1", "Line 2", "Line 3")
7070

71-
{ Update-MatchInFile -Path $testFile -Contains "Line 1`nLine 2" -Replacement "Test" -ErrorAction Stop } |
71+
{ Update-MatchInFile -Path $testFile -OldText "Line 1`nLine 2" -Replacement "Test" -ErrorAction Stop } |
7272
Should -Throw "*cannot contain newline*"
7373
}
7474
}

Tests/Integration/Cmdlets/Update-MatchInFile.Integration.Tests.ps1

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Update-MatchInFile.Tests.ps1
1+
# Update-MatchInFile.Tests.ps1
22
# Update-MatchInFile コマンドレットの統合テスト
33

44
#Requires -Modules @{ ModuleName="Pester"; ModuleVersion="5.0.0" }
@@ -31,26 +31,26 @@ Describe "Update-MatchInFile Integration Tests" {
3131

3232
Context "テキストマッチによる置換(Contains)" {
3333
It "指定したテキストを含む部分を置換できる" {
34-
Update-MatchInFile -Path $script:testFile -Contains "localhost" -Replacement "production.example.com"
34+
Update-MatchInFile -Path $script:testFile -OldText "localhost" -Replacement "production.example.com"
3535
$result = Get-Content $script:testFile
3636
$result[0] | Should -Be "Server: production.example.com"
3737
}
3838

3939
It "複数行にマッチする場合、すべて置換される" {
40-
Update-MatchInFile -Path $script:testFile -Contains "true" -Replacement "false"
40+
Update-MatchInFile -Path $script:testFile -OldText "true" -Replacement "false"
4141
$result = Get-Content $script:testFile
4242
$result[4] | Should -Be "Debug: false"
4343
}
4444

4545
It "マッチしない場合、何も変更されない" {
4646
$originalContent = Get-Content $script:testFile
47-
Update-MatchInFile -Path $script:testFile -Contains "NonExistentText" -Replacement "NewValue"
47+
Update-MatchInFile -Path $script:testFile -OldText "NonExistentText" -Replacement "NewValue"
4848
$result = Get-Content $script:testFile
4949
$result | Should -Be $originalContent
5050
}
5151

5252
It "大文字小文字を区別する(case-sensitive)" {
53-
Update-MatchInFile -Path $script:testFile -Contains "LOCALHOST" -Replacement "server.local"
53+
Update-MatchInFile -Path $script:testFile -OldText "LOCALHOST" -Replacement "server.local"
5454
$result = Get-Content $script:testFile
5555
$result[0] | Should -Be "Server: localhost" # 大文字とマッチしないため変更されない
5656
}
@@ -94,7 +94,7 @@ Describe "Update-MatchInFile Integration Tests" {
9494

9595
Context "範囲内での置換" {
9696
It "LineRange と Contains を組み合わせられる" {
97-
Update-MatchInFile -Path $script:testFile -LineRange 1,3 -Contains "admin" -Replacement "superuser"
97+
Update-MatchInFile -Path $script:testFile -LineRange 1,3 -OldText "admin" -Replacement "superuser"
9898
$result = Get-Content $script:testFile
9999
$result[2] | Should -Be "Username: superuser"
100100
# 範囲外は変更されない
@@ -141,7 +141,7 @@ Describe "Update-MatchInFile Integration Tests" {
141141
Context "特殊文字の処理" {
142142
It "特殊文字を含むテキストを置換できる" {
143143
Set-Content -Path $script:testFile -Value @("Price: $100", "Discount: 10%") -Encoding UTF8
144-
Update-MatchInFile -Path $script:testFile -Contains '$100' -Replacement '$200'
144+
Update-MatchInFile -Path $script:testFile -OldText '$100' -Replacement '$200'
145145
$result = Get-Content $script:testFile
146146
$result[0] | Should -Be "Price: $200"
147147
}
@@ -158,7 +158,7 @@ Describe "Update-MatchInFile Integration Tests" {
158158
It "UTF-8ファイルを正しく処理できる" {
159159
$content = "設定: 日本語"
160160
Set-Content -Path $script:testFile -Value $content -Encoding UTF8
161-
Update-MatchInFile -Path $script:testFile -Contains "日本語" -Replacement "English" -Encoding UTF8
161+
Update-MatchInFile -Path $script:testFile -OldText "日本語" -Replacement "English" -Encoding UTF8
162162
$result = Get-Content $script:testFile -Encoding UTF8
163163
$result | Should -Be "設定: English"
164164
}
@@ -173,14 +173,14 @@ Describe "Update-MatchInFile Integration Tests" {
173173

174174
Context "バックアップ機能" {
175175
It "-Backup を指定するとバックアップファイルが作成される" {
176-
Update-MatchInFile -Path $script:testFile -Contains "localhost" -Replacement "newhost" -Backup
176+
Update-MatchInFile -Path $script:testFile -OldText "localhost" -Replacement "newhost" -Backup
177177
$backupFiles = Get-ChildItem -Path (Split-Path $script:testFile) -Filter "$([System.IO.Path]::GetFileName($script:testFile))*.bak"
178178
$backupFiles.Count | Should -BeGreaterThan 0
179179
}
180180

181181
It "バックアップファイルに元の内容が保存される" {
182182
$originalContent = Get-Content $script:testFile
183-
Update-MatchInFile -Path $script:testFile -Contains "localhost" -Replacement "newhost" -Backup
183+
Update-MatchInFile -Path $script:testFile -OldText "localhost" -Replacement "newhost" -Backup
184184
$backupFile = Get-ChildItem -Path (Split-Path $script:testFile) -Filter "$([System.IO.Path]::GetFileName($script:testFile))*.bak" | Select-Object -First 1
185185
$backupContent = Get-Content $backupFile.FullName
186186
$backupContent | Should -Be $originalContent
@@ -190,25 +190,25 @@ Describe "Update-MatchInFile Integration Tests" {
190190
Context "WhatIf と Confirm" {
191191
It "-WhatIf を指定すると実際には変更しない" {
192192
$originalContent = Get-Content $script:testFile
193-
Update-MatchInFile -Path $script:testFile -Contains "localhost" -Replacement "newhost" -WhatIf
193+
Update-MatchInFile -Path $script:testFile -OldText "localhost" -Replacement "newhost" -WhatIf
194194
$result = Get-Content $script:testFile
195195
$result | Should -Be $originalContent
196196
}
197197
}
198198

199199
Context "エラーハンドリング" {
200200
It "存在しないファイルでエラーになる" {
201-
{ Update-MatchInFile -Path "C:\NonExistent\file.txt" -Contains "test" -Replacement "new" -ErrorAction Stop } |
201+
{ Update-MatchInFile -Path "C:\NonExistent\file.txt" -OldText "test" -Replacement "new" -ErrorAction Stop } |
202202
Should -Throw
203203
}
204204

205205
It "Contains と Pattern を同時に指定するとエラーになる" {
206-
{ Update-MatchInFile -Path $script:testFile -Contains "test" -Pattern "test" -Replacement "new" -ErrorAction Stop } |
206+
{ Update-MatchInFile -Path $script:testFile -OldText "test" -Pattern "test" -Replacement "new" -ErrorAction Stop } |
207207
Should -Throw
208208
}
209209

210210
It "Replacement を指定しないとエラーになる" {
211-
{ Update-MatchInFile -Path $script:testFile -Contains "test" -ErrorAction Stop } |
211+
{ Update-MatchInFile -Path $script:testFile -OldText "test" -ErrorAction Stop } |
212212
Should -Throw
213213
}
214214

@@ -224,7 +224,7 @@ Describe "Update-MatchInFile Integration Tests" {
224224
Set-Content -Path $file2 -Value "Server: localhost"
225225

226226
try {
227-
Get-Item @($script:testFile, $file2) | Update-MatchInFile -Contains "localhost" -Replacement "production"
227+
Get-Item @($script:testFile, $file2) | Update-MatchInFile -OldText "localhost" -Replacement "production"
228228
$result1 = Get-Content $script:testFile
229229
$result2 = Get-Content $file2
230230
$result1[0] | Should -Be "Server: production"
@@ -238,7 +238,7 @@ Describe "Update-MatchInFile Integration Tests" {
238238
Context "空文字列による削除(Empty Replacement)" {
239239
It "Contains + 空文字列でマッチしたテキストを削除できる" {
240240
Set-Content -Path $script:testFile -Value "Server=localhost:8080" -Encoding UTF8
241-
Update-MatchInFile -Path $script:testFile -Contains ":8080" -Replacement ""
241+
Update-MatchInFile -Path $script:testFile -OldText ":8080" -Replacement ""
242242
$result = Get-Content $script:testFile -Raw
243243
$result.Trim() | Should -Be "Server=localhost"
244244
}
@@ -275,15 +275,15 @@ Describe "Update-MatchInFile Integration Tests" {
275275
It "空文字列削除後もエンコーディングが保持される" {
276276
$content = "日本語テキスト:削除対象"
277277
Set-Content -Path $script:testFile -Value $content -Encoding UTF8
278-
Update-MatchInFile -Path $script:testFile -Contains ":削除対象" -Replacement ""
278+
Update-MatchInFile -Path $script:testFile -OldText ":削除対象" -Replacement ""
279279
$result = Get-Content $script:testFile -Raw -Encoding UTF8
280280
$result.Trim() | Should -Be "日本語テキスト"
281281
}
282282
}
283283

284284
Context "Replacement パラメータの検証" {
285285
It "Replacement を指定しない(null)場合、Contains でエラーになる" {
286-
{ Update-MatchInFile -Path $script:testFile -Contains "test" } | Should -Throw
286+
{ Update-MatchInFile -Path $script:testFile -OldText "test" } | Should -Throw
287287
}
288288

289289
It "Replacement を指定しない(null)場合、Pattern でエラーになる" {
@@ -292,7 +292,7 @@ Describe "Update-MatchInFile Integration Tests" {
292292

293293
It "Replacement に空文字列を指定した場合はエラーにならない(削除として動作)" {
294294
Set-Content -Path $script:testFile -Value "Test123" -Encoding UTF8
295-
{ Update-MatchInFile -Path $script:testFile -Contains "123" -Replacement "" } |
295+
{ Update-MatchInFile -Path $script:testFile -OldText "123" -Replacement "" } |
296296
Should -Not -Throw
297297
$result = Get-Content $script:testFile -Raw
298298
$result.Trim() | Should -Be "Test"

Tests/Integration/Cmdlets/UpdateMatchInFile.Integration.Tests.ps1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Update-MatchInFile コマンドレットの統合テスト
1+
# Update-MatchInFile コマンドレットの統合テスト
22

33
#Requires -Modules @{ ModuleName="Pester"; ModuleVersion="5.0.0" }
44

@@ -29,7 +29,7 @@ Describe "Update-MatchInFile Integration Tests" {
2929
Set-Content -Path $script:testFile -Value "Server=localhost:8080" -Encoding UTF8 -NoNewline
3030

3131
# Act
32-
Update-MatchInFile -Path $script:testFile -Contains ":8080" -Replacement ""
32+
Update-MatchInFile -Path $script:testFile -OldText ":8080" -Replacement ""
3333

3434
# Assert
3535
$result = Get-Content -Path $script:testFile -Raw
@@ -53,7 +53,7 @@ Describe "Update-MatchInFile Integration Tests" {
5353
Set-Content -Path $script:testFile -Value "test1 DEBUG test2 DEBUG test3" -Encoding UTF8 -NoNewline
5454

5555
# Act
56-
Update-MatchInFile -Path $script:testFile -Contains "DEBUG " -Replacement ""
56+
Update-MatchInFile -Path $script:testFile -OldText "DEBUG " -Replacement ""
5757

5858
# Assert
5959
$result = Get-Content -Path $script:testFile -Raw
@@ -79,7 +79,7 @@ Describe "Update-MatchInFile Integration Tests" {
7979
Set-Content -Path $script:testFile -Value "test content" -Encoding UTF8 -NoNewline
8080

8181
# Act & Assert
82-
{ Update-MatchInFile -Path $script:testFile -Contains "test" } | Should -Throw
82+
{ Update-MatchInFile -Path $script:testFile -OldText "test" } | Should -Throw
8383
}
8484

8585
It "Pattern を指定して Replacement を省略するとエラーになる" {
@@ -105,7 +105,7 @@ Describe "Update-MatchInFile Integration Tests" {
105105
Set-Content -Path $script:testFile -Value "日本語テキスト DEBUG 終了" -Encoding UTF8 -NoNewline
106106

107107
# Act
108-
Update-MatchInFile -Path $script:testFile -Contains "DEBUG " -Replacement ""
108+
Update-MatchInFile -Path $script:testFile -OldText "DEBUG " -Replacement ""
109109

110110
# Assert
111111
$result = Get-Content -Path $script:testFile -Raw -Encoding UTF8
@@ -118,7 +118,7 @@ Describe "Update-MatchInFile Integration Tests" {
118118
[System.IO.File]::WriteAllText($script:testFile, $content, [System.Text.Encoding]::GetEncoding("Shift_JIS"))
119119

120120
# Act
121-
Update-MatchInFile -Path $script:testFile -Contains "DEBUG " -Replacement ""
121+
Update-MatchInFile -Path $script:testFile -OldText "DEBUG " -Replacement ""
122122

123123
# Assert
124124
$result = [System.IO.File]::ReadAllText($script:testFile, [System.Text.Encoding]::GetEncoding("Shift_JIS"))
@@ -133,7 +133,7 @@ Describe "Update-MatchInFile Integration Tests" {
133133
Set-Content -Path $script:testFile -Value @("Line1", "DEBUG", "Line2") -Encoding UTF8
134134

135135
# Act
136-
Update-MatchInFile -Path $script:testFile -Contains "DEBUG" -Replacement ""
136+
Update-MatchInFile -Path $script:testFile -OldText "DEBUG" -Replacement ""
137137

138138
# Assert
139139
$result = Get-Content -Path $script:testFile -Raw
@@ -146,7 +146,7 @@ Describe "Update-MatchInFile Integration Tests" {
146146
[System.IO.File]::WriteAllText($script:testFile, "Line1`r`nDEBUG`r`nLine2", [System.Text.Encoding]::UTF8)
147147

148148
# Act
149-
Update-MatchInFile -Path $script:testFile -Contains "DEBUG" -Replacement ""
149+
Update-MatchInFile -Path $script:testFile -OldText "DEBUG" -Replacement ""
150150

151151
# Assert
152152
$result = Get-Content -Path $script:testFile -Raw

Tests/Integration/ContextDisplay.EdgeCase.Tests.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Additional Context Display Edge Case Tests
1+
# Additional Context Display Edge Case Tests
22
# v1.3.0以降のコンテキスト表示機能の追加エッジケーステスト
33

44
#Requires -Modules @{ ModuleName="Pester"; ModuleVersion="5.0.0" }
@@ -21,7 +21,7 @@ Describe "Context Display Edge Case Tests" {
2121
$content = @("Line 1: match", "Line 2", "Line 3")
2222
Set-Content -Path $testFile -Value $content -Encoding UTF8
2323

24-
$output = Update-MatchInFile -Path $testFile -Contains "match" -Replacement "REPLACED" -InformationAction Continue 6>&1 | Out-String
24+
$output = Update-MatchInFile -Path $testFile -OldText "match" -Replacement "REPLACED" -InformationAction Continue 6>&1 | Out-String
2525

2626
# 先頭行でも後続2行のコンテキストが表示される
2727
$output | Should -Match "Line 2"
@@ -33,7 +33,7 @@ Describe "Context Display Edge Case Tests" {
3333
$content = @("Line 1", "Line 2", "Line 3: match")
3434
Set-Content -Path $testFile -Value $content -Encoding UTF8
3535

36-
$output = Update-MatchInFile -Path $testFile -Contains "match" -Replacement "REPLACED" -InformationAction Continue 6>&1 | Out-String
36+
$output = Update-MatchInFile -Path $testFile -OldText "match" -Replacement "REPLACED" -InformationAction Continue 6>&1 | Out-String
3737

3838
# 末尾行でも前方2行のコンテキストが表示される
3939
$output | Should -Match "Line 1"
@@ -44,7 +44,7 @@ Describe "Context Display Edge Case Tests" {
4444
$testFile = Join-Path $script:testDir "edge3.txt"
4545
Set-Content -Path $testFile -Value "Single line: match" -Encoding UTF8
4646

47-
$output = Update-MatchInFile -Path $testFile -Contains "match" -Replacement "REPLACED" -InformationAction Continue 6>&1 | Out-String
47+
$output = Update-MatchInFile -Path $testFile -OldText "match" -Replacement "REPLACED" -InformationAction Continue 6>&1 | Out-String
4848

4949
# 1行でもコンテキスト表示が機能する
5050
$output | Should -Match "REPLACED"
@@ -84,7 +84,7 @@ Describe "Context Display Edge Case Tests" {
8484
$content = 1..10 | ForEach-Object { "Line $_ - test" }
8585
Set-Content -Path $testFile -Value $content -Encoding UTF8
8686

87-
$output = Update-MatchInFile -Path $testFile -LineRange 3,7 -Contains "test" -Replacement "updated" -InformationAction Continue 6>&1 | Out-String
87+
$output = Update-MatchInFile -Path $testFile -LineRange 3,7 -OldText "test" -Replacement "updated" -InformationAction Continue 6>&1 | Out-String
8888

8989
# LineRange内のマッチのみ表示される
9090
$output | Should -Match "Line 3"
@@ -103,7 +103,7 @@ Describe "Context Display Edge Case Tests" {
103103
$content[5] = "Line 6: match"
104104
Set-Content -Path $testFile -Value $content -Encoding UTF8
105105

106-
$output = Update-MatchInFile -Path $testFile -Contains "match" -Replacement "REPLACED" -InformationAction Continue 6>&1 | Out-String
106+
$output = Update-MatchInFile -Path $testFile -OldText "match" -Replacement "REPLACED" -InformationAction Continue 6>&1 | Out-String
107107

108108
# ギャップ1行なのでマージされる
109109
$output | Should -Match "Line 4"
@@ -119,7 +119,7 @@ Describe "Context Display Edge Case Tests" {
119119
$content[11] = "Line 12: match" # ギャップは6,7,8,9,10,11行目の6行
120120
Set-Content -Path $testFile -Value $content -Encoding UTF8
121121

122-
$output = Update-MatchInFile -Path $testFile -Contains "match" -Replacement "REPLACED" -InformationAction Continue 6>&1 | Out-String
122+
$output = Update-MatchInFile -Path $testFile -OldText "match" -Replacement "REPLACED" -InformationAction Continue 6>&1 | Out-String
123123

124124
# ギャップが大きいので分離される
125125
# 分離マーカー(空行)が含まれる

0 commit comments

Comments
 (0)