Skip to content

Commit

Permalink
Merge pull request #43 from heilkn/arrays
Browse files Browse the repository at this point in the history
Read Multiple Values for Common Key into Array
  • Loading branch information
lipkau authored Jan 5, 2019
2 parents 2b8dc75 + 273e2c5 commit 2ec97f3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
6 changes: 5 additions & 1 deletion PSIni/Functions/Get-IniContent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ Function Get-IniContent {
}
$name, $value = $matches[1..2]
Write-Verbose "$($MyInvocation.MyCommand.Name):: Adding key $name with value: $value"
$ini[$section][$name] = $value
if (-not $ini[$section][$name]) {
$ini[$section][$name] = @($value)
} else {
$ini[$section][$name] += $value
}
continue
}
}
Expand Down
4 changes: 3 additions & 1 deletion PSIni/Functions/Out-IniFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ Function Out-IniFile {
}
else {
Write-Verbose "$($MyInvocation.MyCommand.Name):: Writing key: $key"
Add-Content -Value "$key$delimiter$($InputObject[$key])" -Encoding $Encoding -Path $Path
$InputObject[$key] |
ForEach-Object { "$key$delimiter$_" } |
Add-Content -Encoding $Encoding -Path $Path
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Tests/PsIni.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Describe "PsIni functionality" {
$dictIn["Category1"]["Key1"] = "Value1"
$dictIn["Category1"]["Key2"] = "Value2"
$dictIn["Category2"] = New-Object System.Collections.Specialized.OrderedDictionary([System.StringComparer]::OrdinalIgnoreCase)
$dictIn["Category2"]["Key3"] = "Value3"
$dictIn["Category2"]["Key3"] = @("Value3.1", "Value3.2", "Value3.3")
$dictIn["Category2"]["Key4"] = "Value4"

Context "Load Module" {
Expand Down Expand Up @@ -69,7 +69,7 @@ Describe "PsIni functionality" {
# assert
It "content matches expected value" {

$content = "[Category1]`r`nKey1=value1`r`nKey2=Value2`r`n[Category2]`r`nKey3=Value3`r`nKey4=Value4`r`n"
$content = "[Category1]`r`nKey1=value1`r`nKey2=Value2`r`n[Category2]`r`nKey3=Value3.1`r`nKey3=Value3.2`r`nKey3=Value3.3`r`nKey4=Value4`r`n"

Get-Content $iniFile -Raw | Should Be $content

Expand All @@ -91,7 +91,7 @@ Describe "PsIni functionality" {
# assert
It "content matches expected value" {

$content = "[Category1]`r`nKey1=value1`r`nKey2=Value2`r`n`r`n[Category2]`r`nKey3=Value3`r`nKey4=Value4`r`n"
$content = "[Category1]`r`nKey1=value1`r`nKey2=Value2`r`n`r`n[Category2]`r`nKey3=Value3.1`r`nKey3=Value3.2`r`nKey3=Value3.3`r`nKey4=Value4`r`n"

Get-Content $iniFile -Raw | Should Be $content

Expand Down

0 comments on commit 2ec97f3

Please sign in to comment.