diff --git a/IMPLEMENTATION_PLAN.md b/IMPLEMENTATION_PLAN.md index 84c2301..bdba5e4 100644 --- a/IMPLEMENTATION_PLAN.md +++ b/IMPLEMENTATION_PLAN.md @@ -574,6 +574,15 @@ priorities. authored `Set-Alias Env:...` invocation. The generator-owned executable corpus now supports per-entry initial- state mode and includes the promoted Parallel and remote/session cases. + It now contains exact generated expectations for 84 of the 90 PowerShell + design cases. Four intentionally deferred condition/deferred-action cases + remain parked. Two stable cases remain implementation work rather than + being mislabeled as corpus-complete: bounded-loop dynamic invocation + still fails atomically, and local `Invoke-Command -AsJob` still needs to + reject its invalid parameter-set combination. Direct generated cases for + `Measure-Command`, `Trace-Command`, and `ForEach-Object + -RemainingScripts` fill the remaining stable receiver-catalog evidence + without renumbering the existing corpus. Stable v0.3 stops at the delivered Start-Job, Parallel, and remote/session boundaries. Optional-module Start-ThreadJob and exact deferred breakpoint/event/completion actions are post-v0.3 catalog work; unknown diff --git a/openspec/changes/v0-3-structured-shell-analysis/tasks.md b/openspec/changes/v0-3-structured-shell-analysis/tasks.md index f4f3690..c6b56c5 100644 --- a/openspec/changes/v0-3-structured-shell-analysis/tasks.md +++ b/openspec/changes/v0-3-structured-shell-analysis/tasks.md @@ -12,6 +12,10 @@ - [ ] 1.10 Promote every design case for a stable-v0.3 construct into the executable corpus as its production parser slice lands. Retain future-scope design cases as non-gating evidence rather than release work. + - PowerShell now has exact generated expectations for 84 of 90 design cases. + Four future-scope cases remain non-gating. The stable bounded-loop dynamic + invocation and invalid local `Invoke-Command -AsJob` cases remain pending + production corrections and are not marked as promoted. - [x] 1.11 Correct the PowerShell script-block boundary and lock the additive execution-region node, origin/phase/timing/cardinality facts, authored-versus-semantic ordering, command projection, and independent shell-state analysis contract @@ -270,8 +274,10 @@ - [ ] 7.6 Add adversarial cases for object-valued iterables, mutation, dynamic invocation, splatting, and cap overflow. - [ ] 7.7 Add PowerShell corpus entries, live `pwsh` oracle coverage, and Netclaw integration cases. - `PwshCorpusTool` now supports case-specific `PwshInitialStateMode`; keep - promoting the remaining stable execution-region and adversarial cases into - its generated manifest, then add the Netclaw PowerShell policy matrix. + promoting the two remaining stable cases into its generated manifest after + their production corrections, then complete the Netclaw PowerShell policy + matrix. Exact generated cases now cover `Measure-Command`, `Trace-Command`, + and `ForEach-Object -RemainingScripts` directly. - [x] 7.8 Implement the additive `PwshDialect` API, PowerShell 7 compatibility default, unknown-value safe-fail, Windows PowerShell 5.1 pipeline-chain rejection, dialect-specific alias and execution-region metadata, and static diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/505_v03_design_simple_command_substitution.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/505_v03_design_simple_command_substitution.json new file mode 100644 index 0000000..0037920 --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/505_v03_design_simple_command_substitution.json @@ -0,0 +1,218 @@ +{ + "name": "V03 design simple command substitution", + "input": "Remove-Item $(Get-Item target.txt)", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "None", + "verb": [ + "Get-Item" + ], + "args": [ + { + "raw": "target.txt", + "kind": "Literal", + "isPath": true, + "resolved": "C:/work/target.txt" + } + ], + "redirects": [], + "elements": [ + { + "raw": "Get-Item", + "value": "Get-Item", + "role": "Verb", + "sourceStart": 14, + "sourceLength": 8, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "target.txt", + "value": "target.txt", + "role": "Argument", + "sourceStart": 23, + "sourceLength": 10, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": false, + "isPath": true, + "resolved": "C:/work/target.txt" + } + ] + }, + { + "operator": "None", + "verb": [ + "Remove-Item" + ], + "args": [ + { + "raw": "$(Get-Item target.txt)", + "kind": "DynamicSkip", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Remove-Item", + "value": "Remove-Item", + "role": "Verb", + "sourceStart": 0, + "sourceLength": 11, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "$(Get-Item target.txt)", + "value": "$(Get-Item target.txt)", + "role": "Argument", + "sourceStart": 12, + "sourceLength": 22, + "precedingVerbElementCount": 1, + "kind": "DynamicSkip", + "isFlag": false, + "isPath": false + } + ] + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 34, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 34, + "clauseIndex": 1, + "groupKind": null, + "listOperator": null + }, + { + "kind": "CommandSubstitution", + "parentIndex": 1, + "region": "Substitution", + "childIndex": 0, + "sourceStart": 12, + "sourceLength": 22, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "Block", + "parentIndex": 2, + "region": "Substitution", + "childIndex": 0, + "sourceStart": 14, + "sourceLength": 19, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 3, + "region": "Statement", + "childIndex": 0, + "sourceStart": 14, + "sourceLength": 19, + "clauseIndex": 0, + "groupKind": null, + "listOperator": null + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "Substitution", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 34 + }, + { + "ancestorKind": "CommandSubstitution", + "region": "Substitution", + "childIndex": 0, + "sourceStart": 12, + "sourceLength": 22 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 14, + "sourceLength": 19 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 1, + "immediateRole": "Ordinary", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 34 + } + ], + "effectiveArguments": [ + { + "clauseElementIndex": 1, + "value": { + "kind": "Unknown", + "values": [], + "pattern": null, + "coveringDirectory": null + } + } + ], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Promotes stable design case pwsh-simple-command-substitution." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/506_v03_design_literal_substitution_spellings.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/506_v03_design_literal_substitution_spellings.json new file mode 100644 index 0000000..af21c05 --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/506_v03_design_literal_substitution_spellings.json @@ -0,0 +1,114 @@ +{ + "name": "V03 design literal substitution spellings", + "input": "Write-Output \u0027$(Get-Date)\u0027 \u0022literal \u0060$(Get-Location)\u0022", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "None", + "verb": [ + "Write-Output" + ], + "args": [ + { + "raw": "\u0027$(Get-Date)\u0027", + "kind": "Literal", + "isPath": false + }, + { + "raw": "\u0022literal \u0060$(Get-Location)\u0022", + "kind": "Literal", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Write-Output", + "value": "Write-Output", + "role": "Verb", + "sourceStart": 0, + "sourceLength": 12, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "\u0027$(Get-Date)\u0027", + "value": "$(Get-Date)", + "role": "Argument", + "sourceStart": 13, + "sourceLength": 13, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "\u0022literal \u0060$(Get-Location)\u0022", + "value": "literal $(Get-Location)", + "role": "Argument", + "sourceStart": 27, + "sourceLength": 26, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": false, + "isPath": false + } + ] + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 53, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 53, + "clauseIndex": 0, + "groupKind": null, + "listOperator": null + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "Ordinary", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 53 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Promotes stable design case pwsh-literal-substitution-spellings." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/507_v03_design_call_operator_script_block_region.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/507_v03_design_call_operator_script_block_region.json new file mode 100644 index 0000000..3ff036b --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/507_v03_design_call_operator_script_block_region.json @@ -0,0 +1,141 @@ +{ + "name": "V03 design call operator script block region", + "input": "\u0026 { Remove-Item target.txt }", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "None", + "verb": [ + "Remove-Item" + ], + "args": [ + { + "raw": "target.txt", + "kind": "Literal", + "isPath": true, + "resolved": "C:/work/target.txt" + } + ], + "redirects": [], + "elements": [ + { + "raw": "Remove-Item", + "value": "Remove-Item", + "role": "Verb", + "sourceStart": 4, + "sourceLength": 11, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "target.txt", + "value": "target.txt", + "role": "Argument", + "sourceStart": 16, + "sourceLength": 10, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": false, + "isPath": true, + "resolved": "C:/work/target.txt" + } + ] + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 28, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ExecutionRegion", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 2, + "sourceLength": 26, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "executionOrigin": "DirectCall", + "hostClauseElementIndex": null, + "executionPhase": "Main", + "executionTiming": "Synchronous", + "executionCardinality": "Once" + }, + { + "kind": "Block", + "parentIndex": 1, + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 3, + "sourceLength": 24, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 2, + "region": "Statement", + "childIndex": 0, + "sourceStart": 4, + "sourceLength": 22, + "clauseIndex": 0, + "groupKind": null, + "listOperator": null + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "ExecutionRegion", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 28 + }, + { + "ancestorKind": "ExecutionRegion", + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 2, + "sourceLength": 26 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 3, + "sourceLength": 24 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Promotes stable design case pwsh-call-operator-script-block-region." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/508_v03_design_call_operator_subexpression_invocation.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/508_v03_design_call_operator_subexpression_invocation.json new file mode 100644 index 0000000..7b3fe31 --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/508_v03_design_call_operator_subexpression_invocation.json @@ -0,0 +1,190 @@ +{ + "name": "V03 design call operator subexpression invocation", + "input": "\u0026 $(Write-Output Get-Date)", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "None", + "verb": [ + "Write-Output" + ], + "args": [ + { + "raw": "Get-Date", + "kind": "Literal", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Write-Output", + "value": "Write-Output", + "role": "Verb", + "sourceStart": 4, + "sourceLength": 12, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "Get-Date", + "value": "Get-Date", + "role": "Argument", + "sourceStart": 17, + "sourceLength": 8, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": false, + "isPath": false + } + ] + }, + { + "operator": "None", + "verb": [ + "$(Write-Output Get-Date)" + ], + "isDynamic": true, + "args": [], + "redirects": [], + "elements": [ + { + "raw": "$(Write-Output Get-Date)", + "value": "$(Write-Output Get-Date)", + "role": "Verb", + "sourceStart": 2, + "sourceLength": 24, + "precedingVerbElementCount": 0, + "kind": "DynamicSkip", + "isFlag": false, + "isPath": false + } + ] + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 26, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 26, + "clauseIndex": 1, + "groupKind": null, + "listOperator": null + }, + { + "kind": "CommandSubstitution", + "parentIndex": 1, + "region": "Substitution", + "childIndex": 0, + "sourceStart": 2, + "sourceLength": 24, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "Block", + "parentIndex": 2, + "region": "Substitution", + "childIndex": 0, + "sourceStart": 4, + "sourceLength": 21, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 3, + "region": "Statement", + "childIndex": 0, + "sourceStart": 4, + "sourceLength": 21, + "clauseIndex": 0, + "groupKind": null, + "listOperator": null + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "Substitution", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 26 + }, + { + "ancestorKind": "CommandSubstitution", + "region": "Substitution", + "childIndex": 0, + "sourceStart": 2, + "sourceLength": 24 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 4, + "sourceLength": 21 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 1, + "immediateRole": "Ordinary", + "isComplete": false, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 26 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Promotes stable design case pwsh-call-operator-subexpression-invocation." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/509_v03_design_command_substitution_current_scope_cwd.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/509_v03_design_command_substitution_current_scope_cwd.json new file mode 100644 index 0000000..d06e62a --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/509_v03_design_command_substitution_current_scope_cwd.json @@ -0,0 +1,439 @@ +{ + "name": "V03 design command substitution current scope cwd", + "input": "Write-Output $(Set-Location /tmp \u0026\u0026 Get-Location); Get-Item relative.txt", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "None", + "verb": [ + "Set-Location" + ], + "args": [ + { + "raw": "/tmp", + "kind": "Literal", + "isPath": true, + "resolved": "/tmp" + } + ], + "redirects": [], + "elements": [ + { + "raw": "Set-Location", + "value": "Set-Location", + "role": "Verb", + "sourceStart": 15, + "sourceLength": 12, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "/tmp", + "value": "/tmp", + "role": "Argument", + "sourceStart": 28, + "sourceLength": 4, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": false, + "isPath": true, + "resolved": "/tmp" + } + ] + }, + { + "operator": "AndIf", + "verb": [ + "Get-Location" + ], + "args": [ + { + "raw": "/tmp", + "kind": "Literal", + "isPath": true, + "resolved": "/tmp", + "isCwdAttribution": true + } + ], + "redirects": [], + "elements": [ + { + "raw": "Get-Location", + "value": "Get-Location", + "role": "Verb", + "sourceStart": 36, + "sourceLength": 12, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + } + ] + }, + { + "operator": "None", + "verb": [ + "Write-Output" + ], + "args": [ + { + "raw": "$(Set-Location /tmp \u0026\u0026 Get-Location)", + "kind": "DynamicSkip", + "isPath": false + }, + { + "raw": "\u003Cdynamic-cwd\u003E", + "kind": "DynamicSkip", + "isPath": false, + "isCwdAttribution": true + } + ], + "redirects": [], + "elements": [ + { + "raw": "Write-Output", + "value": "Write-Output", + "role": "Verb", + "sourceStart": 0, + "sourceLength": 12, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "$(Set-Location /tmp \u0026\u0026 Get-Location)", + "value": "$(Set-Location /tmp \u0026\u0026 Get-Location)", + "role": "Argument", + "sourceStart": 13, + "sourceLength": 36, + "precedingVerbElementCount": 1, + "kind": "DynamicSkip", + "isFlag": false, + "isPath": false + } + ] + }, + { + "operator": "Sequence", + "verb": [ + "Get-Item" + ], + "args": [ + { + "raw": "relative.txt", + "kind": "Literal", + "isPath": true + }, + { + "raw": "\u003Cdynamic-cwd\u003E", + "kind": "DynamicSkip", + "isPath": false, + "isCwdAttribution": true + } + ], + "redirects": [], + "elements": [ + { + "raw": "Get-Item", + "value": "Get-Item", + "role": "Verb", + "sourceStart": 51, + "sourceLength": 8, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "relative.txt", + "value": "relative.txt", + "role": "Argument", + "sourceStart": 60, + "sourceLength": 12, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": false, + "isPath": true + } + ] + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 72, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "CommandList", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 72, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 1, + "region": "Statement", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 49, + "clauseIndex": 2, + "groupKind": null, + "listOperator": "None" + }, + { + "kind": "CommandSubstitution", + "parentIndex": 2, + "region": "Substitution", + "childIndex": 0, + "sourceStart": 13, + "sourceLength": 36, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "Block", + "parentIndex": 3, + "region": "Substitution", + "childIndex": 0, + "sourceStart": 15, + "sourceLength": 33, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "CommandList", + "parentIndex": 4, + "region": "Statement", + "childIndex": 0, + "sourceStart": 15, + "sourceLength": 33, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 5, + "region": "Statement", + "childIndex": 0, + "sourceStart": 15, + "sourceLength": 17, + "clauseIndex": 0, + "groupKind": null, + "listOperator": "None" + }, + { + "kind": "SimpleCommand", + "parentIndex": 5, + "region": "Statement", + "childIndex": 1, + "sourceStart": 36, + "sourceLength": 12, + "clauseIndex": 1, + "groupKind": null, + "listOperator": "AndIf" + }, + { + "kind": "SimpleCommand", + "parentIndex": 1, + "region": "Statement", + "childIndex": 1, + "sourceStart": 51, + "sourceLength": 21, + "clauseIndex": 3, + "groupKind": null, + "listOperator": "Sequence" + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "Substitution", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 72 + }, + { + "ancestorKind": "CommandList", + "region": "Statement", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 72 + }, + { + "ancestorKind": "CommandSubstitution", + "region": "Substitution", + "childIndex": 0, + "sourceStart": 13, + "sourceLength": 36 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 15, + "sourceLength": 33 + }, + { + "ancestorKind": "CommandList", + "region": "Statement", + "childIndex": 0, + "sourceStart": 15, + "sourceLength": 33 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 1, + "immediateRole": "Substitution", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 72 + }, + { + "ancestorKind": "CommandList", + "region": "Statement", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 72 + }, + { + "ancestorKind": "CommandSubstitution", + "region": "Substitution", + "childIndex": 0, + "sourceStart": 13, + "sourceLength": 36 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 15, + "sourceLength": 33 + }, + { + "ancestorKind": "CommandList", + "region": "Statement", + "childIndex": 1, + "sourceStart": 15, + "sourceLength": 33 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "/tmp" + ], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 2, + "immediateRole": "Ordinary", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 72 + }, + { + "ancestorKind": "CommandList", + "region": "Statement", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 72 + } + ], + "effectiveArguments": [ + { + "clauseElementIndex": 1, + "value": { + "kind": "Unknown", + "values": [], + "pattern": null, + "coveringDirectory": null + } + } + ], + "workingDirectory": { + "kind": "Unknown", + "values": [], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 3, + "immediateRole": "Ordinary", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 72 + }, + { + "ancestorKind": "CommandList", + "region": "Statement", + "childIndex": 1, + "sourceStart": 0, + "sourceLength": 72 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Unknown", + "values": [], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Promotes stable design case pwsh-command-substitution-current-scope-cwd." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/510_v03_design_foreach_subexpression_iterator.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/510_v03_design_foreach_subexpression_iterator.json new file mode 100644 index 0000000..d22aac2 --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/510_v03_design_foreach_subexpression_iterator.json @@ -0,0 +1,300 @@ +{ + "name": "V03 design foreach subexpression iterator", + "input": "foreach ($f in $(Get-ChildItem C:\\input)) { Remove-Item -LiteralPath $f }", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "None", + "verb": [ + "Get-ChildItem" + ], + "args": [ + { + "raw": "C:\\input", + "kind": "Literal", + "isPath": true, + "resolved": "C:/input" + } + ], + "redirects": [], + "elements": [ + { + "raw": "Get-ChildItem", + "value": "Get-ChildItem", + "role": "Verb", + "sourceStart": 17, + "sourceLength": 13, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "C:\\input", + "value": "C:\\input", + "role": "Argument", + "sourceStart": 31, + "sourceLength": 8, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": false, + "isPath": true, + "resolved": "C:/input" + } + ] + }, + { + "operator": "None", + "verb": [ + "Remove-Item" + ], + "args": [ + { + "raw": "-LiteralPath", + "kind": "Literal", + "isPath": false + }, + { + "raw": "$f", + "kind": "DynamicSkip", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Remove-Item", + "value": "Remove-Item", + "role": "Verb", + "sourceStart": 44, + "sourceLength": 11, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "-LiteralPath", + "value": "-LiteralPath", + "role": "Argument", + "sourceStart": 56, + "sourceLength": 12, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": true, + "isPath": false + }, + { + "raw": "$f", + "value": "$f", + "role": "Argument", + "sourceStart": 69, + "sourceLength": 2, + "precedingVerbElementCount": 1, + "kind": "DynamicSkip", + "isFlag": false, + "isPath": false + } + ] + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 73, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ForEach", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 73, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "bindingName": "f", + "bindingRaw": "$f", + "bindingSourceStart": 9, + "bindingSourceLength": 2, + "iterableRaw": "$(Get-ChildItem C:\\input)", + "iterableSourceStart": 15, + "iterableSourceLength": 25 + }, + { + "kind": "Block", + "parentIndex": 1, + "region": "Iterator", + "childIndex": null, + "sourceStart": 15, + "sourceLength": 25, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "CommandSubstitution", + "parentIndex": 2, + "region": "Statement", + "childIndex": 0, + "sourceStart": 15, + "sourceLength": 25, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "Block", + "parentIndex": 3, + "region": "Substitution", + "childIndex": 0, + "sourceStart": 17, + "sourceLength": 22, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 4, + "region": "Statement", + "childIndex": 0, + "sourceStart": 17, + "sourceLength": 22, + "clauseIndex": 0, + "groupKind": null, + "listOperator": null + }, + { + "kind": "Block", + "parentIndex": 1, + "region": "LoopBody", + "childIndex": null, + "sourceStart": 43, + "sourceLength": 29, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 6, + "region": "Statement", + "childIndex": 0, + "sourceStart": 44, + "sourceLength": 27, + "clauseIndex": 1, + "groupKind": null, + "listOperator": null + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "Substitution", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 73 + }, + { + "ancestorKind": "ForEach", + "region": "Iterator", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 73 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 15, + "sourceLength": 25 + }, + { + "ancestorKind": "CommandSubstitution", + "region": "Substitution", + "childIndex": 0, + "sourceStart": 15, + "sourceLength": 25 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 17, + "sourceLength": 22 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 1, + "immediateRole": "LoopBody", + "isComplete": false, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 73 + }, + { + "ancestorKind": "ForEach", + "region": "LoopBody", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 73 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 43, + "sourceLength": 29 + } + ], + "effectiveArguments": [ + { + "clauseElementIndex": 2, + "value": { + "kind": "Unknown", + "values": [], + "pattern": null, + "coveringDirectory": null + } + } + ], + "workingDirectory": { + "kind": "Unknown", + "values": [], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Promotes stable design case pwsh-foreach-subexpression-iterator." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/511_v03_design_foreach_cmdlet_parameter_like_value.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/511_v03_design_foreach_cmdlet_parameter_like_value.json new file mode 100644 index 0000000..13b27b8 --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/511_v03_design_foreach_cmdlet_parameter_like_value.json @@ -0,0 +1,165 @@ +{ + "name": "V03 design foreach cmdlet parameter like value", + "input": "foreach ($f in @(\u0027-Force\u0027, \u0027a.txt\u0027)) { Remove-Item $f }", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "None", + "verb": [ + "Remove-Item" + ], + "args": [ + { + "raw": "$f", + "kind": "DynamicSkip", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Remove-Item", + "value": "Remove-Item", + "role": "Verb", + "sourceStart": 39, + "sourceLength": 11, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "$f", + "value": "$f", + "role": "Argument", + "sourceStart": 51, + "sourceLength": 2, + "precedingVerbElementCount": 1, + "kind": "DynamicSkip", + "isFlag": false, + "isPath": false + } + ] + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 55, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ForEach", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 55, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "bindingName": "f", + "bindingRaw": "$f", + "bindingSourceStart": 9, + "bindingSourceLength": 2, + "iterableRaw": "@(\u0027-Force\u0027, \u0027a.txt\u0027)", + "iterableSourceStart": 15, + "iterableSourceLength": 20 + }, + { + "kind": "Block", + "parentIndex": 1, + "region": "Iterator", + "childIndex": null, + "sourceStart": 15, + "sourceLength": 20, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "Block", + "parentIndex": 1, + "region": "LoopBody", + "childIndex": null, + "sourceStart": 38, + "sourceLength": 16, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 3, + "region": "Statement", + "childIndex": 0, + "sourceStart": 39, + "sourceLength": 14, + "clauseIndex": 0, + "groupKind": null, + "listOperator": null + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "LoopBody", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 55 + }, + { + "ancestorKind": "ForEach", + "region": "LoopBody", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 55 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 38, + "sourceLength": 16 + } + ], + "effectiveArguments": [ + { + "clauseElementIndex": 1, + "value": { + "kind": "FiniteSet", + "values": [ + "-Force", + "a.txt" + ], + "pattern": null, + "coveringDirectory": null + } + } + ], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Promotes stable design case pwsh-foreach-cmdlet-parameter-like-value." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/512_v03_design_foreach_native_option_like_value.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/512_v03_design_foreach_native_option_like_value.json new file mode 100644 index 0000000..247cfa6 --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/512_v03_design_foreach_native_option_like_value.json @@ -0,0 +1,165 @@ +{ + "name": "V03 design foreach native option like value", + "input": "foreach ($f in @(\u0027-n\u0027, \u0027file.txt\u0027)) { tool $f }", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "None", + "verb": [ + "tool" + ], + "args": [ + { + "raw": "$f", + "kind": "EnvVar", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "tool", + "value": "tool", + "role": "Verb", + "sourceStart": 38, + "sourceLength": 4, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "$f", + "value": "$f", + "role": "Argument", + "sourceStart": 43, + "sourceLength": 2, + "precedingVerbElementCount": 1, + "kind": "EnvVar", + "isFlag": false, + "isPath": false + } + ] + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 47, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ForEach", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 47, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "bindingName": "f", + "bindingRaw": "$f", + "bindingSourceStart": 9, + "bindingSourceLength": 2, + "iterableRaw": "@(\u0027-n\u0027, \u0027file.txt\u0027)", + "iterableSourceStart": 15, + "iterableSourceLength": 19 + }, + { + "kind": "Block", + "parentIndex": 1, + "region": "Iterator", + "childIndex": null, + "sourceStart": 15, + "sourceLength": 19, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "Block", + "parentIndex": 1, + "region": "LoopBody", + "childIndex": null, + "sourceStart": 37, + "sourceLength": 9, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 3, + "region": "Statement", + "childIndex": 0, + "sourceStart": 38, + "sourceLength": 7, + "clauseIndex": 0, + "groupKind": null, + "listOperator": null + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "LoopBody", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 47 + }, + { + "ancestorKind": "ForEach", + "region": "LoopBody", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 47 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 37, + "sourceLength": 9 + } + ], + "effectiveArguments": [ + { + "clauseElementIndex": 1, + "value": { + "kind": "FiniteSet", + "values": [ + "-n", + "file.txt" + ], + "pattern": null, + "coveringDirectory": null + } + } + ], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Promotes stable design case pwsh-foreach-native-option-like-value." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/513_v03_design_nested_foreach.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/513_v03_design_nested_foreach.json new file mode 100644 index 0000000..e00469d --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/513_v03_design_nested_foreach.json @@ -0,0 +1,221 @@ +{ + "name": "V03 design nested foreach", + "input": "foreach ($d in @(\u0027a\u0027, \u0027b\u0027)) { foreach ($f in @(\u0027x\u0027, \u0027y\u0027)) { Write-Output \u0022$d/$f\u0022 } }", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "None", + "verb": [ + "Write-Output" + ], + "args": [ + { + "raw": "\u0022$d/$f\u0022", + "kind": "DynamicSkip", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Write-Output", + "value": "Write-Output", + "role": "Verb", + "sourceStart": 60, + "sourceLength": 12, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "\u0022$d/$f\u0022", + "value": "$d/$f", + "role": "Argument", + "sourceStart": 73, + "sourceLength": 7, + "precedingVerbElementCount": 1, + "kind": "DynamicSkip", + "isFlag": false, + "isPath": false + } + ] + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 84, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ForEach", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 84, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "bindingName": "d", + "bindingRaw": "$d", + "bindingSourceStart": 9, + "bindingSourceLength": 2, + "iterableRaw": "@(\u0027a\u0027, \u0027b\u0027)", + "iterableSourceStart": 15, + "iterableSourceLength": 11 + }, + { + "kind": "Block", + "parentIndex": 1, + "region": "Iterator", + "childIndex": null, + "sourceStart": 15, + "sourceLength": 11, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "Block", + "parentIndex": 1, + "region": "LoopBody", + "childIndex": null, + "sourceStart": 29, + "sourceLength": 54, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ForEach", + "parentIndex": 3, + "region": "Statement", + "childIndex": 0, + "sourceStart": 30, + "sourceLength": 52, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "bindingName": "f", + "bindingRaw": "$f", + "bindingSourceStart": 39, + "bindingSourceLength": 2, + "iterableRaw": "@(\u0027x\u0027, \u0027y\u0027)", + "iterableSourceStart": 45, + "iterableSourceLength": 11 + }, + { + "kind": "Block", + "parentIndex": 4, + "region": "Iterator", + "childIndex": null, + "sourceStart": 45, + "sourceLength": 11, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "Block", + "parentIndex": 4, + "region": "LoopBody", + "childIndex": null, + "sourceStart": 59, + "sourceLength": 22, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 6, + "region": "Statement", + "childIndex": 0, + "sourceStart": 60, + "sourceLength": 20, + "clauseIndex": 0, + "groupKind": null, + "listOperator": null + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "LoopBody", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 84 + }, + { + "ancestorKind": "ForEach", + "region": "LoopBody", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 84 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 29, + "sourceLength": 54 + }, + { + "ancestorKind": "ForEach", + "region": "LoopBody", + "childIndex": null, + "sourceStart": 30, + "sourceLength": 52 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 59, + "sourceLength": 22 + } + ], + "effectiveArguments": [ + { + "clauseElementIndex": 1, + "value": { + "kind": "FiniteSet", + "values": [ + "a/x", + "a/y", + "b/x", + "b/y" + ], + "pattern": null, + "coveringDirectory": null + } + } + ], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Promotes stable design case pwsh-nested-foreach." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/514_v03_design_malformed_foreach_missing_body.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/514_v03_design_malformed_foreach_missing_body.json new file mode 100644 index 0000000..5fb1b7e --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/514_v03_design_malformed_foreach_missing_body.json @@ -0,0 +1,9 @@ +{ + "name": "V03 design malformed foreach missing body", + "input": "foreach ($f in 1, 2) Remove-Item $f", + "expected": { + "isUnparseable": true, + "unparseableReasonContains": "unsupported PowerShell foreach literal-list expression" + }, + "notes": "Promotes stable design case pwsh-malformed-foreach-missing-body." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/515_v03_design_foreach_candidate_cap_32.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/515_v03_design_foreach_candidate_cap_32.json new file mode 100644 index 0000000..fd6e68c --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/515_v03_design_foreach_candidate_cap_32.json @@ -0,0 +1,195 @@ +{ + "name": "V03 design foreach candidate cap 32", + "input": "foreach ($f in @(\u0027v01\u0027,\u0027v02\u0027,\u0027v03\u0027,\u0027v04\u0027,\u0027v05\u0027,\u0027v06\u0027,\u0027v07\u0027,\u0027v08\u0027,\u0027v09\u0027,\u0027v10\u0027,\u0027v11\u0027,\u0027v12\u0027,\u0027v13\u0027,\u0027v14\u0027,\u0027v15\u0027,\u0027v16\u0027,\u0027v17\u0027,\u0027v18\u0027,\u0027v19\u0027,\u0027v20\u0027,\u0027v21\u0027,\u0027v22\u0027,\u0027v23\u0027,\u0027v24\u0027,\u0027v25\u0027,\u0027v26\u0027,\u0027v27\u0027,\u0027v28\u0027,\u0027v29\u0027,\u0027v30\u0027,\u0027v31\u0027,\u0027v32\u0027)) { Write-Output $f }", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "None", + "verb": [ + "Write-Output" + ], + "args": [ + { + "raw": "$f", + "kind": "EnvVar", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Write-Output", + "value": "Write-Output", + "role": "Verb", + "sourceStart": 213, + "sourceLength": 12, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "$f", + "value": "$f", + "role": "Argument", + "sourceStart": 226, + "sourceLength": 2, + "precedingVerbElementCount": 1, + "kind": "EnvVar", + "isFlag": false, + "isPath": false + } + ] + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 230, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ForEach", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 230, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "bindingName": "f", + "bindingRaw": "$f", + "bindingSourceStart": 9, + "bindingSourceLength": 2, + "iterableRaw": "@(\u0027v01\u0027,\u0027v02\u0027,\u0027v03\u0027,\u0027v04\u0027,\u0027v05\u0027,\u0027v06\u0027,\u0027v07\u0027,\u0027v08\u0027,\u0027v09\u0027,\u0027v10\u0027,\u0027v11\u0027,\u0027v12\u0027,\u0027v13\u0027,\u0027v14\u0027,\u0027v15\u0027,\u0027v16\u0027,\u0027v17\u0027,\u0027v18\u0027,\u0027v19\u0027,\u0027v20\u0027,\u0027v21\u0027,\u0027v22\u0027,\u0027v23\u0027,\u0027v24\u0027,\u0027v25\u0027,\u0027v26\u0027,\u0027v27\u0027,\u0027v28\u0027,\u0027v29\u0027,\u0027v30\u0027,\u0027v31\u0027,\u0027v32\u0027)", + "iterableSourceStart": 15, + "iterableSourceLength": 194 + }, + { + "kind": "Block", + "parentIndex": 1, + "region": "Iterator", + "childIndex": null, + "sourceStart": 15, + "sourceLength": 194, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "Block", + "parentIndex": 1, + "region": "LoopBody", + "childIndex": null, + "sourceStart": 212, + "sourceLength": 17, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 3, + "region": "Statement", + "childIndex": 0, + "sourceStart": 213, + "sourceLength": 15, + "clauseIndex": 0, + "groupKind": null, + "listOperator": null + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "LoopBody", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 230 + }, + { + "ancestorKind": "ForEach", + "region": "LoopBody", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 230 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 212, + "sourceLength": 17 + } + ], + "effectiveArguments": [ + { + "clauseElementIndex": 1, + "value": { + "kind": "FiniteSet", + "values": [ + "v01", + "v02", + "v03", + "v04", + "v05", + "v06", + "v07", + "v08", + "v09", + "v10", + "v11", + "v12", + "v13", + "v14", + "v15", + "v16", + "v17", + "v18", + "v19", + "v20", + "v21", + "v22", + "v23", + "v24", + "v25", + "v26", + "v27", + "v28", + "v29", + "v30", + "v31", + "v32" + ], + "pattern": null, + "coveringDirectory": null + } + } + ], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Promotes stable design case pwsh-foreach-candidate-cap-32." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/516_v03_design_variable_writer_invalidates_proved_binding.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/516_v03_design_variable_writer_invalidates_proved_binding.json new file mode 100644 index 0000000..9d1b7ea --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/516_v03_design_variable_writer_invalidates_proved_binding.json @@ -0,0 +1,279 @@ +{ + "name": "V03 design variable writer invalidates proved binding", + "input": "foreach ($f in \u0027safe.txt\u0027) { }; Write-Output C:/sensitive.txt -OutVariable f; Remove-Item $f", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "Sequence", + "verb": [ + "Write-Output" + ], + "args": [ + { + "raw": "C:/sensitive.txt", + "kind": "Literal", + "isPath": true, + "resolved": "C:/sensitive.txt" + }, + { + "raw": "-OutVariable", + "kind": "Literal", + "isPath": false + }, + { + "raw": "f", + "kind": "Literal", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Write-Output", + "value": "Write-Output", + "role": "Verb", + "sourceStart": 32, + "sourceLength": 12, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "C:/sensitive.txt", + "value": "C:/sensitive.txt", + "role": "Argument", + "sourceStart": 45, + "sourceLength": 16, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": false, + "isPath": true, + "resolved": "C:/sensitive.txt" + }, + { + "raw": "-OutVariable", + "value": "-OutVariable", + "role": "Argument", + "sourceStart": 62, + "sourceLength": 12, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": true, + "isPath": false + }, + { + "raw": "f", + "value": "f", + "role": "Argument", + "sourceStart": 75, + "sourceLength": 1, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": false, + "isPath": false + } + ] + }, + { + "operator": "Sequence", + "verb": [ + "Remove-Item" + ], + "args": [ + { + "raw": "$f", + "kind": "DynamicSkip", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Remove-Item", + "value": "Remove-Item", + "role": "Verb", + "sourceStart": 78, + "sourceLength": 11, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "$f", + "value": "$f", + "role": "Argument", + "sourceStart": 90, + "sourceLength": 2, + "precedingVerbElementCount": 1, + "kind": "DynamicSkip", + "isFlag": false, + "isPath": false + } + ] + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 92, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "CommandList", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 92, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ForEach", + "parentIndex": 1, + "region": "Statement", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 30, + "clauseIndex": null, + "groupKind": null, + "listOperator": "None", + "bindingName": "f", + "bindingRaw": "$f", + "bindingSourceStart": 9, + "bindingSourceLength": 2, + "iterableRaw": "\u0027safe.txt\u0027", + "iterableSourceStart": 15, + "iterableSourceLength": 10 + }, + { + "kind": "Block", + "parentIndex": 2, + "region": "Iterator", + "childIndex": null, + "sourceStart": 15, + "sourceLength": 10, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "Block", + "parentIndex": 2, + "region": "LoopBody", + "childIndex": null, + "sourceStart": 28, + "sourceLength": 1, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 1, + "region": "Statement", + "childIndex": 1, + "sourceStart": 32, + "sourceLength": 44, + "clauseIndex": 0, + "groupKind": null, + "listOperator": "Sequence" + }, + { + "kind": "SimpleCommand", + "parentIndex": 1, + "region": "Statement", + "childIndex": 2, + "sourceStart": 78, + "sourceLength": 14, + "clauseIndex": 1, + "groupKind": null, + "listOperator": "Sequence" + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "Ordinary", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 92 + }, + { + "ancestorKind": "CommandList", + "region": "Statement", + "childIndex": 1, + "sourceStart": 0, + "sourceLength": 92 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 1, + "immediateRole": "Ordinary", + "isComplete": false, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 92 + }, + { + "ancestorKind": "CommandList", + "region": "Statement", + "childIndex": 2, + "sourceStart": 0, + "sourceLength": 92 + } + ], + "effectiveArguments": [ + { + "clauseElementIndex": 1, + "value": { + "kind": "Unknown", + "values": [], + "pattern": null, + "coveringDirectory": null + } + } + ], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Promotes stable design case pwsh-variable-writer-invalidates-proved-binding." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/517_v03_design_alternate_parameter_dash_gated.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/517_v03_design_alternate_parameter_dash_gated.json new file mode 100644 index 0000000..6b744bf --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/517_v03_design_alternate_parameter_dash_gated.json @@ -0,0 +1,11 @@ +{ + "name": "V03 design alternate parameter dash gated", + "input": "foreach ($f in \u0027safe.txt\u0027) { }; Write-Output C:/sensitive.txt \u2013OutVariable f; Remove-Item $f", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": true, + "unparseableReasonContains": "PowerShell parameter dash U\u002B2013 is not supported" + }, + "notes": "Promotes stable fail-closed design case pwsh-alternate-parameter-dash-gated.", + "oracleExpectation": "OutOfScope" +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/518_v03_design_structured_module_qualified_mutation_gated.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/518_v03_design_structured_module_qualified_mutation_gated.json new file mode 100644 index 0000000..7dc137c --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/518_v03_design_structured_module_qualified_mutation_gated.json @@ -0,0 +1,11 @@ +{ + "name": "V03 design structured module qualified mutation gated", + "input": "foreach ($f in \u0027safe.txt\u0027) { }; Write-Output C:/sensitive.txt | Microsoft.PowerShell.Utility\\Tee-Object -Variable f; Remove-Item $f", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": true, + "unparseableReasonContains": "module-qualified cmdlet \u0027Microsoft.PowerShell.Utility\\Tee-Object\u0027 is not supported in v0.2" + }, + "notes": "Promotes stable fail-closed design case pwsh-structured-module-qualified-mutation-gated.", + "oracleExpectation": "OutOfScope" +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/519_v03_design_dynamic_invoke_expression_invalidates_current_state.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/519_v03_design_dynamic_invoke_expression_invalidates_current_state.json new file mode 100644 index 0000000..5c03894 --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/519_v03_design_dynamic_invoke_expression_invalidates_current_state.json @@ -0,0 +1,259 @@ +{ + "name": "V03 design dynamic invoke expression invalidates current state", + "input": "foreach ($f in \u0027safe.txt\u0027) { }; Invoke-Expression $code; git $f", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "Sequence", + "verb": [ + "Invoke-Expression" + ], + "args": [ + { + "raw": "$code", + "kind": "DynamicSkip", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Invoke-Expression", + "value": "Invoke-Expression", + "role": "Verb", + "sourceStart": 32, + "sourceLength": 17, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "$code", + "value": "$code", + "role": "Argument", + "sourceStart": 50, + "sourceLength": 5, + "precedingVerbElementCount": 1, + "kind": "DynamicSkip", + "isFlag": false, + "isPath": false + } + ] + }, + { + "operator": "Sequence", + "verb": [ + "git" + ], + "args": [ + { + "raw": "$f", + "kind": "EnvVar", + "isPath": false + }, + { + "raw": "\u003Cdynamic-cwd\u003E", + "kind": "DynamicSkip", + "isPath": false, + "isCwdAttribution": true + } + ], + "redirects": [], + "elements": [ + { + "raw": "git", + "value": "git", + "role": "Verb", + "sourceStart": 57, + "sourceLength": 3, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "$f", + "value": "$f", + "role": "Argument", + "sourceStart": 61, + "sourceLength": 2, + "precedingVerbElementCount": 1, + "kind": "EnvVar", + "isFlag": false, + "isPath": false + } + ] + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 63, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "CommandList", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 63, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ForEach", + "parentIndex": 1, + "region": "Statement", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 30, + "clauseIndex": null, + "groupKind": null, + "listOperator": "None", + "bindingName": "f", + "bindingRaw": "$f", + "bindingSourceStart": 9, + "bindingSourceLength": 2, + "iterableRaw": "\u0027safe.txt\u0027", + "iterableSourceStart": 15, + "iterableSourceLength": 10 + }, + { + "kind": "Block", + "parentIndex": 2, + "region": "Iterator", + "childIndex": null, + "sourceStart": 15, + "sourceLength": 10, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "Block", + "parentIndex": 2, + "region": "LoopBody", + "childIndex": null, + "sourceStart": 28, + "sourceLength": 1, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 1, + "region": "Statement", + "childIndex": 1, + "sourceStart": 32, + "sourceLength": 23, + "clauseIndex": 0, + "groupKind": null, + "listOperator": "Sequence" + }, + { + "kind": "SimpleCommand", + "parentIndex": 1, + "region": "Statement", + "childIndex": 2, + "sourceStart": 57, + "sourceLength": 6, + "clauseIndex": 1, + "groupKind": null, + "listOperator": "Sequence" + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "Ordinary", + "isComplete": false, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 63 + }, + { + "ancestorKind": "CommandList", + "region": "Statement", + "childIndex": 1, + "sourceStart": 0, + "sourceLength": 63 + } + ], + "effectiveArguments": [ + { + "clauseElementIndex": 1, + "value": { + "kind": "Unknown", + "values": [], + "pattern": null, + "coveringDirectory": null + } + } + ], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 1, + "immediateRole": "Ordinary", + "isComplete": false, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 63 + }, + { + "ancestorKind": "CommandList", + "region": "Statement", + "childIndex": 2, + "sourceStart": 0, + "sourceLength": 63 + } + ], + "effectiveArguments": [ + { + "clauseElementIndex": 1, + "value": { + "kind": "Unknown", + "values": [], + "pattern": null, + "coveringDirectory": null + } + } + ], + "workingDirectory": { + "kind": "Unknown", + "values": [], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Promotes stable design case pwsh-dynamic-invoke-expression-invalidates-current-state." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/520_v03_design_foreach_binding_is_case_insensitive.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/520_v03_design_foreach_binding_is_case_insensitive.json new file mode 100644 index 0000000..948017d --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/520_v03_design_foreach_binding_is_case_insensitive.json @@ -0,0 +1,164 @@ +{ + "name": "V03 design foreach binding is case insensitive", + "input": "foreach ($f in @(\u0027a\u0027)) { Write-Output $F }", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "None", + "verb": [ + "Write-Output" + ], + "args": [ + { + "raw": "$F", + "kind": "EnvVar", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Write-Output", + "value": "Write-Output", + "role": "Verb", + "sourceStart": 25, + "sourceLength": 12, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "$F", + "value": "$F", + "role": "Argument", + "sourceStart": 38, + "sourceLength": 2, + "precedingVerbElementCount": 1, + "kind": "EnvVar", + "isFlag": false, + "isPath": false + } + ] + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 42, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ForEach", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 42, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "bindingName": "f", + "bindingRaw": "$f", + "bindingSourceStart": 9, + "bindingSourceLength": 2, + "iterableRaw": "@(\u0027a\u0027)", + "iterableSourceStart": 15, + "iterableSourceLength": 6 + }, + { + "kind": "Block", + "parentIndex": 1, + "region": "Iterator", + "childIndex": null, + "sourceStart": 15, + "sourceLength": 6, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "Block", + "parentIndex": 1, + "region": "LoopBody", + "childIndex": null, + "sourceStart": 24, + "sourceLength": 17, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 3, + "region": "Statement", + "childIndex": 0, + "sourceStart": 25, + "sourceLength": 15, + "clauseIndex": 0, + "groupKind": null, + "listOperator": null + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "LoopBody", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 42 + }, + { + "ancestorKind": "ForEach", + "region": "LoopBody", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 42 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 24, + "sourceLength": 17 + } + ], + "effectiveArguments": [ + { + "clauseElementIndex": 1, + "value": { + "kind": "Exact", + "values": [ + "a" + ], + "pattern": null, + "coveringDirectory": null + } + } + ], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Promotes stable design case pwsh-foreach-binding-is-case-insensitive." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/521_v03_design_nested_same_name_foreach_overwrites_binding.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/521_v03_design_nested_same_name_foreach_overwrites_binding.json new file mode 100644 index 0000000..59f362f --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/521_v03_design_nested_same_name_foreach_overwrites_binding.json @@ -0,0 +1,457 @@ +{ + "name": "V03 design nested same name foreach overwrites binding", + "input": "foreach ($f in @(\u0027outer\u0027)) { foreach ($f in @(\u0027inner\u0027)) { Write-Output $f }; Write-Output $f }; Write-Output $f", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "None", + "verb": [ + "Write-Output" + ], + "args": [ + { + "raw": "$f", + "kind": "EnvVar", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Write-Output", + "value": "Write-Output", + "role": "Verb", + "sourceStart": 58, + "sourceLength": 12, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "$f", + "value": "$f", + "role": "Argument", + "sourceStart": 71, + "sourceLength": 2, + "precedingVerbElementCount": 1, + "kind": "EnvVar", + "isFlag": false, + "isPath": false + } + ] + }, + { + "operator": "Sequence", + "verb": [ + "Write-Output" + ], + "args": [ + { + "raw": "$f", + "kind": "EnvVar", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Write-Output", + "value": "Write-Output", + "role": "Verb", + "sourceStart": 77, + "sourceLength": 12, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "$f", + "value": "$f", + "role": "Argument", + "sourceStart": 90, + "sourceLength": 2, + "precedingVerbElementCount": 1, + "kind": "EnvVar", + "isFlag": false, + "isPath": false + } + ] + }, + { + "operator": "Sequence", + "verb": [ + "Write-Output" + ], + "args": [ + { + "raw": "$f", + "kind": "EnvVar", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Write-Output", + "value": "Write-Output", + "role": "Verb", + "sourceStart": 96, + "sourceLength": 12, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "$f", + "value": "$f", + "role": "Argument", + "sourceStart": 109, + "sourceLength": 2, + "precedingVerbElementCount": 1, + "kind": "EnvVar", + "isFlag": false, + "isPath": false + } + ] + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 111, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "CommandList", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 111, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ForEach", + "parentIndex": 1, + "region": "Statement", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 94, + "clauseIndex": null, + "groupKind": null, + "listOperator": "None", + "bindingName": "f", + "bindingRaw": "$f", + "bindingSourceStart": 9, + "bindingSourceLength": 2, + "iterableRaw": "@(\u0027outer\u0027)", + "iterableSourceStart": 15, + "iterableSourceLength": 10 + }, + { + "kind": "Block", + "parentIndex": 2, + "region": "Iterator", + "childIndex": null, + "sourceStart": 15, + "sourceLength": 10, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "Block", + "parentIndex": 2, + "region": "LoopBody", + "childIndex": null, + "sourceStart": 28, + "sourceLength": 65, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "CommandList", + "parentIndex": 4, + "region": "Statement", + "childIndex": 0, + "sourceStart": 29, + "sourceLength": 63, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ForEach", + "parentIndex": 5, + "region": "Statement", + "childIndex": 0, + "sourceStart": 29, + "sourceLength": 46, + "clauseIndex": null, + "groupKind": null, + "listOperator": "None", + "bindingName": "f", + "bindingRaw": "$f", + "bindingSourceStart": 38, + "bindingSourceLength": 2, + "iterableRaw": "@(\u0027inner\u0027)", + "iterableSourceStart": 44, + "iterableSourceLength": 10 + }, + { + "kind": "Block", + "parentIndex": 6, + "region": "Iterator", + "childIndex": null, + "sourceStart": 44, + "sourceLength": 10, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "Block", + "parentIndex": 6, + "region": "LoopBody", + "childIndex": null, + "sourceStart": 57, + "sourceLength": 17, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 8, + "region": "Statement", + "childIndex": 0, + "sourceStart": 58, + "sourceLength": 15, + "clauseIndex": 0, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 5, + "region": "Statement", + "childIndex": 1, + "sourceStart": 77, + "sourceLength": 15, + "clauseIndex": 1, + "groupKind": null, + "listOperator": "Sequence" + }, + { + "kind": "SimpleCommand", + "parentIndex": 1, + "region": "Statement", + "childIndex": 1, + "sourceStart": 96, + "sourceLength": 15, + "clauseIndex": 2, + "groupKind": null, + "listOperator": "Sequence" + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "LoopBody", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 111 + }, + { + "ancestorKind": "CommandList", + "region": "Statement", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 111 + }, + { + "ancestorKind": "ForEach", + "region": "LoopBody", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 94 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 28, + "sourceLength": 65 + }, + { + "ancestorKind": "CommandList", + "region": "Statement", + "childIndex": 0, + "sourceStart": 29, + "sourceLength": 63 + }, + { + "ancestorKind": "ForEach", + "region": "LoopBody", + "childIndex": null, + "sourceStart": 29, + "sourceLength": 46 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 57, + "sourceLength": 17 + } + ], + "effectiveArguments": [ + { + "clauseElementIndex": 1, + "value": { + "kind": "Exact", + "values": [ + "inner" + ], + "pattern": null, + "coveringDirectory": null + } + } + ], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 1, + "immediateRole": "LoopBody", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 111 + }, + { + "ancestorKind": "CommandList", + "region": "Statement", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 111 + }, + { + "ancestorKind": "ForEach", + "region": "LoopBody", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 94 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 28, + "sourceLength": 65 + }, + { + "ancestorKind": "CommandList", + "region": "Statement", + "childIndex": 1, + "sourceStart": 29, + "sourceLength": 63 + } + ], + "effectiveArguments": [ + { + "clauseElementIndex": 1, + "value": { + "kind": "Exact", + "values": [ + "inner" + ], + "pattern": null, + "coveringDirectory": null + } + } + ], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 2, + "immediateRole": "Ordinary", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 111 + }, + { + "ancestorKind": "CommandList", + "region": "Statement", + "childIndex": 1, + "sourceStart": 0, + "sourceLength": 111 + } + ], + "effectiveArguments": [ + { + "clauseElementIndex": 1, + "value": { + "kind": "Exact", + "values": [ + "inner" + ], + "pattern": null, + "coveringDirectory": null + } + } + ], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Promotes stable design case pwsh-nested-same-name-foreach-overwrites-binding." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/522_v03_design_foreach_binding_used_as_redirect_target.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/522_v03_design_foreach_binding_used_as_redirect_target.json new file mode 100644 index 0000000..8b9812d --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/522_v03_design_foreach_binding_used_as_redirect_target.json @@ -0,0 +1,189 @@ +{ + "name": "V03 design foreach binding used as redirect target", + "input": "foreach ($f in @(\u0027a.log\u0027,\u0027b.log\u0027)) { Write-Output payload \u003E $f }", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "None", + "verb": [ + "Write-Output" + ], + "args": [ + { + "raw": "payload", + "kind": "Literal", + "isPath": false + } + ], + "redirects": [ + { + "direction": "Out", + "target": "$f", + "isDynamicSkip": true + } + ], + "elements": [ + { + "raw": "Write-Output", + "value": "Write-Output", + "role": "Verb", + "sourceStart": 37, + "sourceLength": 12, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "payload", + "value": "payload", + "role": "Argument", + "sourceStart": 50, + "sourceLength": 7, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "\u003E $f", + "value": "$f", + "role": "Redirect", + "sourceStart": 58, + "sourceLength": 4, + "precedingVerbElementCount": 1, + "kind": "DynamicSkip", + "isFlag": false, + "isPath": false + } + ] + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 64, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ForEach", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 64, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "bindingName": "f", + "bindingRaw": "$f", + "bindingSourceStart": 9, + "bindingSourceLength": 2, + "iterableRaw": "@(\u0027a.log\u0027,\u0027b.log\u0027)", + "iterableSourceStart": 15, + "iterableSourceLength": 18 + }, + { + "kind": "Block", + "parentIndex": 1, + "region": "Iterator", + "childIndex": null, + "sourceStart": 15, + "sourceLength": 18, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "Block", + "parentIndex": 1, + "region": "LoopBody", + "childIndex": null, + "sourceStart": 36, + "sourceLength": 27, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 3, + "region": "Statement", + "childIndex": 0, + "sourceStart": 37, + "sourceLength": 25, + "clauseIndex": 0, + "groupKind": null, + "listOperator": null + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "LoopBody", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 64 + }, + { + "ancestorKind": "ForEach", + "region": "LoopBody", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 64 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 36, + "sourceLength": 27 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + }, + "redirects": [ + { + "redirectIndex": 0, + "sourceKind": "Default", + "sourceDescriptor": null, + "operation": "FileOutput", + "targetDescriptor": null, + "target": { + "kind": "FiniteSet", + "values": [ + "C:/work/a.log", + "C:/work/b.log" + ], + "pattern": null, + "coveringDirectory": null + }, + "isPathRelevant": true, + "isComplete": true + } + ] + } + ] + }, + "notes": "Promotes stable design case pwsh-foreach-binding-used-as-redirect-target." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/523_v03_design_foreach_current_runspace_invoke_expression.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/523_v03_design_foreach_current_runspace_invoke_expression.json new file mode 100644 index 0000000..0aa352f --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/523_v03_design_foreach_current_runspace_invoke_expression.json @@ -0,0 +1,202 @@ +{ + "name": "V03 design foreach current runspace invoke expression", + "input": "foreach ($f in @(\u0027a\u0027,\u0027b\u0027)) { Invoke-Expression \u0027Write-Output $f\u0027 }", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "None", + "verb": [ + "Write-Output" + ], + "args": [ + { + "raw": "$f", + "kind": "EnvVar", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Write-Output", + "value": "Write-Output", + "role": "Verb", + "sourceStart": null, + "sourceLength": null, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "$f", + "value": "$f", + "role": "Argument", + "sourceStart": null, + "sourceLength": null, + "precedingVerbElementCount": 1, + "kind": "EnvVar", + "isFlag": false, + "isPath": false + } + ], + "isCommandStringWrapped": true + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 66, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ForEach", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 66, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "bindingName": "f", + "bindingRaw": "$f", + "bindingSourceStart": 9, + "bindingSourceLength": 2, + "iterableRaw": "@(\u0027a\u0027,\u0027b\u0027)", + "iterableSourceStart": 15, + "iterableSourceLength": 10 + }, + { + "kind": "Block", + "parentIndex": 1, + "region": "Iterator", + "childIndex": null, + "sourceStart": 15, + "sourceLength": 10, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "Block", + "parentIndex": 1, + "region": "LoopBody", + "childIndex": null, + "sourceStart": 28, + "sourceLength": 37, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "Group", + "parentIndex": 3, + "region": "Statement", + "childIndex": 0, + "sourceStart": 29, + "sourceLength": 35, + "clauseIndex": null, + "groupKind": "CurrentScope", + "listOperator": null + }, + { + "kind": "Block", + "parentIndex": 4, + "region": "GroupBody", + "childIndex": null, + "sourceStart": null, + "sourceLength": null, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 5, + "region": "Statement", + "childIndex": 0, + "sourceStart": null, + "sourceLength": null, + "clauseIndex": 0, + "groupKind": null, + "listOperator": null + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "LoopBody", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 66 + }, + { + "ancestorKind": "ForEach", + "region": "LoopBody", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 66 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 28, + "sourceLength": 37 + }, + { + "ancestorKind": "Group", + "region": "GroupBody", + "childIndex": null, + "sourceStart": 29, + "sourceLength": 35 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": null, + "sourceLength": null + } + ], + "effectiveArguments": [ + { + "clauseElementIndex": 1, + "value": { + "kind": "FiniteSet", + "values": [ + "a", + "b" + ], + "pattern": null, + "coveringDirectory": null + } + } + ], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Promotes stable design case pwsh-foreach-current-runspace-invoke-expression." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/524_v03_design_foreach_child_host_does_not_inherit_state_mode.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/524_v03_design_foreach_child_host_does_not_inherit_state_mode.json new file mode 100644 index 0000000..44fb741 --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/524_v03_design_foreach_child_host_does_not_inherit_state_mode.json @@ -0,0 +1,199 @@ +{ + "name": "V03 design foreach child host does not inherit state mode", + "input": "pwsh -NoProfile -NonInteractive -Command \u0027foreach ($f in @(\u0022a\u0022)) { Write-Output $f }\u0027", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "None", + "verb": [ + "Write-Output" + ], + "args": [ + { + "raw": "$f", + "kind": "EnvVar", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Write-Output", + "value": "Write-Output", + "role": "Verb", + "sourceStart": null, + "sourceLength": null, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "$f", + "value": "$f", + "role": "Argument", + "sourceStart": null, + "sourceLength": null, + "precedingVerbElementCount": 1, + "kind": "EnvVar", + "isFlag": false, + "isPath": false + } + ], + "isCommandStringWrapped": true + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 85, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "Group", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 85, + "clauseIndex": null, + "groupKind": "IsolatedScope", + "listOperator": null + }, + { + "kind": "Block", + "parentIndex": 1, + "region": "GroupBody", + "childIndex": null, + "sourceStart": null, + "sourceLength": null, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ForEach", + "parentIndex": 2, + "region": "Statement", + "childIndex": 0, + "sourceStart": null, + "sourceLength": null, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "bindingName": "f", + "bindingRaw": "$f", + "bindingSourceStart": null, + "bindingSourceLength": null, + "iterableRaw": "@(\u0022a\u0022)", + "iterableSourceStart": null, + "iterableSourceLength": null + }, + { + "kind": "Block", + "parentIndex": 3, + "region": "Iterator", + "childIndex": null, + "sourceStart": null, + "sourceLength": null, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "Block", + "parentIndex": 3, + "region": "LoopBody", + "childIndex": null, + "sourceStart": null, + "sourceLength": null, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 5, + "region": "Statement", + "childIndex": 0, + "sourceStart": null, + "sourceLength": null, + "clauseIndex": 0, + "groupKind": null, + "listOperator": null + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "LoopBody", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 85 + }, + { + "ancestorKind": "Group", + "region": "GroupBody", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 85 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": null, + "sourceLength": null + }, + { + "ancestorKind": "ForEach", + "region": "LoopBody", + "childIndex": null, + "sourceStart": null, + "sourceLength": null + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": null, + "sourceLength": null + } + ], + "effectiveArguments": [ + { + "clauseElementIndex": 1, + "value": { + "kind": "Unknown", + "values": [], + "pattern": null, + "coveringDirectory": null + } + } + ], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Promotes stable design case pwsh-foreach-child-host-does-not-inherit-state-mode." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/525_v03_design_dot_source_script_block_region.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/525_v03_design_dot_source_script_block_region.json new file mode 100644 index 0000000..41bb31a --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/525_v03_design_dot_source_script_block_region.json @@ -0,0 +1,122 @@ +{ + "name": "V03 design dot source script block region", + "input": ". { Get-Location }", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "None", + "verb": [ + "Get-Location" + ], + "args": [], + "redirects": [], + "elements": [ + { + "raw": "Get-Location", + "value": "Get-Location", + "role": "Verb", + "sourceStart": 4, + "sourceLength": 12, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + } + ] + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 18, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ExecutionRegion", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 2, + "sourceLength": 16, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "executionOrigin": "DotSource", + "hostClauseElementIndex": null, + "executionPhase": "Main", + "executionTiming": "Synchronous", + "executionCardinality": "Once" + }, + { + "kind": "Block", + "parentIndex": 1, + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 3, + "sourceLength": 14, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 2, + "region": "Statement", + "childIndex": 0, + "sourceStart": 4, + "sourceLength": 12, + "clauseIndex": 0, + "groupKind": null, + "listOperator": null + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "ExecutionRegion", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 18 + }, + { + "ancestorKind": "ExecutionRegion", + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 2, + "sourceLength": 16 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 3, + "sourceLength": 14 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Promotes stable design case pwsh-dot-source-script-block-region." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/526_v03_design_pipeline_foreach_alias.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/526_v03_design_pipeline_foreach_alias.json new file mode 100644 index 0000000..d8f5c10 --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/526_v03_design_pipeline_foreach_alias.json @@ -0,0 +1,307 @@ +{ + "name": "V03 design pipeline foreach alias", + "input": "Get-ChildItem | foreach { Remove-Item $_ }", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "None", + "verb": [ + "Get-ChildItem" + ], + "args": [], + "redirects": [], + "elements": [ + { + "raw": "Get-ChildItem", + "value": "Get-ChildItem", + "role": "Verb", + "sourceStart": 0, + "sourceLength": 13, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + } + ] + }, + { + "operator": "Pipe", + "verb": [ + "foreach" + ], + "canonicalVerb": "ForEach-Object", + "args": [ + { + "raw": "{ Remove-Item $_ }", + "kind": "DynamicSkip", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "foreach", + "value": "foreach", + "role": "Verb", + "sourceStart": 16, + "sourceLength": 7, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "{ Remove-Item $_ }", + "value": "{ Remove-Item $_ }", + "role": "Argument", + "sourceStart": 24, + "sourceLength": 18, + "precedingVerbElementCount": 1, + "kind": "DynamicSkip", + "isFlag": false, + "isPath": false + } + ] + }, + { + "operator": "None", + "verb": [ + "Remove-Item" + ], + "args": [ + { + "raw": "$_", + "kind": "DynamicSkip", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Remove-Item", + "value": "Remove-Item", + "role": "Verb", + "sourceStart": 26, + "sourceLength": 11, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "$_", + "value": "$_", + "role": "Argument", + "sourceStart": 38, + "sourceLength": 2, + "precedingVerbElementCount": 1, + "kind": "DynamicSkip", + "isFlag": false, + "isPath": false + } + ] + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 42, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "Pipeline", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 42, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 1, + "region": "PipelineStage", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 13, + "clauseIndex": 0, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 1, + "region": "PipelineStage", + "childIndex": 1, + "sourceStart": 16, + "sourceLength": 26, + "clauseIndex": 1, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ExecutionRegion", + "parentIndex": 3, + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 24, + "sourceLength": 18, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "executionOrigin": "CommandArgument", + "hostClauseElementIndex": 1, + "executionPhase": "Process", + "executionTiming": "Synchronous", + "executionCardinality": "OncePerInputObject" + }, + { + "kind": "Block", + "parentIndex": 4, + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 25, + "sourceLength": 16, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 5, + "region": "Statement", + "childIndex": 0, + "sourceStart": 26, + "sourceLength": 14, + "clauseIndex": 2, + "groupKind": null, + "listOperator": null + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "PipelineStage", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 42 + }, + { + "ancestorKind": "Pipeline", + "region": "PipelineStage", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 42 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 1, + "immediateRole": "PipelineStage", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 42 + }, + { + "ancestorKind": "Pipeline", + "region": "PipelineStage", + "childIndex": 1, + "sourceStart": 0, + "sourceLength": 42 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 2, + "immediateRole": "ExecutionRegion", + "isComplete": false, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 42 + }, + { + "ancestorKind": "Pipeline", + "region": "PipelineStage", + "childIndex": 1, + "sourceStart": 0, + "sourceLength": 42 + }, + { + "ancestorKind": "ExecutionRegion", + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 24, + "sourceLength": 18 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 25, + "sourceLength": 16 + } + ], + "effectiveArguments": [ + { + "clauseElementIndex": 1, + "value": { + "kind": "Unknown", + "values": [], + "pattern": null, + "coveringDirectory": null + } + } + ], + "workingDirectory": { + "kind": "Unknown", + "values": [], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Promotes stable design case pwsh-pipeline-foreach-alias." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/527_v03_design_where_object_filter_region.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/527_v03_design_where_object_filter_region.json new file mode 100644 index 0000000..8444548 --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/527_v03_design_where_object_filter_region.json @@ -0,0 +1,324 @@ +{ + "name": "V03 design where object filter region", + "input": "Get-ChildItem | Where-Object -FilterScript { Test-Path $_ }", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "None", + "verb": [ + "Get-ChildItem" + ], + "args": [], + "redirects": [], + "elements": [ + { + "raw": "Get-ChildItem", + "value": "Get-ChildItem", + "role": "Verb", + "sourceStart": 0, + "sourceLength": 13, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + } + ] + }, + { + "operator": "Pipe", + "verb": [ + "Where-Object" + ], + "args": [ + { + "raw": "-FilterScript", + "kind": "Literal", + "isPath": false + }, + { + "raw": "{ Test-Path $_ }", + "kind": "DynamicSkip", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Where-Object", + "value": "Where-Object", + "role": "Verb", + "sourceStart": 16, + "sourceLength": 12, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "-FilterScript", + "value": "-FilterScript", + "role": "Argument", + "sourceStart": 29, + "sourceLength": 13, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": true, + "isPath": false + }, + { + "raw": "{ Test-Path $_ }", + "value": "{ Test-Path $_ }", + "role": "Argument", + "sourceStart": 43, + "sourceLength": 16, + "precedingVerbElementCount": 1, + "kind": "DynamicSkip", + "isFlag": false, + "isPath": false + } + ] + }, + { + "operator": "None", + "verb": [ + "Test-Path" + ], + "args": [ + { + "raw": "$_", + "kind": "DynamicSkip", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Test-Path", + "value": "Test-Path", + "role": "Verb", + "sourceStart": 45, + "sourceLength": 9, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "$_", + "value": "$_", + "role": "Argument", + "sourceStart": 55, + "sourceLength": 2, + "precedingVerbElementCount": 1, + "kind": "DynamicSkip", + "isFlag": false, + "isPath": false + } + ] + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 59, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "Pipeline", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 59, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 1, + "region": "PipelineStage", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 13, + "clauseIndex": 0, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 1, + "region": "PipelineStage", + "childIndex": 1, + "sourceStart": 16, + "sourceLength": 43, + "clauseIndex": 1, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ExecutionRegion", + "parentIndex": 3, + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 43, + "sourceLength": 16, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "executionOrigin": "CommandArgument", + "hostClauseElementIndex": 2, + "executionPhase": "Filter", + "executionTiming": "Synchronous", + "executionCardinality": "OncePerInputObject" + }, + { + "kind": "Block", + "parentIndex": 4, + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 44, + "sourceLength": 14, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 5, + "region": "Statement", + "childIndex": 0, + "sourceStart": 45, + "sourceLength": 12, + "clauseIndex": 2, + "groupKind": null, + "listOperator": null + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "PipelineStage", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 59 + }, + { + "ancestorKind": "Pipeline", + "region": "PipelineStage", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 59 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 1, + "immediateRole": "PipelineStage", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 59 + }, + { + "ancestorKind": "Pipeline", + "region": "PipelineStage", + "childIndex": 1, + "sourceStart": 0, + "sourceLength": 59 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 2, + "immediateRole": "ExecutionRegion", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 59 + }, + { + "ancestorKind": "Pipeline", + "region": "PipelineStage", + "childIndex": 1, + "sourceStart": 0, + "sourceLength": 59 + }, + { + "ancestorKind": "ExecutionRegion", + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 43, + "sourceLength": 16 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 44, + "sourceLength": 14 + } + ], + "effectiveArguments": [ + { + "clauseElementIndex": 1, + "value": { + "kind": "Unknown", + "values": [], + "pattern": null, + "coveringDirectory": null + } + } + ], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Promotes stable design case pwsh-where-object-filter-region." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/528_v03_design_foreach_object_authored_versus_phase_order.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/528_v03_design_foreach_object_authored_versus_phase_order.json new file mode 100644 index 0000000..0e3320e --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/528_v03_design_foreach_object_authored_versus_phase_order.json @@ -0,0 +1,517 @@ +{ + "name": "V03 design foreach object authored versus phase order", + "input": "ForEach-Object -End { Write-Output end } -Begin { Write-Output begin } -Process { Write-Output process }", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "None", + "verb": [ + "ForEach-Object" + ], + "args": [ + { + "raw": "-End", + "kind": "Literal", + "isPath": false + }, + { + "raw": "{ Write-Output end }", + "kind": "DynamicSkip", + "isPath": false + }, + { + "raw": "-Begin", + "kind": "Literal", + "isPath": false + }, + { + "raw": "{ Write-Output begin }", + "kind": "DynamicSkip", + "isPath": false + }, + { + "raw": "-Process", + "kind": "Literal", + "isPath": false + }, + { + "raw": "{ Write-Output process }", + "kind": "DynamicSkip", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "ForEach-Object", + "value": "ForEach-Object", + "role": "Verb", + "sourceStart": 0, + "sourceLength": 14, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "-End", + "value": "-End", + "role": "Argument", + "sourceStart": 15, + "sourceLength": 4, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": true, + "isPath": false + }, + { + "raw": "{ Write-Output end }", + "value": "{ Write-Output end }", + "role": "Argument", + "sourceStart": 20, + "sourceLength": 20, + "precedingVerbElementCount": 1, + "kind": "DynamicSkip", + "isFlag": false, + "isPath": false + }, + { + "raw": "-Begin", + "value": "-Begin", + "role": "Argument", + "sourceStart": 41, + "sourceLength": 6, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": true, + "isPath": false + }, + { + "raw": "{ Write-Output begin }", + "value": "{ Write-Output begin }", + "role": "Argument", + "sourceStart": 48, + "sourceLength": 22, + "precedingVerbElementCount": 1, + "kind": "DynamicSkip", + "isFlag": false, + "isPath": false + }, + { + "raw": "-Process", + "value": "-Process", + "role": "Argument", + "sourceStart": 71, + "sourceLength": 8, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": true, + "isPath": false + }, + { + "raw": "{ Write-Output process }", + "value": "{ Write-Output process }", + "role": "Argument", + "sourceStart": 80, + "sourceLength": 24, + "precedingVerbElementCount": 1, + "kind": "DynamicSkip", + "isFlag": false, + "isPath": false + } + ] + }, + { + "operator": "None", + "verb": [ + "Write-Output" + ], + "args": [ + { + "raw": "end", + "kind": "Literal", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Write-Output", + "value": "Write-Output", + "role": "Verb", + "sourceStart": 22, + "sourceLength": 12, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "end", + "value": "end", + "role": "Argument", + "sourceStart": 35, + "sourceLength": 3, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": false, + "isPath": false + } + ] + }, + { + "operator": "None", + "verb": [ + "Write-Output" + ], + "args": [ + { + "raw": "begin", + "kind": "Literal", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Write-Output", + "value": "Write-Output", + "role": "Verb", + "sourceStart": 50, + "sourceLength": 12, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "begin", + "value": "begin", + "role": "Argument", + "sourceStart": 63, + "sourceLength": 5, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": false, + "isPath": false + } + ] + }, + { + "operator": "None", + "verb": [ + "Write-Output" + ], + "args": [ + { + "raw": "process", + "kind": "Literal", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Write-Output", + "value": "Write-Output", + "role": "Verb", + "sourceStart": 82, + "sourceLength": 12, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "process", + "value": "process", + "role": "Argument", + "sourceStart": 95, + "sourceLength": 7, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": false, + "isPath": false + } + ] + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 104, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 104, + "clauseIndex": 0, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ExecutionRegion", + "parentIndex": 1, + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 20, + "sourceLength": 20, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "executionOrigin": "CommandArgument", + "hostClauseElementIndex": 2, + "executionPhase": "End", + "executionTiming": "Synchronous", + "executionCardinality": "Once" + }, + { + "kind": "Block", + "parentIndex": 2, + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 21, + "sourceLength": 18, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 3, + "region": "Statement", + "childIndex": 0, + "sourceStart": 22, + "sourceLength": 16, + "clauseIndex": 1, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ExecutionRegion", + "parentIndex": 1, + "region": "ExecutionRegion", + "childIndex": 1, + "sourceStart": 48, + "sourceLength": 22, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "executionOrigin": "CommandArgument", + "hostClauseElementIndex": 4, + "executionPhase": "Begin", + "executionTiming": "Synchronous", + "executionCardinality": "Once" + }, + { + "kind": "Block", + "parentIndex": 5, + "region": "ExecutionRegion", + "childIndex": 1, + "sourceStart": 49, + "sourceLength": 20, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 6, + "region": "Statement", + "childIndex": 0, + "sourceStart": 50, + "sourceLength": 18, + "clauseIndex": 2, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ExecutionRegion", + "parentIndex": 1, + "region": "ExecutionRegion", + "childIndex": 2, + "sourceStart": 80, + "sourceLength": 24, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "executionOrigin": "CommandArgument", + "hostClauseElementIndex": 6, + "executionPhase": "Process", + "executionTiming": "Synchronous", + "executionCardinality": "OncePerInputObject" + }, + { + "kind": "Block", + "parentIndex": 8, + "region": "ExecutionRegion", + "childIndex": 2, + "sourceStart": 81, + "sourceLength": 22, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 9, + "region": "Statement", + "childIndex": 0, + "sourceStart": 82, + "sourceLength": 20, + "clauseIndex": 3, + "groupKind": null, + "listOperator": null + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "Ordinary", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 104 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 1, + "immediateRole": "ExecutionRegion", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 104 + }, + { + "ancestorKind": "ExecutionRegion", + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 20, + "sourceLength": 20 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 21, + "sourceLength": 18 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 2, + "immediateRole": "ExecutionRegion", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 104 + }, + { + "ancestorKind": "ExecutionRegion", + "region": "ExecutionRegion", + "childIndex": 1, + "sourceStart": 48, + "sourceLength": 22 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 49, + "sourceLength": 20 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 3, + "immediateRole": "ExecutionRegion", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 104 + }, + { + "ancestorKind": "ExecutionRegion", + "region": "ExecutionRegion", + "childIndex": 2, + "sourceStart": 80, + "sourceLength": 24 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 81, + "sourceLength": 22 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Promotes stable design case pwsh-foreach-object-authored-versus-phase-order." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/529_v03_design_invoke_command_local_region.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/529_v03_design_invoke_command_local_region.json new file mode 100644 index 0000000..ab10d65 --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/529_v03_design_invoke_command_local_region.json @@ -0,0 +1,229 @@ +{ + "name": "V03 design invoke command local region", + "input": "Invoke-Command -ScriptBlock { Get-Item child.txt }", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "None", + "verb": [ + "Invoke-Command" + ], + "args": [ + { + "raw": "-ScriptBlock", + "kind": "Literal", + "isPath": false + }, + { + "raw": "{ Get-Item child.txt }", + "kind": "DynamicSkip", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Invoke-Command", + "value": "Invoke-Command", + "role": "Verb", + "sourceStart": 0, + "sourceLength": 14, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "-ScriptBlock", + "value": "-ScriptBlock", + "role": "Argument", + "sourceStart": 15, + "sourceLength": 12, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": true, + "isPath": false + }, + { + "raw": "{ Get-Item child.txt }", + "value": "{ Get-Item child.txt }", + "role": "Argument", + "sourceStart": 28, + "sourceLength": 22, + "precedingVerbElementCount": 1, + "kind": "DynamicSkip", + "isFlag": false, + "isPath": false + } + ] + }, + { + "operator": "None", + "verb": [ + "Get-Item" + ], + "args": [ + { + "raw": "child.txt", + "kind": "Literal", + "isPath": true, + "resolved": "C:/work/child.txt" + } + ], + "redirects": [], + "elements": [ + { + "raw": "Get-Item", + "value": "Get-Item", + "role": "Verb", + "sourceStart": 30, + "sourceLength": 8, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "child.txt", + "value": "child.txt", + "role": "Argument", + "sourceStart": 39, + "sourceLength": 9, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": false, + "isPath": true, + "resolved": "C:/work/child.txt" + } + ] + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 50, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 50, + "clauseIndex": 0, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ExecutionRegion", + "parentIndex": 1, + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 28, + "sourceLength": 22, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "executionOrigin": "CommandArgument", + "hostClauseElementIndex": 2, + "executionPhase": "Main", + "executionTiming": "Synchronous", + "executionCardinality": "Once" + }, + { + "kind": "Block", + "parentIndex": 2, + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 29, + "sourceLength": 20, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 3, + "region": "Statement", + "childIndex": 0, + "sourceStart": 30, + "sourceLength": 18, + "clauseIndex": 1, + "groupKind": null, + "listOperator": null + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "Ordinary", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 50 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 1, + "immediateRole": "ExecutionRegion", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 50 + }, + { + "ancestorKind": "ExecutionRegion", + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 28, + "sourceLength": 22 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 29, + "sourceLength": 20 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Promotes stable design case pwsh-invoke-command-local-region." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/530_v03_design_invoke_command_remote_region.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/530_v03_design_invoke_command_remote_region.json new file mode 100644 index 0000000..9c071cd --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/530_v03_design_invoke_command_remote_region.json @@ -0,0 +1,263 @@ +{ + "name": "V03 design invoke command remote region", + "input": "Invoke-Command -ComputerName server -ScriptBlock { Get-Item child.txt }", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "None", + "verb": [ + "Invoke-Command" + ], + "args": [ + { + "raw": "-ComputerName", + "kind": "Literal", + "isPath": false + }, + { + "raw": "server", + "kind": "Literal", + "isPath": false + }, + { + "raw": "-ScriptBlock", + "kind": "Literal", + "isPath": false + }, + { + "raw": "{ Get-Item child.txt }", + "kind": "DynamicSkip", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Invoke-Command", + "value": "Invoke-Command", + "role": "Verb", + "sourceStart": 0, + "sourceLength": 14, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "-ComputerName", + "value": "-ComputerName", + "role": "Argument", + "sourceStart": 15, + "sourceLength": 13, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": true, + "isPath": false + }, + { + "raw": "server", + "value": "server", + "role": "Argument", + "sourceStart": 29, + "sourceLength": 6, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "-ScriptBlock", + "value": "-ScriptBlock", + "role": "Argument", + "sourceStart": 36, + "sourceLength": 12, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": true, + "isPath": false + }, + { + "raw": "{ Get-Item child.txt }", + "value": "{ Get-Item child.txt }", + "role": "Argument", + "sourceStart": 49, + "sourceLength": 22, + "precedingVerbElementCount": 1, + "kind": "DynamicSkip", + "isFlag": false, + "isPath": false + } + ] + }, + { + "operator": "None", + "verb": [ + "Get-Item" + ], + "args": [ + { + "raw": "child.txt", + "kind": "Literal", + "isPath": true + }, + { + "raw": "\u003Cdynamic-cwd\u003E", + "kind": "DynamicSkip", + "isPath": false, + "isCwdAttribution": true + } + ], + "redirects": [], + "elements": [ + { + "raw": "Get-Item", + "value": "Get-Item", + "role": "Verb", + "sourceStart": 51, + "sourceLength": 8, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "child.txt", + "value": "child.txt", + "role": "Argument", + "sourceStart": 60, + "sourceLength": 9, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": false, + "isPath": true + } + ] + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 71, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 71, + "clauseIndex": 0, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ExecutionRegion", + "parentIndex": 1, + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 49, + "sourceLength": 22, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "executionOrigin": "CommandArgument", + "hostClauseElementIndex": 4, + "executionPhase": "Main", + "executionTiming": "Synchronous", + "executionCardinality": "Once" + }, + { + "kind": "Block", + "parentIndex": 2, + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 50, + "sourceLength": 20, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 3, + "region": "Statement", + "childIndex": 0, + "sourceStart": 51, + "sourceLength": 18, + "clauseIndex": 1, + "groupKind": null, + "listOperator": null + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "Ordinary", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 71 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 1, + "immediateRole": "ExecutionRegion", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 71 + }, + { + "ancestorKind": "ExecutionRegion", + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 49, + "sourceLength": 22 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 50, + "sourceLength": 20 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Unknown", + "values": [], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Promotes stable design case pwsh-invoke-command-remote-region." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/531_v03_design_start_job_initialization_and_main.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/531_v03_design_start_job_initialization_and_main.json new file mode 100644 index 0000000..adc1c34 --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/531_v03_design_start_job_initialization_and_main.json @@ -0,0 +1,372 @@ +{ + "name": "V03 design start job initialization and main", + "input": "Start-Job -ScriptBlock { Write-Output main } -InitializationScript { Write-Output init }", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "None", + "verb": [ + "Start-Job" + ], + "args": [ + { + "raw": "-ScriptBlock", + "kind": "Literal", + "isPath": false + }, + { + "raw": "{ Write-Output main }", + "kind": "DynamicSkip", + "isPath": false + }, + { + "raw": "-InitializationScript", + "kind": "Literal", + "isPath": false + }, + { + "raw": "{ Write-Output init }", + "kind": "DynamicSkip", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Start-Job", + "value": "Start-Job", + "role": "Verb", + "sourceStart": 0, + "sourceLength": 9, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "-ScriptBlock", + "value": "-ScriptBlock", + "role": "Argument", + "sourceStart": 10, + "sourceLength": 12, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": true, + "isPath": false + }, + { + "raw": "{ Write-Output main }", + "value": "{ Write-Output main }", + "role": "Argument", + "sourceStart": 23, + "sourceLength": 21, + "precedingVerbElementCount": 1, + "kind": "DynamicSkip", + "isFlag": false, + "isPath": false + }, + { + "raw": "-InitializationScript", + "value": "-InitializationScript", + "role": "Argument", + "sourceStart": 45, + "sourceLength": 21, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": true, + "isPath": false + }, + { + "raw": "{ Write-Output init }", + "value": "{ Write-Output init }", + "role": "Argument", + "sourceStart": 67, + "sourceLength": 21, + "precedingVerbElementCount": 1, + "kind": "DynamicSkip", + "isFlag": false, + "isPath": false + } + ] + }, + { + "operator": "None", + "verb": [ + "Write-Output" + ], + "args": [ + { + "raw": "main", + "kind": "Literal", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Write-Output", + "value": "Write-Output", + "role": "Verb", + "sourceStart": 25, + "sourceLength": 12, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "main", + "value": "main", + "role": "Argument", + "sourceStart": 38, + "sourceLength": 4, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": false, + "isPath": false + } + ] + }, + { + "operator": "None", + "verb": [ + "Write-Output" + ], + "args": [ + { + "raw": "init", + "kind": "Literal", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Write-Output", + "value": "Write-Output", + "role": "Verb", + "sourceStart": 69, + "sourceLength": 12, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "init", + "value": "init", + "role": "Argument", + "sourceStart": 82, + "sourceLength": 4, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": false, + "isPath": false + } + ] + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 88, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 88, + "clauseIndex": 0, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ExecutionRegion", + "parentIndex": 1, + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 23, + "sourceLength": 21, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "executionOrigin": "CommandArgument", + "hostClauseElementIndex": 2, + "executionPhase": "Main", + "executionTiming": "Concurrent", + "executionCardinality": "Once" + }, + { + "kind": "Block", + "parentIndex": 2, + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 24, + "sourceLength": 19, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 3, + "region": "Statement", + "childIndex": 0, + "sourceStart": 25, + "sourceLength": 17, + "clauseIndex": 1, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ExecutionRegion", + "parentIndex": 1, + "region": "ExecutionRegion", + "childIndex": 1, + "sourceStart": 67, + "sourceLength": 21, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "executionOrigin": "CommandArgument", + "hostClauseElementIndex": 4, + "executionPhase": "Initialization", + "executionTiming": "Concurrent", + "executionCardinality": "Once" + }, + { + "kind": "Block", + "parentIndex": 5, + "region": "ExecutionRegion", + "childIndex": 1, + "sourceStart": 68, + "sourceLength": 19, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 6, + "region": "Statement", + "childIndex": 0, + "sourceStart": 69, + "sourceLength": 17, + "clauseIndex": 2, + "groupKind": null, + "listOperator": null + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "Ordinary", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 88 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 1, + "immediateRole": "ExecutionRegion", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 88 + }, + { + "ancestorKind": "ExecutionRegion", + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 23, + "sourceLength": 21 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 24, + "sourceLength": 19 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 2, + "immediateRole": "ExecutionRegion", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 88 + }, + { + "ancestorKind": "ExecutionRegion", + "region": "ExecutionRegion", + "childIndex": 1, + "sourceStart": 67, + "sourceLength": 21 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 68, + "sourceLength": 19 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Promotes stable design case pwsh-start-job-initialization-and-main." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/532_v03_design_new_module_initialization_region.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/532_v03_design_new_module_initialization_region.json new file mode 100644 index 0000000..4f88bfd --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/532_v03_design_new_module_initialization_region.json @@ -0,0 +1,227 @@ +{ + "name": "V03 design new module initialization region", + "input": "New-Module -ScriptBlock { Write-Output initialized }", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "None", + "verb": [ + "New-Module" + ], + "args": [ + { + "raw": "-ScriptBlock", + "kind": "Literal", + "isPath": false + }, + { + "raw": "{ Write-Output initialized }", + "kind": "DynamicSkip", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "New-Module", + "value": "New-Module", + "role": "Verb", + "sourceStart": 0, + "sourceLength": 10, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "-ScriptBlock", + "value": "-ScriptBlock", + "role": "Argument", + "sourceStart": 11, + "sourceLength": 12, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": true, + "isPath": false + }, + { + "raw": "{ Write-Output initialized }", + "value": "{ Write-Output initialized }", + "role": "Argument", + "sourceStart": 24, + "sourceLength": 28, + "precedingVerbElementCount": 1, + "kind": "DynamicSkip", + "isFlag": false, + "isPath": false + } + ] + }, + { + "operator": "None", + "verb": [ + "Write-Output" + ], + "args": [ + { + "raw": "initialized", + "kind": "Literal", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Write-Output", + "value": "Write-Output", + "role": "Verb", + "sourceStart": 26, + "sourceLength": 12, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "initialized", + "value": "initialized", + "role": "Argument", + "sourceStart": 39, + "sourceLength": 11, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": false, + "isPath": false + } + ] + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 52, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 52, + "clauseIndex": 0, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ExecutionRegion", + "parentIndex": 1, + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 24, + "sourceLength": 28, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "executionOrigin": "CommandArgument", + "hostClauseElementIndex": 2, + "executionPhase": "Initialization", + "executionTiming": "Synchronous", + "executionCardinality": "Once" + }, + { + "kind": "Block", + "parentIndex": 2, + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 25, + "sourceLength": 26, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 3, + "region": "Statement", + "childIndex": 0, + "sourceStart": 26, + "sourceLength": 24, + "clauseIndex": 1, + "groupKind": null, + "listOperator": null + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "Ordinary", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 52 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 1, + "immediateRole": "ExecutionRegion", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 52 + }, + { + "ancestorKind": "ExecutionRegion", + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 24, + "sourceLength": 28 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 25, + "sourceLength": 26 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Promotes stable design case pwsh-new-module-initialization-region." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/533_v03_design_direct_call_trailing_arguments_fail_closed.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/533_v03_design_direct_call_trailing_arguments_fail_closed.json new file mode 100644 index 0000000..0ad9e65 --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/533_v03_design_direct_call_trailing_arguments_fail_closed.json @@ -0,0 +1,11 @@ +{ + "name": "V03 design direct call trailing arguments fail closed", + "input": "\u0026 { Write-Output $args } alpha", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": true, + "unparseableReasonContains": "direct PowerShell script-block arguments are not supported" + }, + "notes": "Promotes stable fail-closed design case pwsh-direct-call-trailing-arguments-fail-closed.", + "oracleExpectation": "OutOfScope" +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/534_v03_design_dot_source_trailing_arguments_fail_closed.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/534_v03_design_dot_source_trailing_arguments_fail_closed.json new file mode 100644 index 0000000..ff9ba60 --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/534_v03_design_dot_source_trailing_arguments_fail_closed.json @@ -0,0 +1,11 @@ +{ + "name": "V03 design dot source trailing arguments fail closed", + "input": ". { Write-Output $args } alpha", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": true, + "unparseableReasonContains": "direct PowerShell script-block arguments are not supported" + }, + "notes": "Promotes stable fail-closed design case pwsh-dot-source-trailing-arguments-fail-closed.", + "oracleExpectation": "OutOfScope" +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/535_v03_design_execution_region_param_header_fail_closed.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/535_v03_design_execution_region_param_header_fail_closed.json new file mode 100644 index 0000000..7f8f245 --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/535_v03_design_execution_region_param_header_fail_closed.json @@ -0,0 +1,11 @@ +{ + "name": "V03 design execution region param header fail closed", + "input": "Register-ArgumentCompleter -CommandName tool -ScriptBlock { param($commandName) Write-Output $commandName }", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": true, + "unparseableReasonContains": "control-flow / definition keyword \u0027param\u0027 is not supported in v0.2" + }, + "notes": "Promotes stable fail-closed design case pwsh-execution-region-param-header-fail-closed.", + "oracleExpectation": "OutOfScope" +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/536_v03_execution_region_measure_command.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/536_v03_execution_region_measure_command.json new file mode 100644 index 0000000..9d19e18 --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/536_v03_execution_region_measure_command.json @@ -0,0 +1,213 @@ +{ + "name": "V03 execution region measure command", + "input": "Measure-Command { Get-Item child.txt }", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "None", + "verb": [ + "Measure-Command" + ], + "args": [ + { + "raw": "{ Get-Item child.txt }", + "kind": "DynamicSkip", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Measure-Command", + "value": "Measure-Command", + "role": "Verb", + "sourceStart": 0, + "sourceLength": 15, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "{ Get-Item child.txt }", + "value": "{ Get-Item child.txt }", + "role": "Argument", + "sourceStart": 16, + "sourceLength": 22, + "precedingVerbElementCount": 1, + "kind": "DynamicSkip", + "isFlag": false, + "isPath": false + } + ] + }, + { + "operator": "None", + "verb": [ + "Get-Item" + ], + "args": [ + { + "raw": "child.txt", + "kind": "Literal", + "isPath": true, + "resolved": "C:/work/child.txt" + } + ], + "redirects": [], + "elements": [ + { + "raw": "Get-Item", + "value": "Get-Item", + "role": "Verb", + "sourceStart": 18, + "sourceLength": 8, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "child.txt", + "value": "child.txt", + "role": "Argument", + "sourceStart": 27, + "sourceLength": 9, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": false, + "isPath": true, + "resolved": "C:/work/child.txt" + } + ] + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 38, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 38, + "clauseIndex": 0, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ExecutionRegion", + "parentIndex": 1, + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 16, + "sourceLength": 22, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "executionOrigin": "CommandArgument", + "hostClauseElementIndex": 1, + "executionPhase": "Main", + "executionTiming": "Synchronous", + "executionCardinality": "Once" + }, + { + "kind": "Block", + "parentIndex": 2, + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 17, + "sourceLength": 20, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 3, + "region": "Statement", + "childIndex": 0, + "sourceStart": 18, + "sourceLength": 18, + "clauseIndex": 1, + "groupKind": null, + "listOperator": null + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "Ordinary", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 38 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 1, + "immediateRole": "ExecutionRegion", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 38 + }, + { + "ancestorKind": "ExecutionRegion", + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 16, + "sourceLength": 22 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 17, + "sourceLength": 20 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Pins exact-once ownership for the stable Measure-Command execution-region catalog entry." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/537_v03_execution_region_trace_command.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/537_v03_execution_region_trace_command.json new file mode 100644 index 0000000..7ae4df9 --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/537_v03_execution_region_trace_command.json @@ -0,0 +1,277 @@ +{ + "name": "V03 execution region trace command", + "input": "Trace-Command -Name ParameterBinding -Expression { Get-Item child.txt } -PSHost", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "None", + "verb": [ + "Trace-Command" + ], + "args": [ + { + "raw": "-Name", + "kind": "Literal", + "isPath": false + }, + { + "raw": "ParameterBinding", + "kind": "Literal", + "isPath": false + }, + { + "raw": "-Expression", + "kind": "Literal", + "isPath": false + }, + { + "raw": "{ Get-Item child.txt }", + "kind": "DynamicSkip", + "isPath": false + }, + { + "raw": "-PSHost", + "kind": "Literal", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Trace-Command", + "value": "Trace-Command", + "role": "Verb", + "sourceStart": 0, + "sourceLength": 13, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "-Name", + "value": "-Name", + "role": "Argument", + "sourceStart": 14, + "sourceLength": 5, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": true, + "isPath": false + }, + { + "raw": "ParameterBinding", + "value": "ParameterBinding", + "role": "Argument", + "sourceStart": 20, + "sourceLength": 16, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "-Expression", + "value": "-Expression", + "role": "Argument", + "sourceStart": 37, + "sourceLength": 11, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": true, + "isPath": false + }, + { + "raw": "{ Get-Item child.txt }", + "value": "{ Get-Item child.txt }", + "role": "Argument", + "sourceStart": 49, + "sourceLength": 22, + "precedingVerbElementCount": 1, + "kind": "DynamicSkip", + "isFlag": false, + "isPath": false + }, + { + "raw": "-PSHost", + "value": "-PSHost", + "role": "Argument", + "sourceStart": 72, + "sourceLength": 7, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": true, + "isPath": false + } + ] + }, + { + "operator": "None", + "verb": [ + "Get-Item" + ], + "args": [ + { + "raw": "child.txt", + "kind": "Literal", + "isPath": true, + "resolved": "C:/work/child.txt" + } + ], + "redirects": [], + "elements": [ + { + "raw": "Get-Item", + "value": "Get-Item", + "role": "Verb", + "sourceStart": 51, + "sourceLength": 8, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "child.txt", + "value": "child.txt", + "role": "Argument", + "sourceStart": 60, + "sourceLength": 9, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": false, + "isPath": true, + "resolved": "C:/work/child.txt" + } + ] + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 79, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 79, + "clauseIndex": 0, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ExecutionRegion", + "parentIndex": 1, + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 49, + "sourceLength": 22, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "executionOrigin": "CommandArgument", + "hostClauseElementIndex": 4, + "executionPhase": "Main", + "executionTiming": "Synchronous", + "executionCardinality": "Once" + }, + { + "kind": "Block", + "parentIndex": 2, + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 50, + "sourceLength": 20, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 3, + "region": "Statement", + "childIndex": 0, + "sourceStart": 51, + "sourceLength": 18, + "clauseIndex": 1, + "groupKind": null, + "listOperator": null + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "Ordinary", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 79 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 1, + "immediateRole": "ExecutionRegion", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 79 + }, + { + "ancestorKind": "ExecutionRegion", + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 49, + "sourceLength": 22 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 50, + "sourceLength": 20 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Pins exact-once ownership for the stable Trace-Command execution-region catalog entry." +} diff --git a/tests/ShellSyntaxTree.Tests/Corpus/powershell/538_v03_execution_region_foreach_object_remaining_scripts.json b/tests/ShellSyntaxTree.Tests/Corpus/powershell/538_v03_execution_region_foreach_object_remaining_scripts.json new file mode 100644 index 0000000..81bbda1 --- /dev/null +++ b/tests/ShellSyntaxTree.Tests/Corpus/powershell/538_v03_execution_region_foreach_object_remaining_scripts.json @@ -0,0 +1,501 @@ +{ + "name": "V03 execution region foreach object remaining scripts", + "input": "ForEach-Object -RemainingScripts { Write-Output first }, { Write-Output second } -Process { Write-Output third }", + "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", + "expected": { + "isUnparseable": false, + "clauses": [ + { + "operator": "None", + "verb": [ + "ForEach-Object" + ], + "args": [ + { + "raw": "-RemainingScripts", + "kind": "Literal", + "isPath": false + }, + { + "raw": "{ Write-Output first },", + "kind": "DynamicSkip", + "isPath": false + }, + { + "raw": "{ Write-Output second }", + "kind": "DynamicSkip", + "isPath": false + }, + { + "raw": "-Process", + "kind": "Literal", + "isPath": false + }, + { + "raw": "{ Write-Output third }", + "kind": "DynamicSkip", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "ForEach-Object", + "value": "ForEach-Object", + "role": "Verb", + "sourceStart": 0, + "sourceLength": 14, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "-RemainingScripts", + "value": "-RemainingScripts", + "role": "Argument", + "sourceStart": 15, + "sourceLength": 17, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": true, + "isPath": false + }, + { + "raw": "{ Write-Output first },", + "value": "{ Write-Output first },", + "role": "Argument", + "sourceStart": 33, + "sourceLength": 23, + "precedingVerbElementCount": 1, + "kind": "DynamicSkip", + "isFlag": false, + "isPath": false + }, + { + "raw": "{ Write-Output second }", + "value": "{ Write-Output second }", + "role": "Argument", + "sourceStart": 57, + "sourceLength": 23, + "precedingVerbElementCount": 1, + "kind": "DynamicSkip", + "isFlag": false, + "isPath": false + }, + { + "raw": "-Process", + "value": "-Process", + "role": "Argument", + "sourceStart": 81, + "sourceLength": 8, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": true, + "isPath": false + }, + { + "raw": "{ Write-Output third }", + "value": "{ Write-Output third }", + "role": "Argument", + "sourceStart": 90, + "sourceLength": 22, + "precedingVerbElementCount": 1, + "kind": "DynamicSkip", + "isFlag": false, + "isPath": false + } + ] + }, + { + "operator": "None", + "verb": [ + "Write-Output" + ], + "args": [ + { + "raw": "first", + "kind": "Literal", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Write-Output", + "value": "Write-Output", + "role": "Verb", + "sourceStart": 35, + "sourceLength": 12, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "first", + "value": "first", + "role": "Argument", + "sourceStart": 48, + "sourceLength": 5, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": false, + "isPath": false + } + ] + }, + { + "operator": "None", + "verb": [ + "Write-Output" + ], + "args": [ + { + "raw": "second", + "kind": "Literal", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Write-Output", + "value": "Write-Output", + "role": "Verb", + "sourceStart": 59, + "sourceLength": 12, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "second", + "value": "second", + "role": "Argument", + "sourceStart": 72, + "sourceLength": 6, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": false, + "isPath": false + } + ] + }, + { + "operator": "None", + "verb": [ + "Write-Output" + ], + "args": [ + { + "raw": "third", + "kind": "Literal", + "isPath": false + } + ], + "redirects": [], + "elements": [ + { + "raw": "Write-Output", + "value": "Write-Output", + "role": "Verb", + "sourceStart": 92, + "sourceLength": 12, + "precedingVerbElementCount": 0, + "kind": "Literal", + "isFlag": false, + "isPath": false + }, + { + "raw": "third", + "value": "third", + "role": "Argument", + "sourceStart": 105, + "sourceLength": 5, + "precedingVerbElementCount": 1, + "kind": "Literal", + "isFlag": false, + "isPath": false + } + ] + } + ], + "syntax": [ + { + "kind": "Block", + "parentIndex": null, + "region": "Unknown", + "childIndex": null, + "sourceStart": 0, + "sourceLength": 112, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 0, + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 112, + "clauseIndex": 0, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ExecutionRegion", + "parentIndex": 1, + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 33, + "sourceLength": 22, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "executionOrigin": "CommandArgument", + "hostClauseElementIndex": 2, + "executionPhase": "Begin", + "executionTiming": "Synchronous", + "executionCardinality": "Once" + }, + { + "kind": "Block", + "parentIndex": 2, + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 34, + "sourceLength": 20, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 3, + "region": "Statement", + "childIndex": 0, + "sourceStart": 35, + "sourceLength": 18, + "clauseIndex": 1, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ExecutionRegion", + "parentIndex": 1, + "region": "ExecutionRegion", + "childIndex": 1, + "sourceStart": 57, + "sourceLength": 23, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "executionOrigin": "CommandArgument", + "hostClauseElementIndex": 3, + "executionPhase": "Process", + "executionTiming": "Synchronous", + "executionCardinality": "OncePerInputObject" + }, + { + "kind": "Block", + "parentIndex": 5, + "region": "ExecutionRegion", + "childIndex": 1, + "sourceStart": 58, + "sourceLength": 21, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 6, + "region": "Statement", + "childIndex": 0, + "sourceStart": 59, + "sourceLength": 19, + "clauseIndex": 2, + "groupKind": null, + "listOperator": null + }, + { + "kind": "ExecutionRegion", + "parentIndex": 1, + "region": "ExecutionRegion", + "childIndex": 2, + "sourceStart": 90, + "sourceLength": 22, + "clauseIndex": null, + "groupKind": null, + "listOperator": null, + "executionOrigin": "CommandArgument", + "hostClauseElementIndex": 5, + "executionPhase": "End", + "executionTiming": "Synchronous", + "executionCardinality": "Once" + }, + { + "kind": "Block", + "parentIndex": 8, + "region": "ExecutionRegion", + "childIndex": 2, + "sourceStart": 91, + "sourceLength": 20, + "clauseIndex": null, + "groupKind": null, + "listOperator": null + }, + { + "kind": "SimpleCommand", + "parentIndex": 9, + "region": "Statement", + "childIndex": 0, + "sourceStart": 92, + "sourceLength": 18, + "clauseIndex": 3, + "groupKind": null, + "listOperator": null + } + ], + "commands": [ + { + "clauseIndex": 0, + "immediateRole": "Ordinary", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 112 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 1, + "immediateRole": "ExecutionRegion", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 112 + }, + { + "ancestorKind": "ExecutionRegion", + "region": "ExecutionRegion", + "childIndex": 0, + "sourceStart": 33, + "sourceLength": 22 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 34, + "sourceLength": 20 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 2, + "immediateRole": "ExecutionRegion", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 112 + }, + { + "ancestorKind": "ExecutionRegion", + "region": "ExecutionRegion", + "childIndex": 1, + "sourceStart": 57, + "sourceLength": 23 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 58, + "sourceLength": 21 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + }, + { + "clauseIndex": 3, + "immediateRole": "ExecutionRegion", + "isComplete": true, + "ancestry": [ + { + "ancestorKind": "Block", + "region": "Root", + "childIndex": 0, + "sourceStart": 0, + "sourceLength": 112 + }, + { + "ancestorKind": "ExecutionRegion", + "region": "ExecutionRegion", + "childIndex": 2, + "sourceStart": 90, + "sourceLength": 22 + }, + { + "ancestorKind": "Block", + "region": "Statement", + "childIndex": 0, + "sourceStart": 91, + "sourceLength": 20 + } + ], + "effectiveArguments": [], + "workingDirectory": { + "kind": "Exact", + "values": [ + "C:/work" + ], + "pattern": null, + "coveringDirectory": null + } + } + ] + }, + "notes": "Pins authored ordering and exact-once ownership for the stable RemainingScripts binding." +} diff --git a/tests/ShellSyntaxTree.Tests/DesignCorpus/v0.3/powershell.json b/tests/ShellSyntaxTree.Tests/DesignCorpus/v0.3/powershell.json index 1731a14..21328b0 100644 --- a/tests/ShellSyntaxTree.Tests/DesignCorpus/v0.3/powershell.json +++ b/tests/ShellSyntaxTree.Tests/DesignCorpus/v0.3/powershell.json @@ -437,6 +437,7 @@ }, { "id": "pwsh-pipeline-foreach-alias", + "compatibilityProjectionLanded": true, "concern": "Contextual foreach alias is not a foreach statement", "input": "Get-ChildItem | foreach { Remove-Item $_ }", "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", @@ -1028,6 +1029,7 @@ }, { "id": "pwsh-static-stream-merge", + "compatibilityProjectionLanded": true, "concern": "Static PowerShell stream merge", "input": "Get-ChildItem 2>&1", "current": { "isUnparseable": false }, @@ -1053,6 +1055,7 @@ }, { "id": "pwsh-contextual-foreach-argument", + "compatibilityProjectionLanded": true, "concern": "Control keyword used as ordinary argument", "input": "Write-Output foreach", "current": { "isUnparseable": false }, @@ -1110,6 +1113,7 @@ }, { "id": "pwsh-literal-here-string-is-value", + "compatibilityProjectionLanded": true, "concern": "PowerShell here-string syntax remains an argument rather than a redirect", "input": "Write-Output @'\n$literal text\n'@", "current": { "isUnparseable": false }, @@ -1314,6 +1318,7 @@ }, { "id": "pwsh-double-quoted-literal-expandable-composition", + "compatibilityProjectionLanded": true, "concern": "Literal and expandable regions compose within one token", "input": "Write-Output \"`${HOME}-$HOME\"", "current": { "isUnparseable": false }, @@ -2235,6 +2240,7 @@ }, { "id": "pwsh-where-object-filter-region", + "compatibilityProjectionLanded": true, "concern": "Where-Object FilterScript executes once per pipeline input object", "input": "Get-ChildItem | Where-Object -FilterScript { Test-Path $_ }", "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", @@ -2260,6 +2266,7 @@ }, { "id": "pwsh-foreach-object-authored-versus-phase-order", + "compatibilityProjectionLanded": true, "concern": "ForEach-Object retains authored script-block order while exposing semantic phases", "input": "ForEach-Object -End { Write-Output end } -Begin { Write-Output begin } -Process { Write-Output process }", "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", @@ -2290,6 +2297,7 @@ }, { "id": "pwsh-invoke-command-local-region", + "compatibilityProjectionLanded": true, "concern": "Local Invoke-Command exposes a synchronous main execution region", "input": "Invoke-Command -ScriptBlock { Get-Item child.txt }", "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", @@ -2312,6 +2320,7 @@ }, { "id": "pwsh-invoke-command-remote-region", + "compatibilityProjectionLanded": true, "concern": "Remote Invoke-Command exposes its body while withholding unproved remote state", "input": "Invoke-Command -ComputerName server -ScriptBlock { Get-Item child.txt }", "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", @@ -2334,6 +2343,7 @@ }, { "id": "pwsh-start-job-initialization-and-main", + "compatibilityProjectionLanded": true, "concern": "Start-Job exposes authored main and initialization blocks while analysis schedules initialization first", "input": "Start-Job -ScriptBlock { Write-Output main } -InitializationScript { Write-Output init }", "current": { "isUnparseable": false }, @@ -2359,6 +2369,7 @@ }, { "id": "pwsh-foreach-object-parallel-region", + "compatibilityProjectionLanded": true, "concern": "ForEach-Object Parallel exposes a concurrent child-runspace process region", "input": "Get-ChildItem | ForEach-Object -Parallel { Remove-Item $_ }", "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", @@ -2428,6 +2439,7 @@ }, { "id": "pwsh-new-module-initialization-region", + "compatibilityProjectionLanded": true, "concern": "New-Module script block is immediate module initialization rather than opaque data", "input": "New-Module -ScriptBlock { Write-Output initialized }", "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", @@ -2468,6 +2480,7 @@ }, { "id": "pwsh-direct-call-trailing-arguments-fail-closed", + "compatibilityProjectionLanded": true, "concern": "Direct call-operator block arguments remain atomic until parameter binding is modeled", "input": "& { Write-Output $args } alpha", "current": { "isUnparseable": true }, @@ -2484,6 +2497,7 @@ }, { "id": "pwsh-dot-source-trailing-arguments-fail-closed", + "compatibilityProjectionLanded": true, "concern": "Dot-source block arguments remain atomic until parameter binding is modeled", "input": ". { Write-Output $args } alpha", "current": { "isUnparseable": true }, @@ -2500,6 +2514,7 @@ }, { "id": "pwsh-execution-region-param-header-fail-closed", + "compatibilityProjectionLanded": true, "concern": "A leading param declaration keeps the complete argument-completer region atomic until declaration grammar lands", "input": "Register-ArgumentCompleter -CommandName tool -ScriptBlock { param($commandName) Write-Output $commandName }", "powerShellInitialStateMode": "IsolatedNonInteractiveNoProfile", diff --git a/tools/PwshCorpusTool/CorpusJson.cs b/tools/PwshCorpusTool/CorpusJson.cs index a9a1665..832aa95 100644 --- a/tools/PwshCorpusTool/CorpusJson.cs +++ b/tools/PwshCorpusTool/CorpusJson.cs @@ -368,7 +368,9 @@ private static void AppendSyntax( executionRegion.Body, currentIndex, CommandAncestryRegion.ExecutionRegion, - childIndex: 0, + // The body ancestry keeps the owning region's authored + // sibling coordinate so multiple host regions stay distinct. + childIndex, listOperator: null, parsed, nodes, diff --git a/tools/PwshCorpusTool/CorpusManifest.cs b/tools/PwshCorpusTool/CorpusManifest.cs index eae37f2..89468b3 100644 --- a/tools/PwshCorpusTool/CorpusManifest.cs +++ b/tools/PwshCorpusTool/CorpusManifest.cs @@ -1421,5 +1421,108 @@ private static string NestIex(string inner, int depth) W("v03_windows_powershell_convert_from_string_alias", "CFS", "Windows PowerShell 5.1 defines CFS as the ConvertFrom-String alias."), + VIE("v03_design_simple_command_substitution", + "Remove-Item $(Get-Item target.txt)", + "Promotes stable design case pwsh-simple-command-substitution."), + VIE("v03_design_literal_substitution_spellings", + "Write-Output '$(Get-Date)' \"literal `$(Get-Location)\"", + "Promotes stable design case pwsh-literal-substitution-spellings."), + VIE("v03_design_call_operator_script_block_region", + "& { Remove-Item target.txt }", + "Promotes stable design case pwsh-call-operator-script-block-region."), + VIE("v03_design_call_operator_subexpression_invocation", + "& $(Write-Output Get-Date)", + "Promotes stable design case pwsh-call-operator-subexpression-invocation."), + VIE("v03_design_command_substitution_current_scope_cwd", + "Write-Output $(Set-Location /tmp && Get-Location); Get-Item relative.txt", + "Promotes stable design case pwsh-command-substitution-current-scope-cwd."), + VIE("v03_design_foreach_subexpression_iterator", + "foreach ($f in $(Get-ChildItem C:\\input)) { Remove-Item -LiteralPath $f }", + "Promotes stable design case pwsh-foreach-subexpression-iterator."), + VIE("v03_design_foreach_cmdlet_parameter_like_value", + "foreach ($f in @('-Force', 'a.txt')) { Remove-Item $f }", + "Promotes stable design case pwsh-foreach-cmdlet-parameter-like-value."), + VIE("v03_design_foreach_native_option_like_value", + "foreach ($f in @('-n', 'file.txt')) { tool $f }", + "Promotes stable design case pwsh-foreach-native-option-like-value."), + VIE("v03_design_nested_foreach", + "foreach ($d in @('a', 'b')) { foreach ($f in @('x', 'y')) { Write-Output \"$d/$f\" } }", + "Promotes stable design case pwsh-nested-foreach."), + E("v03_design_malformed_foreach_missing_body", + "foreach ($f in 1, 2) Remove-Item $f", + "Promotes stable design case pwsh-malformed-foreach-missing-body."), + VIE("v03_design_foreach_candidate_cap_32", + "foreach ($f in @('v01','v02','v03','v04','v05','v06','v07','v08','v09','v10','v11','v12','v13','v14','v15','v16','v17','v18','v19','v20','v21','v22','v23','v24','v25','v26','v27','v28','v29','v30','v31','v32')) { Write-Output $f }", + "Promotes stable design case pwsh-foreach-candidate-cap-32."), + VIE("v03_design_variable_writer_invalidates_proved_binding", + "foreach ($f in 'safe.txt') { }; Write-Output C:/sensitive.txt -OutVariable f; Remove-Item $f", + "Promotes stable design case pwsh-variable-writer-invalidates-proved-binding."), + OosI("v03_design_alternate_parameter_dash_gated", + "foreach ($f in 'safe.txt') { }; Write-Output C:/sensitive.txt –OutVariable f; Remove-Item $f", + "Promotes stable fail-closed design case pwsh-alternate-parameter-dash-gated."), + OosI("v03_design_structured_module_qualified_mutation_gated", + "foreach ($f in 'safe.txt') { }; Write-Output C:/sensitive.txt | Microsoft.PowerShell.Utility\\Tee-Object -Variable f; Remove-Item $f", + "Promotes stable fail-closed design case pwsh-structured-module-qualified-mutation-gated."), + VIE("v03_design_dynamic_invoke_expression_invalidates_current_state", + "foreach ($f in 'safe.txt') { }; Invoke-Expression $code; git $f", + "Promotes stable design case pwsh-dynamic-invoke-expression-invalidates-current-state."), + VIE("v03_design_foreach_binding_is_case_insensitive", + "foreach ($f in @('a')) { Write-Output $F }", + "Promotes stable design case pwsh-foreach-binding-is-case-insensitive."), + VIE("v03_design_nested_same_name_foreach_overwrites_binding", + "foreach ($f in @('outer')) { foreach ($f in @('inner')) { Write-Output $f }; Write-Output $f }; Write-Output $f", + "Promotes stable design case pwsh-nested-same-name-foreach-overwrites-binding."), + VIE("v03_design_foreach_binding_used_as_redirect_target", + "foreach ($f in @('a.log','b.log')) { Write-Output payload > $f }", + "Promotes stable design case pwsh-foreach-binding-used-as-redirect-target."), + VIE("v03_design_foreach_current_runspace_invoke_expression", + "foreach ($f in @('a','b')) { Invoke-Expression 'Write-Output $f' }", + "Promotes stable design case pwsh-foreach-current-runspace-invoke-expression."), + VIE("v03_design_foreach_child_host_does_not_inherit_state_mode", + "pwsh -NoProfile -NonInteractive -Command 'foreach ($f in @(\"a\")) { Write-Output $f }'", + "Promotes stable design case pwsh-foreach-child-host-does-not-inherit-state-mode."), + VIE("v03_design_dot_source_script_block_region", + ". { Get-Location }", + "Promotes stable design case pwsh-dot-source-script-block-region."), + VIE("v03_design_pipeline_foreach_alias", + "Get-ChildItem | foreach { Remove-Item $_ }", + "Promotes stable design case pwsh-pipeline-foreach-alias."), + VIE("v03_design_where_object_filter_region", + "Get-ChildItem | Where-Object -FilterScript { Test-Path $_ }", + "Promotes stable design case pwsh-where-object-filter-region."), + VIE("v03_design_foreach_object_authored_versus_phase_order", + "ForEach-Object -End { Write-Output end } -Begin { Write-Output begin } -Process { Write-Output process }", + "Promotes stable design case pwsh-foreach-object-authored-versus-phase-order."), + VIE("v03_design_invoke_command_local_region", + "Invoke-Command -ScriptBlock { Get-Item child.txt }", + "Promotes stable design case pwsh-invoke-command-local-region."), + VIE("v03_design_invoke_command_remote_region", + "Invoke-Command -ComputerName server -ScriptBlock { Get-Item child.txt }", + "Promotes stable design case pwsh-invoke-command-remote-region."), + VIE("v03_design_start_job_initialization_and_main", + "Start-Job -ScriptBlock { Write-Output main } -InitializationScript { Write-Output init }", + "Promotes stable design case pwsh-start-job-initialization-and-main."), + VIE("v03_design_new_module_initialization_region", + "New-Module -ScriptBlock { Write-Output initialized }", + "Promotes stable design case pwsh-new-module-initialization-region."), + OosI("v03_design_direct_call_trailing_arguments_fail_closed", + "& { Write-Output $args } alpha", + "Promotes stable fail-closed design case pwsh-direct-call-trailing-arguments-fail-closed."), + OosI("v03_design_dot_source_trailing_arguments_fail_closed", + ". { Write-Output $args } alpha", + "Promotes stable fail-closed design case pwsh-dot-source-trailing-arguments-fail-closed."), + OosI("v03_design_execution_region_param_header_fail_closed", + "Register-ArgumentCompleter -CommandName tool -ScriptBlock { param($commandName) Write-Output $commandName }", + "Promotes stable fail-closed design case pwsh-execution-region-param-header-fail-closed."), + VIE("v03_execution_region_measure_command", + "Measure-Command { Get-Item child.txt }", + "Pins exact-once ownership for the stable Measure-Command execution-region catalog entry."), + VIE("v03_execution_region_trace_command", + "Trace-Command -Name ParameterBinding -Expression { Get-Item child.txt } -PSHost", + "Pins exact-once ownership for the stable Trace-Command execution-region catalog entry."), + VIE("v03_execution_region_foreach_object_remaining_scripts", + "ForEach-Object -RemainingScripts { Write-Output first }, " + + "{ Write-Output second } -Process { Write-Output third }", + "Pins authored ordering and exact-once ownership for the stable RemainingScripts binding."), }; }