Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ItemGroup>
<!-- Source: https://github.com/lunet-io/markdig/ -->
<ProjectReference Include="../System.Management.Automation/System.Management.Automation.csproj" />
<PackageReference Include="Markdig.Signed" Version="0.15.3" />
<PackageReference Include="Markdig.Signed" Version="0.15.4" />
</ItemGroup>

</Project>
26 changes: 13 additions & 13 deletions test/powershell/Language/Operators/ReplaceOperator.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,52 @@ Describe "Replace Operator" -Tags CI {
Context "Replace operator" {
It "Replace operator can replace string values using regular expressions" {
$res = "Get-Process" -replace "Get", "Stop"
$res | Should BeExactly "Stop-Process"
$res | Should -BeExactly "Stop-Process"

$res = "image.gif" -replace "\.gif$",".jpg"
$res | Should BeExactly "image.jpg"
$res | Should -BeExactly "image.jpg"
}

It "Replace operator can be case-insensitive and case-sensitive" {
$res = "book" -replace "B","C"
$res | Should BeExactly "Cook"
$res | Should -BeExactly "Cook"

$res = "book" -ireplace "B","C"
$res | Should BeExactly "Cook"
$res | Should -BeExactly "Cook"

$res = "book" -creplace "B","C"
$res | Should BeExactly "book"
$res | Should -BeExactly "book"
}

It "Replace operator can take 2 arguments, a mandatory pattern, and an optional substitution" {
$res = "PowerPoint" -replace "Point","Shell"
$res | Should BeExactly "PowerShell"
$res | Should -BeExactly "PowerShell"

$res = "PowerPoint" -replace "Point"
$res | Should BeExactly "Power"
$res | Should -BeExactly "Power"
}
}

Context "Replace operator substitutions" {
It "Replace operator supports numbered substitution groups using ```$n" {
$res = "domain.example" -replace ".*\.(\w+)$","Tld of '`$0' is - '`$1'"
$res | Should BeExactly "Tld of 'domain.example' is - 'example'"
$res | Should -BeExactly "Tld of 'domain.example' is - 'example'"
}

It "Replace operator supports named substitution groups using ```${name}" {
$res = "domain.example" -replace ".*\.(?<tld>\w+)$","`${tld}"
$res | Should BeExactly "example"
$res | Should -BeExactly "example"
}

It "Replace operator can take a ScriptBlock in place of a substitution string" {
$res = "ID ABC123" -replace "\b[A-C]+", {return "X" * $_[0].Value.Length}
$res | Should BeExactly "ID XXX123"
$res = "ID ABC123" -replace "\b[A-C]+", {return "X" * $_.Value.Length}
$res | Should -BeExactly "ID XXX123"
}

It "Replace operator can take a MatchEvaluator in place of a substitution string" {
$matchEvaluator = {return "X" * $args[0].Value.Length} -as [System.Text.RegularExpressions.MatchEvaluator]
$res = "ID ABC123" -replace "\b[A-C]+", $matchEvaluator
$res | Should BeExactly "ID XXX123"
$res | Should -BeExactly "ID XXX123"
}

It "Replace operator can take a static PSMethod in place of a substitution string" {
Expand All @@ -61,7 +61,7 @@ Describe "Replace Operator" -Tags CI {
}
$substitutionMethod = [R]::Replace
$res = "ID 0000123" -replace "\b0+", $substitutionMethod
$res | Should BeExactly "ID XXXX123"
$res | Should -BeExactly "ID XXXX123"
}
}
}