Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New-xDscResource: Change Dsc Module Validate Set Quotes to Singles #83

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ These uses of these functions are given below.

* Fix Parameter Blocks to conform to Dsc Style Guidlelines [issue #79](https://github.com/PowerShell/xDSCResourceDesigner/issues/79).
* Fix README.md MarkDownLint Errors and Formatting Issues
* New-xDscResource: Change Dsc Module Validate Set Quotes to Singles

### 1.12.0.0

Expand Down
20 changes: 20 additions & 0 deletions Tests/xDscResourceDesigner.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,26 @@ end

}
}

Describe 'New-DelimitedList' {
It 'Should return the correct default single quote string list' {
$List = 'a','b','c'
$Result = New-DelimitedList $List -String
$Result | Should Be "'a','b','c'"
}

It 'Should return the correct single quote string list' {
$List = 'a','b','c'
$Result = New-DelimitedList $List -String -QuoteType Single
$Result | Should Be "'a','b','c'"
}

It 'Should return the correct double quote string list' {
$List = 'a','b','c'
$Result = New-DelimitedList $List -String -QuoteType Double
$Result | Should Be '"a","b","c"'
}
}
}
}

Expand Down
27 changes: 21 additions & 6 deletions xDSCResourceDesigner.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ function New-DscSchemaParameter
{
Add-StringBuilderLine $SchemaEntry ", ValueMap{" -Append

$CommaList = New-DelimitedList $Parameter.ValueMap -String:($Parameter.Type -eq "String" -or $Parameter.Type -eq "String[]")
$CommaList = New-DelimitedList $Parameter.ValueMap -String:($Parameter.Type -eq "String" -or $Parameter.Type -eq "String[]") -QuoteType Double

Add-StringBuilderLine $SchemaEntry $CommaList -Append
Add-StringBuilderLine $SchemaEntry "}" -Append
Expand All @@ -880,7 +880,7 @@ function New-DscSchemaParameter
{
Add-StringBuilderLine $SchemaEntry ", Values{" -Append

$CommaList = New-DelimitedList $Parameter.Values -String
$CommaList = New-DelimitedList $Parameter.Values -String -QuoteType Double

Add-StringBuilderLine $SchemaEntry $CommaList -Append
Add-StringBuilderLine $SchemaEntry "}" -Append
Expand Down Expand Up @@ -916,9 +916,24 @@ function New-DelimitedList
$String,

[String]
$Separator = ","
$Separator = ",",

[Parameter()]
[ValidateSet('Single', 'Double')]
[String]
$QuoteType = 'Single'

)

if ($QuoteType -eq 'Single')
{
$Quote = ''''
}
else
{
$Quote = '"'
}

$CommaList = New-Object -TypeName System.Text.StringBuilder

for ($i = 0; $i -lt $list.Count; $i++)
Expand All @@ -929,9 +944,9 @@ function New-DelimitedList
# the validateSet items need to be wrapped in quotes?
if ($String)
{
Add-StringBuilderLine $CommaList "`"" -Append
Add-StringBuilderLine $CommaList $Quote -Append
Add-StringBuilderLine $CommaList $curItem -Append
Add-StringBuilderLine $CommaList "`"" -Append
Add-StringBuilderLine $CommaList $Quote -Append
}
else
{
Expand Down Expand Up @@ -2436,7 +2451,7 @@ function Test-MockSchema

if ($_ -cmatch "^class\s+$className\s*:\s*OMI_BaseResource")
{
$extendsOMI = $true
$extendsOMI = $true
if($className -eq $schemaName)
{
$classNameMatch = $true
Expand Down