2016-03-04 23:48:30 +01:00
|
|
|
Describe "Compare-Object" {
|
2015-12-28 20:05:48 +01:00
|
|
|
$nl = [Environment]::NewLine
|
2015-12-29 00:59:55 +01:00
|
|
|
$slash = [System.IO.Path]::DirectorySeparatorChar
|
|
|
|
$testDirectory = $HOME + $slash + "testDirectory"
|
|
|
|
$dir = $testDirectory
|
2015-10-06 22:30:51 +02:00
|
|
|
|
|
|
|
New-Item $testDirectory -ItemType directory -Force
|
|
|
|
|
|
|
|
$content1 = "line 1" + $nl + "line 2"
|
|
|
|
$content2 = "line 1" + $nl + "line 2.1"
|
|
|
|
$content3 = "line 1" + $nl + "line 2" + $nl + "line 3"
|
|
|
|
$content4 = "line 1" + $nl + "line 2.1" + $nl + "Line 3"
|
|
|
|
|
|
|
|
$file1 = $testDirectory + $slash + "test1.txt"
|
|
|
|
$file2 = $testDirectory + $slash + "test2.txt"
|
|
|
|
$file3 = $testDirectory + $slash + "test3.txt"
|
|
|
|
$file4 = $testDirectory + $slash + "test4.txt"
|
|
|
|
|
|
|
|
New-Item $file1 -ItemType file -Value $content1 -Force
|
|
|
|
New-Item $file2 -ItemType file -Value $content2 -Force
|
|
|
|
New-Item $file3 -ItemType file -Value $content3 -Force
|
|
|
|
New-Item $file4 -ItemType file -Value $content4 -Force
|
|
|
|
|
|
|
|
Test-Path $testDirectory | Should Be $true
|
|
|
|
|
|
|
|
It "Should be able to compare the same object using the referenceObject and differenceObject switches" {
|
2016-03-04 23:52:27 +01:00
|
|
|
{ Compare-Object -ReferenceObject $(Get-Content $file1) -DifferenceObject $(Get-Content $file2) } | Should Not Throw
|
2015-10-06 22:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should not throw when referenceobject switch is not used" {
|
2016-03-04 23:52:27 +01:00
|
|
|
{ Compare-Object $(Get-Content $file1) -DifferenceObject $(Get-Content $file2) } | Should Not Throw
|
2015-10-06 22:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should not throw when differenceobject switch is not used" {
|
2016-03-04 23:52:27 +01:00
|
|
|
{ Compare-Object -ReferenceObject $(Get-Content $file1) $(Get-Content $file2) } | Should Not Throw
|
2015-10-06 22:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should indicate data that exists only in the reference dataset" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4)
|
2015-10-06 22:30:51 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$actualOutput[1].SideIndicator | Should Be "<="
|
2015-10-06 22:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should indicate data that exists only in the difference dataset" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4)
|
2015-10-06 22:30:51 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$actualOutput[1].SideIndicator | Should Be "<="
|
2015-10-06 22:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should indicate data that exists in both datasets when the includeEqual switch is used" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -IncludeEqual
|
2015-10-06 22:30:51 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$actualOutput.Length | Should Be 4
|
|
|
|
$actualOutput[0].SideIndicator | Should Be "=="
|
|
|
|
$actualOutput[1].SideIndicator | Should Be "=="
|
2015-10-06 22:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should be able to use the casesensitive switch" {
|
2016-03-04 23:52:27 +01:00
|
|
|
{ Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -CaseSensitive } | Should Not Throw
|
2015-10-06 22:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should correctly indicate that different cases are different when the casesensitive switch is used" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$caOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -CaseSensitive
|
|
|
|
$ncaOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4)
|
2015-10-06 22:30:51 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$caOutput.Length | Should Be 4
|
2015-10-06 22:30:51 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$ncaOutput[1].SideIndicator | Should Not Be $caOutput[1].SideIndicator
|
|
|
|
$ncaOutput[2].SideIndicator | Should Not Be $caOutput[2].SideIndicator
|
|
|
|
$ncaOutput[3].SideIndicator | Should Not Be $caOutput[3].SideIndicator
|
2015-10-06 22:30:51 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
It "Should throw when reference set is null" {
|
2016-03-04 23:52:27 +01:00
|
|
|
{ Compare-Object -ReferenceObject $anonexistentvariable -DifferenceObject $(Get-Content $file4) } | Should Throw
|
2015-10-06 22:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should throw when difference set is null" {
|
2016-03-04 23:52:27 +01:00
|
|
|
{ Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $anonexistentvariable } | Should Throw
|
2015-10-06 22:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should give a 0 array when using excludedifferent switch without also using the includeequal switch" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -ExcludeDifferent
|
2015-10-06 22:30:51 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$actualOutput.Length | Should Be 0
|
2015-10-06 22:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should only display equal lines when excludeDifferent switch is used alongside the includeequal switch" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$actualOutput = Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -IncludeEqual -ExcludeDifferent
|
2015-10-06 22:30:51 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$actualOutput.Length | Should Be 2
|
2015-10-06 22:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should be able to pass objects to pipeline using the passthru switch" {
|
2016-03-04 23:52:27 +01:00
|
|
|
{ Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -Passthru | Format-Wide } | Should Not Throw
|
2015-10-06 22:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should be able to specify the property of two objects to compare" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$actualOutput = Compare-Object -ReferenceObject $file3 -DifferenceObject $testDirectory -Property Length
|
2015-10-06 22:30:51 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$actualOutput[0].Length | Should BeGreaterThan 0
|
|
|
|
$actualOutput[1].Length | Should BeGreaterThan 0
|
|
|
|
$actualOutput[0].Length | Should Not Be $actualOutput[1].Length
|
2015-10-06 22:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should be able to specify the syncwindow without error" {
|
2016-03-04 23:52:27 +01:00
|
|
|
{ Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -syncWindow 5 } | Should Not Throw
|
|
|
|
{ Compare-Object -ReferenceObject $(Get-Content $file3) -DifferenceObject $(Get-Content $file4) -syncWindow 8 } | Should Not Throw
|
2015-10-06 22:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
It "Should have the expected output when changing the syncwindow" {
|
2016-03-04 23:52:27 +01:00
|
|
|
$var1 = 1..15
|
|
|
|
$var2 = 15..1
|
2015-10-06 22:30:51 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$actualOutput = Compare-Object -ReferenceObject $var1 -DifferenceObject $var2 -syncWindow 6
|
2015-10-06 22:30:51 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$actualOutput[0].InputObject | Should Be 15
|
|
|
|
$actualOutput[1].InputObject | Should Be 1
|
|
|
|
$actualOutput[2].InputObject | Should Be 1
|
|
|
|
$actualOutput[3].InputObject | Should Be 15
|
2015-10-06 22:30:51 +02:00
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
$actualOutput[0].SideIndicator | Should be "=>"
|
|
|
|
$actualOutput[1].SideIndicator | Should be "<="
|
|
|
|
$actualOutput[2].SideIndicator | Should be "=>"
|
|
|
|
$actualOutput[3].SideIndicator | Should be "<="
|
2015-10-06 22:30:51 +02:00
|
|
|
}
|
|
|
|
|
2016-03-04 23:52:27 +01:00
|
|
|
# Clean up after yourself
|
2015-10-06 22:30:51 +02:00
|
|
|
Remove-Item $testDirectory -Recurse -Force
|
|
|
|
Test-Path $testDirectory | Should Be $false
|
|
|
|
}
|