Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Unicode issue in Contain and ContainExactly. #378

Merged
merged 1 commit into from
Aug 13, 2015
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
12 changes: 9 additions & 3 deletions Functions/Assertions/Contain.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
Set-StrictMode -Version Latest
Set-StrictMode -Version Latest

InModuleScope Pester {
Describe "PesterContain" {
Context "when testing file contents" {
Setup -File "test.txt" "this is line 1`nrush is awesome"
Setup -File "test.txt" "this is line 1`nrush is awesome`nAnd this is Unicode: ☺"

It "returns true if the file contains the specified content" {
Test-PositiveAssertion (PesterContain "$TestDrive\test.txt" "rush")
}

It "returns true if the file contains the specified content with different case" {
Test-PositiveAssertion (PesterContain "$TestDrive\test.txt" "RUSH")
}

It "returns false if the file does not contain the specified content" {
Test-NegativeAssertion (PesterContain "$TestDrive\test.txt" "slime")
}

It "returns true if the file contains the specified UTF8 content" {
Test-PositiveAssertion (PesterContain "$TestDrive\test.txt" "☺")
}
}
}
}
}
2 changes: 1 addition & 1 deletion Functions/Assertions/Contain.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

function PesterContain($file, $contentExpecation) {
return ((Get-Content $file) -match $contentExpecation)
return ((Get-Content -Encoding UTF8 $file) -match $contentExpecation)
}

function PesterContainFailureMessage($file, $contentExpecation) {
Expand Down
8 changes: 6 additions & 2 deletions Functions/Assertions/ContainExactly.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
Set-StrictMode -Version Latest
Set-StrictMode -Version Latest

InModuleScope Pester {
Describe "PesterContainExactly" {
Context "when testing file contents" {
Setup -File "test.txt" "this is line 1`nPester is awesome"
Setup -File "test.txt" "this is line 1`nPester is awesome`nAnd this is Unicode: ☺"
It "returns true if the file contains the specified content exactly" {
Test-PositiveAssertion (PesterContainExactly "$TestDrive\test.txt" "Pester")
}

It "returns false if the file does not contain the specified content exactly" {
Test-NegativeAssertion (PesterContainExactly "$TestDrive\test.txt" "pESTER")
}

It "returns true if the file contains the specified Unicode content exactyle" {
Test-PositiveAssertion (PesterContainExactly "$TestDrive\test.txt" "☺")
}
}
}
}
3 changes: 1 addition & 2 deletions Functions/Assertions/ContainExactly.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

function PesterContainExactly($file, $contentExpecation) {
return ((Get-Content $file) -cmatch $contentExpecation)
return ((Get-Content -Encoding UTF8 $file) -cmatch $contentExpecation)
}

function PesterContainExactlyFailureMessage($file, $contentExpecation) {
Expand Down