Repository: PowerShell/PowerShell
File: test/powershell/engine/Api/TypeInference.Tests.ps1 (PowerShell)

Code before:

    It 'Should only consider assignments wrapped in parentheses to be a part of the output in a Named block' {
        $res = [AstTypeInference]::InferTypeOf( { [string]$Assignment1 = "Hello"; ([int]$Assignment2 = 42) }.Ast)
        $res.Count | Should -Be 1
        $res.Name | Should -Be 'System.Int32'
    }

    It 'Should only consider assignments wrapped in parentheses to be a part of the output in a Statement block' {
        $res = [AstTypeInference]::InferTypeOf( { if ($true){ [string]$Assignment1 = "Hello"; ([int]$Assignment2 = 42) }}.Ast)
        $res.Count | Should -Be 1
        $res.Name | Should -Be 'System.Int32'
    }

    It 'Should only consider increments/decrements wrapped in parentheses to be a part of the output in a Named block' {
        $res = [AstTypeInference]::InferTypeOf( {
            [Int16]$Int16 = 1; [Int32]$Int32 = 1; [Int64]$Int64 = 1; [System.Int128]$Int128 = 1;
            [UInt16]$Uint16 = 1; [UInt32]$Uint32 = 1; [UInt64]$Uint64 = 1; [System.UInt128]$Uint128 = 1

            $Int16++; $Int32--; ++$Int64; --$Int128
            ($Uint16++); ($Uint32--); (++$Uint64); (--$Uint128) }.Ast)
        $res.Count | Should -Be 4
        $res.Name -join ',' | Should -Be ('System.UInt16', 'System.UInt32', 'System.UInt64', 'System.UInt128' -join ',')
    }

    It 'Should only consider increments/decrements wrapped in parentheses to be a part of the output in a Statement block' {
        $res = [AstTypeInference]::InferTypeOf( {if ($true){
            [Int16]$Int16 = 1; [Int32]$Int32 = 1; [Int64]$Int64 = 1; [System.Int128]$Int128 = 1;
            [UInt16]$Uint16 = 1; [UInt32]$Uint32 = 1; [UInt64]$Uint64 = 1; [System.UInt128]$Uint128 = 1

            $Int16++; $Int32--; ++$Int64; --$Int128
            ($Uint16++); ($Uint32--); (++$Uint64); (--$Uint128) }}.Ast)
        $res.Count | Should -Be 4
        $res.Name -join ',' | Should -Be ('System.UInt16', 'System.UInt32', 'System.UInt64', 'System.UInt128' -join ',')
    }

    It 'Redirected increments/decrements should be considered part of the output in a Named block' {
        $res = [AstTypeInference]::InferTypeOf( {
            [Int16]$Int16 = 1; [Int32]$Int32 = 1; [Int64]$Int64 = 1; [System.Int128]$Int128 = 1;

            $Int16++ *>&1; $Int32-- *>&1; ++$Int64 *>&1; --$Int128 *>&1}.Ast)
        $res.Count | Should -Be 4
        $res.Name -join ',' | Should -Be ('System.Int16', 'System.Int32', 'System.Int64', 'System.Int128' -join ',')
    }

    It 'Redirected increments/decrements should be considered part of the output in a Statement block' {
        $res = [AstTypeInference]::InferTypeOf( {if ($true){
            [Int16]$Int16 = 1; [Int32]$Int32 = 1; [Int64]$Int64 = 1; [System.Int128]$Int128 = 1;

            $Int16++ *>&1; $Int32-- *>&1; ++$Int64 *>&1; --$Int128 *>&1}}.Ast)
        $res.Count | Should -Be 4
        $res.Name -join ',' | Should -Be ('System.Int16', 'System.Int32', 'System.Int64', 'System.Int128' -join ',')

Review comment (suggestion):
Previous tests have one case with string "Hello" and second one with int and we can distinct string and int.
In the tests all is int-s and it is not clear what is line in the test return non-empty result.
I mean we should check (1) first 3 line, (2) then all 4 line.

Code after:

    It 'Should only consider assignments wrapped in parentheses to be a part of the output in a Named block' {
        $res = [AstTypeInference]::InferTypeOf( { [string]$Assignment1 = "Hello"; ([int]$Assignment2 = 42) }.Ast)
        $res.Count | Should -Be 1
        $res.Name | Should -Be 'System.Int32'
    }

    It 'Should only consider assignments wrapped in parentheses to be a part of the output in a Statement block' {
        $res = [AstTypeInference]::InferTypeOf( { if ($true){ [string]$Assignment1 = "Hello"; ([int]$Assignment2 = 42) }}.Ast)
        $res.Count | Should -Be 1
        $res.Name | Should -Be 'System.Int32'
    }

    It 'Should only consider increments/decrements wrapped in parentheses to be a part of the output in a Named block' {
        $res = [AstTypeInference]::InferTypeOf( {
            [Int16]$Int16 = 1; [Int32]$Int32 = 1; [Int64]$Int64 = 1; [System.Int128]$Int128 = 1;

            $Int16++; $Int32--; ++$Int64; --$Int128}.Ast)
        $res.Count | Should -Be 0

        $res = [AstTypeInference]::InferTypeOf( {
            [UInt16]$Uint16 = 1; [UInt32]$Uint32 = 1; [UInt64]$Uint64 = 1; [System.UInt128]$Uint128 = 1

            ($Uint16++); ($Uint32--); (++$Uint64); (--$Uint128) }.Ast)
        $res.Count | Should -Be 4
        $res.Name -join ',' | Should -Be ('System.UInt16', 'System.UInt32', 'System.UInt64', 'System.UInt128' -join ',')
    }

    It 'Should only consider increments/decrements wrapped in parentheses to be a part of the output in a Statement block' {
        $res = [AstTypeInference]::InferTypeOf( {if ($true){
            [Int16]$Int16 = 1; [Int32]$Int32 = 1; [Int64]$Int64 = 1; [System.Int128]$Int128 = 1;

            $Int16++; $Int32--; ++$Int64; --$Int128}}.Ast)
        $res.Count | Should -Be 0

        $res = [AstTypeInference]::InferTypeOf( {if ($true){
            [UInt16]$Uint16 = 1; [UInt32]$Uint32 = 1; [UInt64]$Uint64 = 1; [System.UInt128]$Uint128 = 1

            ($Uint16++); ($Uint32--); (++$Uint64); (--$Uint128) }}.Ast)
        $res.Count | Should -Be 4
        $res.Name -join ',' | Should -Be ('System.UInt16', 'System.UInt32', 'System.UInt64', 'System.UInt128' -join ',')
    }

    It 'Redirected increments/decrements should be considered part of the output in a Named block' {
        $res = [AstTypeInference]::InferTypeOf( {
            [Int16]$Int16 = 1; [Int32]$Int32 = 1; [Int64]$Int64 = 1; [System.Int128]$Int128 = 1;

            $Int16++ *>&1; $Int32-- *>&1; ++$Int64 *>&1; --$Int128 *>&1}.Ast)
        $res.Count | Should -Be 4
        $res.Name -join ',' | Should -Be ('System.Int16', 'System.Int32', 'System.Int64', 'System.Int128' -join ',')
    }