Download PowerShell-master/test/powershell/Language/Parser/Ast.Tests.ps1 from MegaBites-AI/Windows-powershell: direct link, hf CLI and curl.
- Browser
- Download file 1.23 kB
-
https://huggingface.co/datasets/MegaBites-AI/Windows-powershell/resolve/main/PowerShell-master/test/powershell/Language/Parser/Ast.Tests.ps1
- Command line
-
hf download hf://datasets/MegaBites-AI/Windows-powershell/PowerShell-master/test/powershell/Language/Parser/Ast.Tests.ps1
-
curl -L -o Ast.Tests.ps1 https://huggingface.co/datasets/MegaBites-AI/Windows-powershell/resolve/main/PowerShell-master/test/powershell/Language/Parser/Ast.Tests.ps1
1.23 kB
| # Copyright (c) Microsoft Corporation. | |
| # Licensed under the MIT License. | |
| using Namespace System.Management.Automation.Language | |
| Describe "The SafeGetValue method on AST returns safe values" -Tags "CI" { | |
| It "A hashtable is returned from a HashtableAst" { | |
| $HashtableAstType = [HashtableAst] | |
| $HtAst = { | |
| @{ one = 1 } | |
| }.ast.Find({$args[0] -is $HashtableAstType}, $true) | |
| $HtAst | Should -Not -BeNullOrEmpty | |
| $HtAst.SafeGetValue() | Should -BeOfType Hashtable | |
| } | |
| It "An Array is returned from a LiteralArrayAst" { | |
| $ArrayAstType = [ArrayLiteralAst] | |
| $ArrayAst = { | |
| @( 1,2,3,4) | |
| }.ast.Find({$args[0] -is $ArrayAstType}, $true) | |
| $ArrayAst | Should -Not -BeNullOrEmpty | |
| ,$ArrayAst.SafeGetValue() | Should -BeOfType Object[] | |
| } | |
| It "The proper error is returned when a variable is referenced" { | |
| $ast = { $a }.Ast.Find({$args[0] -is "VariableExpressionAst"},$true) | |
| { $ast.SafeGetValue() } | Should -Throw -ErrorId "InvalidOperationException" | |
| } | |
| It "A ScriptBlock AST fails with the proper error" { | |
| { { 1 }.Ast.SafeGetValue() } | Should -Throw -ErrorId "InvalidOperationException" | |
| } | |
| } | |