made changes based off of feedback

This commit is contained in:
Aaron 2015-09-11 11:43:50 -07:00
parent 807b47a8ce
commit 7790be0601

View file

@ -1,9 +1,9 @@
Describe ".\Test-Select-String" {
Describe "Test-Select-String" {
Context "String actions" {
$testInputOne = "Hello","HELLO","Goodbye"
$testInputTwo = "Hello","HELLO"
It "Should be called with out error" {
It "Should be called with out errors" {
{ $testInputOne | Select-String -Pattern "HELLO" } | Should Not Throw
}
@ -12,18 +12,32 @@
}
It "Should return an array data type when multiple matches are found" {
# Array is case insensitive
( $testInputTwo | Select-String -Pattern "HELLO").GetType().BaseType | Should Be Array
}
It "Should return an array of matches when multiple matches are found" {
$testInputOne | Select-String -Pattern "HELLO" | Should Be "HELLO", "Hello"
$a = $testInputOne | Select-String -Pattern "HELLO"
$b = $testInputOne | sls -Pattern "HELLO"
$a | Should Be $b
}
It "Should return an object type when one match is found" {
# look into the aliases for the switches. ca for case-sensitive, n for notmatch, etc
( $testInputTwo | Select-String -Pattern "HELLO" -CaseSensitive).GetType().BaseType | Should Be System.Object
}
It "Should return MatchInfo type" {
( $testInputTwo | Select-String -Pattern "HELLO" -CaseSensitive).GetType().Name | Should Be MatchInfo
}
It "Should use the ca alias for casesenstive" {
$a = $testInputTwo | Select-String -Pattern "HELLO" -CaseSensitive
$b = $testInputTwo | Select-String -Pattern "HELLO" -ca
$a | Should Be $b
}
It "Should only return the case sensitive match when the casesensitive switch is used" {
$testInputTwo | Select-String -Pattern "HELLO" -CaseSensitive | Should Be "HELLO"
}
@ -45,7 +59,7 @@
}
It "Should be true when select string returns a positive result when the quiet switch is used" {
($testInputTwo | Select-String -Quiet "HELLO" -CaseSensitive) | Should Be TRUE
($testInputTwo | Select-String -Quiet "HELLO" -CaseSensitive) | Should Be $true
}
It "Should be empty when select string does not return a result when the quiet switch is used" {
@ -55,6 +69,13 @@
It "Should return an array of non matching strings when the switch of NotMatch is used and the string do not match" {
$testInputOne | Select-String -Pattern "Goodbye" -NotMatch | Should Be "HELLO", "Hello"
}
It "Should return the same as NotMatch" {
$a = $testInputOne | Select-String -Pattern "Goodbye" -NotMatch
$b = $testInputOne | Select-String -Pattern "Goodbye" -n
$a | Should Be $b
}
}
Context "Filesytem actions" {
@ -67,6 +88,10 @@
(Select-String $testInputFile -Pattern "string").GetType().BaseType | Should be System.Object
}
It "Should return an array when a match is found is the file on several lines" {
(Select-String $testInputFile -Pattern "in").GetType().BaseType | Should be array
}
It "Should return the name of the file and the string that 'string' is found if there is only one lines that has a match" {
$expected = $testInputFile + ":1:This is a text string, and another string"
@ -79,22 +104,17 @@
Select-String $testInputFile -Pattern "second"| Should Be $expected
}
#this should probably go up near the one that returns 'object' when only a single match is found
It "Should return an array when a match is found is the file on several lines"{
(Select-String $testInputFile -Pattern "in").GetType().BaseType | Should be array
}
It "Should return all strings where 'in' is found in testfile1 pattern switch is not required" {
$expected1 = $testInputFile + ":1:This is a text string, and another string"
$expected2 = $testInputFile + ":2:This is the second line"
$expected3 = $testInputFile + ":3:This is the third line"
$expected4 = $testInputFile + ":4:This is the fourth line"
$expected1 = "This is a text string, and another string"
$expected2 = "This is the second line"
$expected3 = "This is the third line"
$expected4 = "This is the fourth line"
(Select-String in $testInputFile)[0] | Should Be $expected1
(Select-String in $testInputFile)[1] | Should Be $expected2
(Select-String in $testInputFile)[2] | Should Be $expected3
(Select-String in $testInputFile)[3] | Should Be $expected4
(Select-String in $testInputFile)[4] | Should BeNullOrEmpty
(Select-String in $testInputFile)[0].Line | Should Be $expected1
(Select-String in $testInputFile)[1].Line | Should Be $expected2
(Select-String in $testInputFile)[2].Line | Should Be $expected3
(Select-String in $testInputFile)[3].Line | Should Be $expected4
(Select-String in $testInputFile)[4].Line | Should BeNullOrEmpty
}
It "Should return empty because 'for' is not found in testfile1 " {