mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
added changes from code review
This commit is contained in:
@@ -1,12 +1,21 @@
|
||||
Describe "Test-Get-Content" {
|
||||
$testString = "This is a test content for a file"
|
||||
$secondline = "Here's a first line `n here's a second line`nmore text`njust to make sure`n there's plenty to work with"
|
||||
$nl = "`n"
|
||||
|
||||
$firstline = "Here's a first line "
|
||||
$secondline = " here's a second line"
|
||||
$thirdline = "more text"
|
||||
$fourthline = "just to make sure"
|
||||
$fifthline = "there's plenty to work with"
|
||||
|
||||
$testString2 = $firstline + $nl + $secondline + $nl + $thirdline + $nl + $fourthline + $nl + $fifthline
|
||||
|
||||
$testPath = "/tmp/testfile1"
|
||||
$testPath2 = "/tmp/testfile2"
|
||||
|
||||
BeforeEach {
|
||||
New-Item -Path $testPath -Force -Value $testString
|
||||
New-Item -Path $testPath2 -Force -Value $secondline
|
||||
New-Item -Path $testPath2 -Force -Value $testString2
|
||||
}
|
||||
|
||||
It "Should throw an error on a directory " {
|
||||
@@ -38,37 +47,48 @@
|
||||
{ type -Path $testPath } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should return the same values for aliases" {
|
||||
$getContentAlias = Get-Content -Path $testPath
|
||||
$gcAlias = gc -Path $testPath
|
||||
$catAlias = gc -Path $testPath
|
||||
$typeAlias = gc -Path $testPath
|
||||
|
||||
$getContentAlias | Should Be $gcAlias
|
||||
$getContentAlias | Should Be $catAlias
|
||||
$getContentAlias | Should Be $typeAlias
|
||||
}
|
||||
|
||||
It "Should be able to return a specific line from a file" {
|
||||
(cat -Path $testPath2)[1] | Should be " here's a second line"
|
||||
(Get-Content -Path $testPath2)[1] | Should be $secondline
|
||||
}
|
||||
|
||||
It "Should be able to specify the number of lines to get the content of using the TotalCount switch" {
|
||||
$returnArray = (cat -Path $testPath2 -TotalCount 2)
|
||||
|
||||
$returnArray[0] | Should Be "Here's a first line "
|
||||
$returnArray[1] | Should Be " here's a second line"
|
||||
$returnArray[0] | Should Be $firstline
|
||||
$returnArray[1] | Should Be $secondline
|
||||
}
|
||||
|
||||
It "Should be able to specify the number of lines to get the content of using the Head switch" {
|
||||
$returnArray = (cat -Path $testPath2 -Head 2)
|
||||
|
||||
$returnArray[0] | Should Be "Here's a first line "
|
||||
$returnArray[1] | Should Be " here's a second line"
|
||||
$returnArray[0] | Should Be $firstline
|
||||
$returnArray[1] | Should Be $secondline
|
||||
}
|
||||
|
||||
It "Should be able to specify the number of lines to get the content of using the First switch" {
|
||||
$returnArray = (cat -Path $testPath2 -First 2)
|
||||
|
||||
$returnArray[0] | Should Be "Here's a first line "
|
||||
$returnArray[1] | Should Be " here's a second line"
|
||||
$returnArray[0] | Should Be $firstline
|
||||
$returnArray[1] | Should Be $secondline
|
||||
}
|
||||
|
||||
It "Should return the last line of a file using the Tail switch" {
|
||||
Get-Content -Path $testPath -Tail 1 | Should Be " there's plenty to work with"
|
||||
Get-Content -Path $testPath -Tail 1 | Should Be $fifthline
|
||||
}
|
||||
|
||||
It "Should return the last lines of a file using the Last alias" {
|
||||
Get-Content -Path $testPath2 -Tail 1 | Should Be " there's plenty to work with"
|
||||
Get-Content -Path $testPath2 -Last 1 | Should Be $fifthline
|
||||
}
|
||||
|
||||
It "Should be able to get content within a different drive" {
|
||||
|
||||
Reference in New Issue
Block a user