-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #514 from SteveL-MSFT/array-index
Add array index support to expression grammar
- Loading branch information
Showing
12 changed files
with
1,725 additions
and
320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
|
||
Describe 'Expressions tests' { | ||
It 'Accessors work: <text>' -TestCases @( | ||
@{ text = "[parameters('test').hello]"; expected = '@{world=there}' } | ||
@{ text = "[parameters('test').hello.world]"; expected = 'there' } | ||
@{ text = "[parameters('test').array[0]]"; expected = 'one' } | ||
@{ text = "[parameters('test').array[1][1]]"; expected = 'three' } | ||
@{ text = "[parameters('test').objectArray[0].name]"; expected = 'one' } | ||
@{ text = "[parameters('test').objectArray[1].value[0]]"; expected = '2' } | ||
@{ text = "[parameters('test').objectArray[1].value[1].name]"; expected = 'three' } | ||
) { | ||
param($text, $expected) | ||
$yaml = @" | ||
`$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json | ||
parameters: | ||
test: | ||
type: object | ||
defaultValue: | ||
hello: | ||
world: there | ||
array: | ||
- one | ||
- [ 'two', 'three' ] | ||
objectArray: | ||
- name: one | ||
value: 1 | ||
- name: two | ||
value: | ||
- 2 | ||
- nestedObject: | ||
name: three | ||
value: 3 | ||
resources: | ||
- name: echo | ||
type: Test/Echo | ||
properties: | ||
output: "$text" | ||
"@ | ||
$debug = $yaml | dsc -l debug config get -f yaml 2>&1 | Out-String | ||
$out = $yaml | dsc config get | ConvertFrom-Json | ||
$LASTEXITCODE | Should -Be 0 | ||
$out.results[0].result.actualState.output | Should -Be $expected -Because $debug | ||
} | ||
|
||
It 'Invalid expressions: <expression>' -TestCases @( | ||
@{ expression = "[concat('A','B')].hello" } | ||
@{ expression = "[concat('A','B')](0)" } | ||
@{ expression = "[concat('a','b').hello]" } | ||
@{ expression = "[concat('a','b')[0]]" } | ||
) { | ||
param($expression) | ||
$yaml = @" | ||
`$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json | ||
resources: | ||
- name: echo | ||
type: Test/Echo | ||
properties: | ||
output: "$expression" | ||
"@ | ||
$out = dsc config get -d $yaml 2>&1 | ||
$LASTEXITCODE | Should -Be 2 | ||
$out | Should -BeLike "*ERROR*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
; We generally want to save install/update commands | ||
save=true | ||
; We use a public Azure Artifacts mirror | ||
registry=https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/npm/registry/ | ||
|
||
always-auth=true | ||
; But we don't want references to it in the lockfile | ||
omit-lockfile-registry-resolved=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.