IOperationTests_IArgument.vb 4.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
' Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.

Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Imports Roslyn.Test.Utilities

Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Semantics

    Partial Public Class IOperationTests
        Inherits SemanticModelTestBase

        <Fact()>
        Public Sub ExplicitSimpleArgument()
            Dim source = <![CDATA[
Module P
    Sub M1()
        M2(1, "")'BIND:"M2(1, "")"
    End Sub

    Sub M2(x As Integer, y As String)
    End Sub
End Module]]>.Value

            Dim expectedOperationTree = <![CDATA[
IInvocationExpression (static Sub P.M2(x As System.Int32, y As System.String)) (OperationKind.InvocationExpression, Type: System.Void)
  IArgument (ArgumentKind.Positional Matching Parameter: x) (OperationKind.Argument)
    ILiteralExpression (Text: 1) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 1)
  IArgument (ArgumentKind.Positional Matching Parameter: y) (OperationKind.Argument)
    ILiteralExpression (OperationKind.LiteralExpression, Type: System.String, Constant: )
]]>.Value

            VerifyOperationTreeForTest(Of InvocationExpressionSyntax)(source, expectedOperationTree)
        End Sub

        <Fact()>
        Public Sub ExplicitSimpleArgumentByName()
            Dim source = <![CDATA[   
Class P
    Sub M1()
        M2(y:=1, x:=2)'BIND:"M2(y:=1, x:=2)"
    End Sub

    Sub M2(x As Integer, y As Integer)
    End Sub
End Class]]>.Value

            Dim expectedOperationTree = <![CDATA[
IInvocationExpression ( Sub P.M2(x As System.Int32, y As System.Int32)) (OperationKind.InvocationExpression, Type: System.Void)
  Instance Receiver: IInstanceReferenceExpression (InstanceReferenceKind.Implicit) (OperationKind.InstanceReferenceExpression, Type: P)
  IArgument (ArgumentKind.Positional Matching Parameter: x) (OperationKind.Argument)
    ILiteralExpression (Text: 2) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 2)
  IArgument (ArgumentKind.Positional Matching Parameter: y) (OperationKind.Argument)
    ILiteralExpression (Text: 1) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 1)
]]>.Value

            VerifyOperationTreeForTest(Of InvocationExpressionSyntax)(source, expectedOperationTree)
        End Sub

        <Fact()>
        Public Sub DefaultArgument()
            Dim source = <![CDATA[  
Class P
    Sub M1()
        M2(1)'BIND:"M2(1)"
    End Sub

    Sub M2(x As Integer, Optional y As Integer = 10)
    End Sub
End Class]]>.Value

            Dim expectedOperationTree = <![CDATA[
IInvocationExpression ( Sub P.M2(x As System.Int32, [y As System.Int32 = 10])) (OperationKind.InvocationExpression, Type: System.Void)
  Instance Receiver: IInstanceReferenceExpression (InstanceReferenceKind.Implicit) (OperationKind.InstanceReferenceExpression, Type: P)
  IArgument (ArgumentKind.Positional Matching Parameter: x) (OperationKind.Argument)
    ILiteralExpression (Text: 1) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 1)
  IArgument (ArgumentKind.Positional Matching Parameter: y) (OperationKind.Argument)
    ILiteralExpression (OperationKind.LiteralExpression, Type: System.Int32, Constant: 10)
]]>.Value

            VerifyOperationTreeForTest(Of InvocationExpressionSyntax)(source, expectedOperationTree)
        End Sub

        <Fact()>
        Public Sub ParamArrayArgument()
            Dim source = <![CDATA[
Class P
    Sub M1()
        M2(1, 2, 3)'BIND:"M2(1, 2, 3)"
    End Sub

    Sub M2(a As Integer, ParamArray c As Integer())
    End Sub
End Class]]>.Value

            Dim expectedOperationTree = <![CDATA[
IInvocationExpression ( Sub P.M2(a As System.Int32, ParamArray c As System.Int32())) (OperationKind.InvocationExpression, Type: System.Void)
  Instance Receiver: IInstanceReferenceExpression (InstanceReferenceKind.Implicit) (OperationKind.InstanceReferenceExpression, Type: P)
  IArgument (ArgumentKind.Positional Matching Parameter: a) (OperationKind.Argument)
    ILiteralExpression (Text: 1) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 1)
  IArgument (ArgumentKind.ParamArray Matching Parameter: c) (OperationKind.Argument)
    IArrayCreationExpression (Dimension sizes: 1, Element Type: System.Int32) (OperationKind.ArrayCreationExpression, Type: System.Int32())
      ILiteralExpression (OperationKind.LiteralExpression, Type: System.Int32, Constant: 2)
      IArrayInitializer (OperationKind.ArrayInitializer)
        ILiteralExpression (Text: 2) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 2)
        ILiteralExpression (Text: 3) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 3)
]]>.Value

            VerifyOperationTreeForTest(Of InvocationExpressionSyntax)(source, expectedOperationTree)
        End Sub



    End Class
End Namespace