@@ -142,6 +142,8 @@ def test_keyword(self):
142
142
"in" , "param" , "process" , "return" ,
143
143
"switch" , "throw" , "trap" , "try" ,
144
144
"until" , "using" , "var" , "while" )
145
+ literals = chain (literals ,
146
+ [literal .swapcase () for literal in literals ])
145
147
self ._test_expected (Keyword , literals )
146
148
147
149
def test_expandable_string_part (self ):
@@ -547,7 +549,8 @@ def test_single_line_comment(self):
547
549
self ._parse (SingleLineComment , "t#rrop" )
548
550
549
551
def test_numeric_multiplier (self ):
550
- multipliers = ["kb" , "mb" , "gb" , "tb" , "pb" ]
552
+ multipliers = ["kb" , "mb" , "gb" , "tb" , "pb" ,
553
+ "Kb" , "MB" , "gB" , "TB" , "Pb" ]
551
554
self ._test_expected (NumericMultiplier , multipliers )
552
555
553
556
with self .assertRaises (ParseError ):
@@ -689,6 +692,8 @@ def test_comparison_operator(self):
689
692
"split"
690
693
]
691
694
literals = ["-{}" .format (op ) for op in ops ]
695
+ literals = chain (literals ,
696
+ [literal .swapcase () for literal in literals ])
692
697
self ._test_expected (ComparisonOperator , literals )
693
698
694
699
def test_operator_or_punctuator (self ):
@@ -699,10 +704,10 @@ def test_operator_or_punctuator(self):
699
704
"-" , "--" ,
700
705
"-and" , "-band" , "-bnot" ,
701
706
"-bor" , "-bxor" , "-not" ,
702
- "-or" , "-xor" ,
707
+ "-or" , "-xor" , "-AND" , "-BAND" , "-BNOT" ,
708
+ "-BOR" , "-Bxor" , "-nOt" ,
703
709
"+=" , "*=" ,
704
- ">>" ,
705
- "-inotlike" ,
710
+ ">>" , "-INOTliKe" , "-inotlike" ,
706
711
"-f"
707
712
]
708
713
self ._test_expected (OperatorOrPunctuator , literals )
@@ -722,9 +727,9 @@ def test_variable_namespace(self):
722
727
self ._parse (VariableNamespace , ":a" )
723
728
724
729
def test_variable_scope (self ):
725
- scopes = ["globe:" , "local:" , "private:" , "script:" ]
730
+ scopes = ["globe:" , "global:" , "local:" , "private:" , "script:" ,
731
+ "GLOBE:" , "GLOBAL:" , "Local:" , "Private:" , "SCRIPT:" ]
726
732
self ._test_expected (VariableScope , scopes )
727
-
728
733
self ._test_expected (VariableScope , ["abc:" ])
729
734
730
735
def test_braced_variable (self ):
@@ -1019,12 +1024,15 @@ def test_statement_terminators(self):
1019
1024
self ._test_expected (StatementTerminators , [";;" , "\n \n " ])
1020
1025
1021
1026
def test_block_name (self ):
1022
- names = ["dynamicparam" , "begin" , "process" , "end" ]
1027
+ names = ["dynamicparam" , "begin" , "process" , "end" ,
1028
+ "DynamicParam" , "BEGIN" , "PrOcEss" , "End" ]
1023
1029
self ._test_expected (BlockName , names )
1024
1030
1025
1031
def test_switch_parameters (self ):
1026
1032
params = ["-regex" , "-wildcard" , "-exact" , "-casesensitive" ]
1027
1033
self ._test_expected (SwitchParameter , params )
1034
+ self ._test_expected (SwitchParameter ,
1035
+ [param .upper () for param in params ])
1028
1036
1029
1037
params = [param + " " + param
1030
1038
for param in params ]
@@ -1048,20 +1056,25 @@ def test_flow_control_statement(self):
1048
1056
"break" ,
1049
1057
"break $lab" ,
1050
1058
"break labelA" ,
1059
+ "Break $lab" ,
1051
1060
1052
1061
"continue" ,
1053
1062
"continue $lab" ,
1054
1063
"continue labelA" ,
1064
+ "CONTINUE labelB" ,
1055
1065
1056
1066
"throw" ,
1057
1067
"throw 100" ,
1058
1068
'throw "No such record in file"' ,
1069
+ "Throw 42" ,
1059
1070
1060
1071
"return 1" ,
1061
1072
"return $4" ,
1073
+ "Return $52" ,
1062
1074
1063
1075
"exit" ,
1064
1076
"exit $4" ,
1077
+ "EXIT $42" ,
1065
1078
]
1066
1079
self ._test_expected (FlowControlStatement , parts )
1067
1080
@@ -1227,6 +1240,9 @@ def test_bitwise_expression(self):
1227
1240
"0x0F0F -bxor 0xFEL" ,
1228
1241
"0x0F0F -bxor 14.40D" ,
1229
1242
"0x0F0F -bxor 14.6" ,
1243
+ "0x0F0F -BXOR 14" ,
1244
+ "0x0F0F -BOR 24" ,
1245
+ "0x0F0F -BaND 23" ,
1230
1246
]
1231
1247
self ._test_expected (BitwiseExpression , parts )
1232
1248
@@ -1265,6 +1281,9 @@ def test_logical_expression(self):
1265
1281
"($j -eq 5) -and (++$k -gt 15)" ,
1266
1282
"($j++ -gt 5) -or (++$k -lt 15)" ,
1267
1283
"($j -eq 10) -or ($k -gt 15)" ,
1284
+ "($j -eq 10) -OR ($k -gt 15)" ,
1285
+ "($j -eq 10) -XoR ($k -gt 15)" ,
1286
+ "($j -eq 10) -AND ($k -gt 15)" ,
1268
1287
]
1269
1288
self ._test_expected (LogicalExpression , parts )
1270
1289
@@ -1431,6 +1450,8 @@ def test_if_statement(self):
1431
1450
else { "Grade F" }''' ),
1432
1451
dedent ('''if ($grade -ge 90) { "Grade A" }''' ),
1433
1452
dedent ('''if($grade -ge 90){"Grade A"}''' ),
1453
+ dedent ('''IF($grade -ge 90){"Grade A"}''' ),
1454
+ dedent ('''If($grade -ge 90){"Grade A"}''' ),
1434
1455
]
1435
1456
self ._test_expected (IfStatement , parts )
1436
1457
@@ -1439,6 +1460,8 @@ def test_else_clause(self):
1439
1460
'else { "grade f" }' ,
1440
1461
'else{"grafe f"\n }' ,
1441
1462
'else{"giraffe"}' ,
1463
+ 'ELSE{"giraffe"}' ,
1464
+ 'Else{"giraffe"}' ,
1442
1465
]
1443
1466
self ._test_expected (ElseClause , parts )
1444
1467
@@ -1447,6 +1470,8 @@ def test_else_if_clause(self):
1447
1470
'elseif ($grade -ge 80) { "Grade B" }' ,
1448
1471
'elseif($grade -ge 70){ "Grade C" }' ,
1449
1472
'elseif($grade -ge 60)\n {"Grade D"}' ,
1473
+ 'ELSEIF($grade -ge 60)\n {"Grade D"}' ,
1474
+ 'ElseIf($grade -ge 60)\n {"Grade D"}' ,
1450
1475
]
1451
1476
self ._test_expected (ElseIfClause , parts )
1452
1477
@@ -1470,6 +1495,8 @@ def test_for_statement(self):
1470
1495
'for ($i = 1;)\n { "$i" }' ,
1471
1496
'for ()\n { "$i" }' ,
1472
1497
'for (){ "$i" }' ,
1498
+ 'For (){ "$i" }' ,
1499
+ 'FOR (){ "$i" }' ,
1473
1500
]
1474
1501
self ._test_expected (ForStatement , parts )
1475
1502
@@ -1491,7 +1518,9 @@ def test_while_statement(self):
1491
1518
'while ($i++ -lt 2) { $i }' ,
1492
1519
'while ($i++ -lt 2)\n { $i }' ,
1493
1520
'while (\n $i++ -lt 2\n ) { $i }' ,
1494
- 'while (1) { $i }'
1521
+ 'while (1) { $i }' ,
1522
+ 'WHILE (1) { $i }' ,
1523
+ 'While (1) { $i }' ,
1495
1524
]
1496
1525
self ._test_expected (WhileStatement , parts )
1497
1526
@@ -1500,7 +1529,9 @@ def test_do_statement(self):
1500
1529
'do\n {\n $i;\n }\n while (++$i -le 5)' ,
1501
1530
'do\n {\n $i;}\n until (++$i -gt 5)' ,
1502
1531
'do { $i } while ($i)' ,
1503
- 'do { $i } until ($i -le 85)'
1532
+ 'do { $i } until ($i -le 85)' ,
1533
+ 'DO { $i } Until ($i -le 85)' ,
1534
+ 'Do { $i } WHILE ($i)' ,
1504
1535
]
1505
1536
self ._test_expected (DoStatement , parts )
1506
1537
@@ -1511,12 +1542,14 @@ def test_foreach_statement(self):
1511
1542
'foreach ($t in [byte],[int],[long]) {$t::MaxValue}' ,
1512
1543
'foreach ($f in dir *.txt)\n \n {}' ,
1513
1544
'foreach ($e in $h1.Keys) {}' ,
1545
+ 'Foreach ($e In $h1.Keys) {}' ,
1546
+ 'FOREACH ($e IN $h1.Keys) {}' ,
1514
1547
]
1515
1548
self ._test_expected (ForeachStatement , parts )
1516
1549
1517
1550
def test_foreach_parameter (self ):
1518
- parsed = self . _parse ( ForeachParameter , "-parallel" )
1519
- self .assertEqual ( str ( parsed ), "-parallel" )
1551
+ params = [ "-parallel" , "-Parallel" , "-PARALLEL" ]
1552
+ self ._test_expected ( ForeachParameter , params )
1520
1553
1521
1554
def test_switch_clause (self ):
1522
1555
parts = [
@@ -1600,6 +1633,14 @@ def test_switch_statement(self):
1600
1633
{
1601
1634
a* { ++$lineCount }
1602
1635
}''' ),
1636
+ dedent ('''Switch -wildcard ("abc")
1637
+ {
1638
+ a* { ++$lineCount }
1639
+ }''' ),
1640
+ dedent ('''SWITCH -wildcard ("abc")
1641
+ {
1642
+ a* { ++$lineCount }
1643
+ }''' ),
1603
1644
1604
1645
dedent ('''switch -regex -casesensitive ("abc")
1605
1646
{
@@ -1631,14 +1672,17 @@ def test_expression_with_unary_operator(self):
1631
1672
for operator in
1632
1673
("," , "-bnot" , "-not" , "-split" , "-join" , "!" , "+" )
1633
1674
]
1634
- parts += [
1635
- "[bool]-10" ,
1636
- "[int]-10.70D" ,
1637
- "[int]10.7" ,
1638
- '[long]"+2.3e+3"' ,
1639
- '[char[]]"Hello"' ,
1640
- '++$k' , '++${k}' ,
1641
- ]
1675
+ parts = chain (
1676
+ parts ,
1677
+ [literal .swapcase () for literal in parts ],
1678
+ [
1679
+ "[bool]-10" ,
1680
+ "[int]-10.70D" ,
1681
+ "[int]10.7" ,
1682
+ '[long]"+2.3e+3"' ,
1683
+ '[char[]]"Hello"' ,
1684
+ '++$k' , '++${k}' ,
1685
+ ])
1642
1686
self ._test_expected (ExpressionWithUnaryOperator , parts )
1643
1687
1644
1688
def test_merging_redirection_operator (self ):
@@ -1701,19 +1745,25 @@ def test_trap_statement(self):
1701
1745
'trap { $j =2; continue }' ,
1702
1746
'trap {$j =2; break }' ,
1703
1747
'trap{}' ,
1748
+ 'Trap{}' ,
1749
+ 'TRAP{}' ,
1704
1750
]
1705
1751
self ._test_expected (TrapStatement , stmts )
1706
1752
1707
1753
def test_finally_clause (self ):
1708
1754
clauses = [
1709
1755
'finally\n { "Tobi is a good boy" }' ,
1710
1756
'finally{$a=4}' ,
1757
+ 'Finally{$a=4}' ,
1758
+ 'FINALLY{$a=4}' ,
1711
1759
]
1712
1760
self ._test_expected (FinallyClause , clauses )
1713
1761
1714
1762
def test_catch_clause (self ):
1715
1763
clauses = [
1716
1764
'catch\n {"Caught unexpected exception"}' ,
1765
+ 'Catch\n {"Caught unexpected exception"}' ,
1766
+ 'CATCH\n {"Caught unexpected exception"}' ,
1717
1767
dedent ('''catch [IndexOutOfRangeException]
1718
1768
{
1719
1769
"Handling out-of-bounds index, >$_<`n"
@@ -1852,6 +1902,10 @@ def test_function_statement(self):
1852
1902
{
1853
1903
$_ * $_
1854
1904
}''' ),
1905
+ dedent ('''FILTER Get-Square2
1906
+ {
1907
+ $_ * $_
1908
+ }''' ),
1855
1909
dedent ('''function Get-Power ([long]$base, [int]$exponent)
1856
1910
{
1857
1911
$result = 1
@@ -1862,6 +1916,7 @@ def test_function_statement(self):
1862
1916
return $result
1863
1917
}''' ),
1864
1918
'function Find-Str ([string]$str, [int]$start_pos = 0) { $str }' ,
1919
+ 'Function Find-Str ([string]$str, [int]$start_pos = 0) { $str }' ,
1865
1920
dedent ('''function Get-Square1
1866
1921
{
1867
1922
foreach ($i in $input)
@@ -1882,6 +1937,9 @@ def test_function_statement(self):
1882
1937
dedent ('''workflow paralleltest {
1883
1938
parallel {
1884
1939
Get-Service -Name s*}}''' ),
1940
+ dedent ('''WORKflow paralleltest {
1941
+ parallel {
1942
+ Get-Service -Name s*}}''' ),
1885
1943
]
1886
1944
self ._test_expected (FunctionStatement , funcs )
1887
1945
@@ -1968,27 +2026,34 @@ def test_inlinescript_statement(self):
1968
2026
stmts = [
1969
2027
'inlinescript {"Inline A0 = $a"}' ,
1970
2028
'inlinescript{$a = $Using:a+1; $a}' ,
2029
+ 'InlineScript{$a = $Using:a+1; $a}' ,
2030
+
1971
2031
]
1972
2032
self ._test_expected (InlinescriptStatement , stmts )
1973
2033
1974
2034
def test_parallel_statement (self ):
1975
2035
stmts = [
1976
2036
'parallel {"Inline A0 = $a"}' ,
1977
2037
'parallel{$a = $Using:a+1; $a}' ,
2038
+ 'Parallel{$a = $Using:a+1; $a}' ,
2039
+ 'PARALLEL{$a = $Using:a+1; $a}' ,
1978
2040
]
1979
2041
self ._test_expected (ParallelStatement , stmts )
1980
2042
1981
2043
def test_sequence_statement (self ):
1982
2044
stmts = [
1983
2045
'sequence {"Inline A0 = $a"}' ,
1984
2046
'sequence {$a = $Using:a+1; $a}' ,
2047
+ 'Sequence {$a = $Using:a+1; $a}' ,
1985
2048
]
1986
2049
self ._test_expected (SequenceStatement , stmts )
1987
2050
1988
2051
def test_param_block (self ):
1989
2052
blocks = [
1990
2053
dedent ('''param ([Parameter(Mandatory = $true)]
1991
2054
[string[]] $ComputerName )''' ),
2055
+ dedent ('''PARAM ([Parameter(Mandatory = $true)]
2056
+ [string[]] $ComputerName )''' ),
1992
2057
dedent ('''param (
1993
2058
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
1994
2059
[string[]]$ComputerName )''' ),
@@ -2096,6 +2161,7 @@ def test_data_commands_allowed(self):
2096
2161
commands = [
2097
2162
"-supportedcommand ConvertFromString" ,
2098
2163
"-supportedcommand TobiIsObito" ,
2164
+ "-SupportedCommand TobiIsObito" ,
2099
2165
]
2100
2166
self ._test_expected (DataCommandsAllowed , commands )
2101
2167
@@ -2104,7 +2170,7 @@ def test_data_statement(self):
2104
2170
# TODO: pathological case
2105
2171
# "data -supportedcommand Format-XML { "
2106
2172
# "Format-XML -strings string1, string2, string3}",
2107
-
2173
+ "DATA {}" ,
2108
2174
"data -supportedcommand Format-XML { "
2109
2175
"Format-XML -strings string1}" ,
2110
2176
@@ -2130,6 +2196,8 @@ def test_data_statement(self):
2130
2196
def test_try_statement (self ):
2131
2197
statement = [
2132
2198
'try { $value / 10 }\n catch { Break }' ,
2199
+ 'Try { $value / 10 }\n Catch { Break }' ,
2200
+ 'TRY { $value / 10 }\n catch { Break }' ,
2133
2201
'try { $value / 10 }\n finally { $status=1 }' ,
2134
2202
2135
2203
'try\n {\n $value / 10\n }\n catch\n {\n Break\n }' ,
0 commit comments