From 243142693fd674c8fa4d877a261bd5db57c7ffd6 Mon Sep 17 00:00:00 2001 From: JumpingYang001 Date: Mon, 18 Jul 2016 02:16:19 -0700 Subject: [PATCH] Add remain part of Parser Pester Unit Test --- test/powershell/enginecore/Parser.Test.ps1 | 91 ++++++++++++++++++++-- 1 file changed, 83 insertions(+), 8 deletions(-) diff --git a/test/powershell/enginecore/Parser.Test.ps1 b/test/powershell/enginecore/Parser.Test.ps1 index d216989a6..df22e5f14 100644 --- a/test/powershell/enginecore/Parser.Test.ps1 +++ b/test/powershell/enginecore/Parser.Test.ps1 @@ -102,6 +102,7 @@ Describe "ParserTests (admin\monad\tests\monad\src\engine\core\ParserTests.cs)" } AfterEach { $PowerShell.Commands.Clear() + $PowerShell.Streams.Error.Clear() if(Test-Path $testfile) { Remove-Item $testfile @@ -731,14 +732,88 @@ Describe "ParserTests (admin\monad\tests\monad\src\engine\core\ParserTests.cs)" $result | Should be "1" } - It "Newlines are allowed after operators (line 3033)" { - $result = ExecuteCommand "(20 % - 6 * - 4 + - 2) / - 2 - - 3" - $result | should be 2 + It 'Tests accessing using null as index. (line 2648)'{ + ExecuteCommand '$A=$(testcmd-parserBVT -returntype array); $A[$NONEXISTING_VARIABLE];' + $PowerShell.HadErrors | should be $true + $PowerShell.Streams.Error.FullyQualifiedErrorId | should be "NullArrayIndex" + } + + It 'Tests the parser response to ArrayName[. (line 2678)'{ + try { + ExecuteCommand '$A=$(testcmd-parserBVT -returntype array); $A[ ;' + throw "Execution OK" + } + catch { + $_.FullyQualifiedErrorId | Should be "ParseException" + } + } + + It 'Tests the parser response to ArrayName[]. (line 2687)'{ + try { + ExecuteCommand '$A=$(testcmd-parserBVT -returntype array); $A[] ;' + throw "Execution OK" + } + catch { + $_.FullyQualifiedErrorId | Should be "ParseException" + } + } + + #Issue#1430 + It "Tests function scopes in a script. (line 2800)" -Pending{ + " function global:func { 'global' }; " + + " function func { 'default' }; " + + " local:func; " + + " script:func; " + + " global:func; ">$testfile + $result = ExecuteCommand "function func { 'notcalled' };. $testfile" + $result -join "" | should be ("default", "default", "global" -join "") + $result = ExecuteCommand "func" + $result | should be "global" + } + + It 'Test piping arguments to a script block. The objects should be accesible from "$input". (line 2870)'{ + ExecuteCommand '$script = { $input; };$results = @(0,0),-1 | &$script' + $result = ExecuteCommand '$results[0][0]' + $result | Should be "0" + $result = ExecuteCommand '$results[0][1]' + $result | Should be "0" + $result = ExecuteCommand '$results[1]' + $result | Should be "-1" + } + + It 'Test piping null into a scriptblock. The script block should not be passed anything. (line 2903)'{ + $result = ExecuteCommand '$() | &{ $count = 0; foreach ($i in $input) { $count++ }; $count }' + $result | Should be "1" + $result = ExecuteCommand '$() | &{ $input }' + $result | Should BeNullOrEmpty + } + + It 'Test that types in System.dll are found automatically. (line 2951)'{ + $result = ExecuteCommand '[ System.IO.FileInfo]' + $result | Should be "System.IO.FileInfo" + } + + Context "Mathematical Operations Tests (starting at line 2975 to line 3036)" { + $testData = @( + @{ Script = '$a=6; $a -= 2;$a'; Expected = 4 } + @{ Script = "20 % + 6"; Expected = "2" } + @{ Script = "(20 % + 6 * + 4 + + 2 ) / + 2 - + 3"; Expected = "2" } + ) + It "