@@ -361,10 +361,8 @@ Describe "Type inference Tests" -tags "CI" {
361
361
362
362
It" Infers type from foreach-object of integer" {
363
363
$res = [AstTypeInference ]::InferTypeOf( { [int []]$i = 1 .. 20 ;$i | ForEach-Object {$_ * 10 } }.Ast)
364
- $res.Count | Should- Be2
365
- foreach ($r in $res ) {
366
- $r.Name -In ' System.Int32' , ' System.Int32[]' | Should- BeTrue
367
- }
364
+ $res.Count | Should- Be1
365
+ $res.Name | Should- Be' System.Int32'
368
366
}
369
367
370
368
It" Infers type from generic new" {
@@ -386,9 +384,9 @@ Describe "Type inference Tests" -tags "CI" {
386
384
387
385
It" Infers type from foreach-object with begin/end" {
388
386
$res = [AstTypeInference ]::InferTypeOf( { [int []]$i = 1 .. 20 ;$i | ForEach-Object - Begin {" Hi" } {$_ * 10 }- End {[int ]} }.Ast)
389
- $res.Count | Should- Be4
387
+ $res.Count | Should- Be3
390
388
foreach ($r in $res ) {
391
- $r.Name -In ' System.Int32' , ' System.Int32[] ' , ' System. String' , ' System.Type' | Should- BeTrue
389
+ $r.Name -In ' System.Int32' , ' System.String' , ' System.Type' | Should- BeTrue
392
390
}
393
391
}
394
392
@@ -618,16 +616,6 @@ Describe "Type inference Tests" -tags "CI" {
618
616
$res.Name | Should- Be' System.Int32'
619
617
}
620
618
621
- It' Infers type from attributed expession' {
622
- $res = [AstTypeInference ]::InferTypeOf( {
623
- [ValidateRange (1 , 2 )]
624
- [int ]$i = 1
625
- }.Ast)
626
-
627
- $res.Count | Should- Be1
628
- $res.Name | Should- Be System.Int32
629
- }
630
-
631
619
It' Infers type from if statement' {
632
620
$res = [AstTypeInference ]::InferTypeOf( {
633
621
if ($true ) {return 1 }
@@ -1399,7 +1387,8 @@ Describe "Type inference Tests" -tags "CI" {
1399
1387
1400
1388
It' Infers closest variable type' {
1401
1389
$res = [AstTypeInference ]::InferTypeOf( { [string ]$TestVar = " " ;[hashtable ]$TestVar = @ {};$TestVar }.Ast)
1402
- $res.Name | Select-Object - Last1 | Should- Be" System.Collections.Hashtable"
1390
+ $res.Count | Should- Be1
1391
+ $res.Name | Should- Be" System.Collections.Hashtable"
1403
1392
}
1404
1393
1405
1394
It' Infers closest variable type and ignores unrelated param blocks' {
@@ -1444,6 +1433,66 @@ Describe "Type inference Tests" -tags "CI" {
1444
1433
)
1445
1434
$null = [AstTypeInference ]::InferTypeOf($FoundAst )
1446
1435
}
1436
+
1437
+ It' Should only consider assignments wrapped in parentheses to be a part of the output in a Named block' {
1438
+ $res = [AstTypeInference ]::InferTypeOf( { [string ]$Assignment1 = " Hello" ; ([int ]$Assignment2 = 42 ) }.Ast)
1439
+ $res.Count | Should- Be1
1440
+ $res.Name | Should- Be' System.Int32'
1441
+ }
1442
+
1443
+ It' Should only consider assignments wrapped in parentheses to be a part of the output in a Statement block' {
1444
+ $res = [AstTypeInference ]::InferTypeOf( {if ($true ){ [string ]$Assignment1 = " Hello" ; ([int ]$Assignment2 = 42 ) }}.Ast)
1445
+ $res.Count | Should- Be1
1446
+ $res.Name | Should- Be' System.Int32'
1447
+ }
1448
+
1449
+ It' Should only consider increments/decrements wrapped in parentheses to be a part of the output in a Named block' {
1450
+ $res = [AstTypeInference ]::InferTypeOf( {
1451
+ [Int16 ]$Int16 = 1 ; [Int32 ]$Int32 = 1 ; [Int64 ]$Int64 = 1 ; [System.Int128 ]$Int128 = 1 ;
1452
+
1453
+ $Int16 ++ ;$Int32 -- ;++ $Int64 ;-- $Int128 }.Ast)
1454
+ $res.Count | Should- Be0
1455
+
1456
+ $res = [AstTypeInference ]::InferTypeOf( {
1457
+ [UInt16 ]$Uint16 = 1 ; [UInt32 ]$Uint32 = 1 ; [UInt64 ]$Uint64 = 1 ; [System.UInt128 ]$Uint128 = 1
1458
+
1459
+ ($Uint16 ++ ); ($Uint32 -- ); (++ $Uint64 ); (-- $Uint128 ) }.Ast)
1460
+ $res.Count | Should- Be4
1461
+ $res.Name -join ' ,' | Should- Be (' System.UInt16' , ' System.UInt32' , ' System.UInt64' , ' System.UInt128' -join ' ,' )
1462
+ }
1463
+
1464
+ It' Should only consider increments/decrements wrapped in parentheses to be a part of the output in a Statement block' {
1465
+ $res = [AstTypeInference ]::InferTypeOf( {if ($true ){
1466
+ [Int16 ]$Int16 = 1 ; [Int32 ]$Int32 = 1 ; [Int64 ]$Int64 = 1 ; [System.Int128 ]$Int128 = 1 ;
1467
+
1468
+ $Int16 ++ ;$Int32 -- ;++ $Int64 ;-- $Int128 }}.Ast)
1469
+ $res.Count | Should- Be0
1470
+
1471
+ $res = [AstTypeInference ]::InferTypeOf( {if ($true ){
1472
+ [UInt16 ]$Uint16 = 1 ; [UInt32 ]$Uint32 = 1 ; [UInt64 ]$Uint64 = 1 ; [System.UInt128 ]$Uint128 = 1
1473
+
1474
+ ($Uint16 ++ ); ($Uint32 -- ); (++ $Uint64 ); (-- $Uint128 ) }}.Ast)
1475
+ $res.Count | Should- Be4
1476
+ $res.Name -join ' ,' | Should- Be (' System.UInt16' , ' System.UInt32' , ' System.UInt64' , ' System.UInt128' -join ' ,' )
1477
+ }
1478
+
1479
+ It' Redirected increments/decrements should be considered part of the output in a Named block' {
1480
+ $res = [AstTypeInference ]::InferTypeOf( {
1481
+ [Int16 ]$Int16 = 1 ; [Int32 ]$Int32 = 1 ; [Int64 ]$Int64 = 1 ; [System.Int128 ]$Int128 = 1 ;
1482
+
1483
+ $Int16 ++ * > & 1 ;$Int32 -- * > & 1 ;++ $Int64 * > & 1 ;-- $Int128 * > & 1 }.Ast)
1484
+ $res.Count | Should- Be4
1485
+ $res.Name -join ' ,' | Should- Be (' System.Int16' , ' System.Int32' , ' System.Int64' , ' System.Int128' -join ' ,' )
1486
+ }
1487
+
1488
+ It' Redirected increments/decrements should be considered part of the output in a Statement block' {
1489
+ $res = [AstTypeInference ]::InferTypeOf( {if ($true ){
1490
+ [Int16 ]$Int16 = 1 ; [Int32 ]$Int32 = 1 ; [Int64 ]$Int64 = 1 ; [System.Int128 ]$Int128 = 1 ;
1491
+
1492
+ $Int16 ++ * > & 1 ;$Int32 -- * > & 1 ;++ $Int64 * > & 1 ;-- $Int128 * > & 1 }}.Ast)
1493
+ $res.Count | Should- Be4
1494
+ $res.Name -join ' ,' | Should- Be (' System.Int16' , ' System.Int32' , ' System.Int64' , ' System.Int128' -join ' ,' )
1495
+ }
1447
1496
}
1448
1497
1449
1498
Describe" AstTypeInference tests" - Tags CI {