Skip to content

Commit

Permalink
Address most PR review issues.
Browse files Browse the repository at this point in the history
I don't know that Pester will support a user-defined construct to encapuslate BeforeAll/AfterAll.  But I did pull the guts out into shared functions.
  • Loading branch information
rkeithhill-keysight committed Feb 13, 2017
1 parent 8440c88 commit 32c9a2b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
5 changes: 3 additions & 2 deletions src/GitTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ catch {
}

filter quoteStringWithSpecialChars {
if ($_ -and ($_ -match '\s+|#|@|\$|;|\{|\}|\(|\)')) {
"'" + $_ + "'"
if ($_ -and ($_ -match '\s+|#|@|\$|;|,|''|\{|\}|\(|\)')) {
$str = $_ -replace "'", "''"
"'$str'"
}
else {
$_
Expand Down
22 changes: 22 additions & 0 deletions test/Shared.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,28 @@ function MakeGitPath([string]$Path) {
$Path -replace '\\', '/'
}

function NewGitTempRepo {
Push-Location
$temp = [System.IO.Path]::GetTempPath()
$repoPath = Join-Path $temp ([IO.Path]::GetRandomFileName())
git.exe init $repoPath *>$null
Set-Location $repoPath
$repoPath
}

function RemoveGitTempRepo($RepoPath) {
Pop-Location
if (Test-Path $repoPath) {
Remove-Item $repoPath -Recurse -Force
}
}

function ResetGitTempRepoWorkingDir($RepoPath, $Branch = 'master') {
Set-Location $repoPath
git.exe reset HEAD --hard
git.exe checkout $Branch 2>$null
}

# Force the posh-git prompt to be installed. Could be runnng on dev system where
# user has customized the prompt.
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssigments', '')]
Expand Down
35 changes: 12 additions & 23 deletions test/TabExpansion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,14 @@ Describe 'TabExpansion Tests' {
}
}
}

Context 'Add/Reset/Checkout TabExpansion Tests' {
BeforeEach {
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssigments', '')]
$origPath = Get-Location
$temp = [System.IO.Path]::GetTempPath()
$repoPath = Join-Path $temp ([IO.Path]::GetRandomFileName())

git.exe init $repoPath
Set-Location $repoPath
$repoPath = NewGitTempRepo
}
AfterEach {
Set-Location $origPath
if (Test-Path $repoPath) {
Remove-Item $repoPath -Recurse -Force
}
RemoveGitTempRepo $repoPath
}
It 'Tab completes non-ASCII file name' {
git.exe config core.quotepath true # Problematic (default) config
Expand All @@ -152,27 +145,17 @@ Describe 'TabExpansion Tests' {
Context 'PowerShell Special Chars Tests' {
BeforeAll {
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssigments', '')]
$origPath = Get-Location
$temp = [System.IO.Path]::GetTempPath()
$repoPath = Join-Path $temp ([IO.Path]::GetRandomFileName())

git.exe init $repoPath
Set-Location $repoPath
$repoPath = NewGitTempRepo

'readme' | Out-File .\README.md -Encoding ascii
git.exe add .\README.md
git.exe commit -m "initial commit."
}
AfterAll {
Set-Location $origPath
if (Test-Path $repoPath) {
Remove-Item $repoPath -Recurse -Force
}
RemoveGitTempRepo $repoPath
}
AfterEach {
Set-Location $repoPath
git.exe reset HEAD --hard
git.exe checkout master 2>$null
ResetGitTempRepoWorkingDir $repoPath
}
It 'Tab completes branch name with special char as quoted' {
git.exe branch '#develop' 2>$null
Expand All @@ -193,6 +176,12 @@ Describe 'TabExpansion Tests' {
$result = & $module GitTabExpansionInternal 'git show v1'
$result | Should BeExactly "'$tag'"
}
It 'Tab completes a tag name with single quote correctly' {
git.exe tag "v2.0.0'"

$result = & $module GitTabExpansionInternal 'git show v2'
$result | Should BeExactly "'v2.0.0'''"
}
It 'Tab completes add file in working dir with special char as quoted' {
$filename = 'foo{bar} (x86).txt';
New-Item $filename -ItemType File
Expand Down

0 comments on commit 32c9a2b

Please sign in to comment.