IOperationTests_IArgument.vb 9.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
' 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[
14
Class P
15
    Sub M1()
16
        M2(1, 2.0)'BIND:"M2(1, 2.0)"
17 18
    End Sub

19
    Sub M2(x As Integer, y As Double)
20
    End Sub
21
End Class]]>.Value
22 23

            Dim expectedOperationTree = <![CDATA[
24 25
IInvocationExpression ( Sub P.M2(x As System.Int32, y As System.Double)) (OperationKind.InvocationExpression, Type: System.Void) (Syntax: 'M2(1, 2.0)')
  Instance Receiver: IInstanceReferenceExpression (InstanceReferenceKind.Implicit) (OperationKind.InstanceReferenceExpression, Type: P) (Syntax: 'M2')
G
Gen Lu 已提交
26
  Arguments(2): IArgument (ArgumentKind.Explicit Matching Parameter: x) (OperationKind.Argument) (Syntax: '1')
27
      ILiteralExpression (Text: 1) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 1) (Syntax: '1')
G
Gen Lu 已提交
28
    IArgument (ArgumentKind.Explicit Matching Parameter: y) (OperationKind.Argument) (Syntax: '2.0')
29
      ILiteralExpression (OperationKind.LiteralExpression, Type: System.Double, Constant: 2) (Syntax: '2.0')
30 31
]]>.Value

32 33 34
            Dim expectedDiagnostics = String.Empty

            VerifyOperationTreeAndDiagnosticsForTest(Of InvocationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics)
35 36 37 38
        End Sub

        <Fact()>
        Public Sub ExplicitSimpleArgumentByName()
39 40 41 42 43 44 45 46 47 48 49 50 51
            Dim source = <![CDATA[
Class P
    Sub M1()
        M2(y:=1, x:=2.0)'BIND:"M2(y:=1, x:=2.0)"
    End Sub

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

            Dim expectedOperationTree = <![CDATA[
IInvocationExpression ( Sub P.M2(x As System.Int32, y As System.Double)) (OperationKind.InvocationExpression, Type: System.Void) (Syntax: 'M2(y:=1, x:=2.0)')
  Instance Receiver: IInstanceReferenceExpression (InstanceReferenceKind.Implicit) (OperationKind.InstanceReferenceExpression, Type: P) (Syntax: 'M2')
G
Gen Lu 已提交
52
  Arguments(2): IArgument (ArgumentKind.Explicit Matching Parameter: x) (OperationKind.Argument) (Syntax: '2.0')
53 54
      IConversionExpression (ConversionKind.Basic, Implicit) (OperationKind.ConversionExpression, Type: System.Int32, Constant: 2) (Syntax: '2.0')
        ILiteralExpression (OperationKind.LiteralExpression, Type: System.Double, Constant: 2) (Syntax: '2.0')
G
Gen Lu 已提交
55
    IArgument (ArgumentKind.Explicit Matching Parameter: y) (OperationKind.Argument) (Syntax: '1')
56 57 58 59 60 61 62 63 64 65 66 67
      IConversionExpression (ConversionKind.Basic, Implicit) (OperationKind.ConversionExpression, Type: System.Double, Constant: 1) (Syntax: '1')
        ILiteralExpression (Text: 1) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 1) (Syntax: '1')
]]>.Value

            Dim expectedDiagnostics = String.Empty

            VerifyOperationTreeAndDiagnosticsForTest(Of InvocationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics)
        End Sub

        <Fact()>
        Public Sub XXXX()
            Dim source = <![CDATA[
68 69
Class P
    Sub M1()
70
        M2(y:=2)'BIND:"M2(y:=2)"
71 72
    End Sub

73
    Sub M2(Optional x As Integer = 0, Optional y As Integer = 0)
74 75 76 77
    End Sub
End Class]]>.Value

            Dim expectedOperationTree = <![CDATA[
78 79
IInvocationExpression ( Sub P.M2([x As System.Int32 = 0], [y As System.Int32 = 0])) (OperationKind.InvocationExpression, Type: System.Void) (Syntax: 'M2(y:=2)')
  Instance Receiver: IInstanceReferenceExpression (InstanceReferenceKind.Implicit) (OperationKind.InstanceReferenceExpression, Type: P) (Syntax: 'M2')
G
Gen Lu 已提交
80
  Arguments(2): IArgument (ArgumentKind.DefaultValue Matching Parameter: x) (OperationKind.Argument) (Syntax: 'M2')
81
      ILiteralExpression (OperationKind.LiteralExpression, Type: System.Int32, Constant: 0) (Syntax: 'M2')
G
Gen Lu 已提交
82
    IArgument (ArgumentKind.Explicit Matching Parameter: y) (OperationKind.Argument) (Syntax: '2')
83
      ILiteralExpression (Text: 2) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 2) (Syntax: '2')
84 85
]]>.Value

86 87 88
            Dim expectedDiagnostics = String.Empty

            VerifyOperationTreeAndDiagnosticsForTest(Of InvocationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics)
89 90 91 92
        End Sub

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

99
    Sub M2(x As Integer, Optional y As Double = 0.0)
100 101 102 103
    End Sub
End Class]]>.Value

            Dim expectedOperationTree = <![CDATA[
104 105
IInvocationExpression ( Sub P.M2(x As System.Int32, [y As System.Double = 0])) (OperationKind.InvocationExpression, Type: System.Void) (Syntax: 'M2(1)')
  Instance Receiver: IInstanceReferenceExpression (InstanceReferenceKind.Implicit) (OperationKind.InstanceReferenceExpression, Type: P) (Syntax: 'M2')
G
Gen Lu 已提交
106
  Arguments(2): IArgument (ArgumentKind.Explicit Matching Parameter: x) (OperationKind.Argument) (Syntax: '1')
107
      ILiteralExpression (Text: 1) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 1) (Syntax: '1')
G
Gen Lu 已提交
108
    IArgument (ArgumentKind.DefaultValue Matching Parameter: y) (OperationKind.Argument) (Syntax: 'M2')
109
      ILiteralExpression (OperationKind.LiteralExpression, Type: System.Double, Constant: 0) (Syntax: 'M2')
110 111
]]>.Value

112 113 114
            Dim expectedDiagnostics = String.Empty

            VerifyOperationTreeAndDiagnosticsForTest(Of InvocationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics)
115 116 117 118 119 120 121 122 123 124
        End Sub

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

125
    Sub M2(x As Integer, ParamArray array As Integer())
126 127 128 129
    End Sub
End Class]]>.Value

            Dim expectedOperationTree = <![CDATA[
130 131
IInvocationExpression ( Sub P.M2(x As System.Int32, ParamArray array As System.Int32())) (OperationKind.InvocationExpression, Type: System.Void) (Syntax: 'M2(1, 2, 3)')
  Instance Receiver: IInstanceReferenceExpression (InstanceReferenceKind.Implicit) (OperationKind.InstanceReferenceExpression, Type: P) (Syntax: 'M2')
G
Gen Lu 已提交
132
  Arguments(2): IArgument (ArgumentKind.Explicit Matching Parameter: x) (OperationKind.Argument) (Syntax: '1')
133 134 135 136 137 138 139
      ILiteralExpression (Text: 1) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 1) (Syntax: '1')
    IArgument (ArgumentKind.ParamArray Matching Parameter: array) (OperationKind.Argument) (Syntax: 'M2(1, 2, 3)')
      IArrayCreationExpression (Element Type: System.Int32) (OperationKind.ArrayCreationExpression, Type: System.Int32()) (Syntax: 'M2(1, 2, 3)')
        Dimension Sizes(1): ILiteralExpression (OperationKind.LiteralExpression, Type: System.Int32, Constant: 2) (Syntax: 'M2(1, 2, 3)')
        Initializer: IArrayInitializer (OperationKind.ArrayInitializer) (Syntax: 'M2(1, 2, 3)')
            Element Values(2): ILiteralExpression (Text: 2) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 2) (Syntax: '2')
              ILiteralExpression (Text: 3) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 3) (Syntax: '3')
140 141
]]>.Value

142 143 144
            Dim expectedDiagnostics = String.Empty

            VerifyOperationTreeAndDiagnosticsForTest(Of InvocationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics)
145 146
        End Sub

147 148 149 150 151 152 153 154 155 156 157
        <Fact()>
        Public Sub ArrayAsParamsArrayArgument()
            Dim source = <![CDATA[
Class P
    Sub M1()
        M2(1, New Integer() {2, 3})'BIND:"M2(1, New Integer() {2, 3})"
    End Sub

    Sub M2(x As Integer, ParamArray array As Integer())
    End Sub
End Class]]>.Value
158

159 160 161
            Dim expectedOperationTree = <![CDATA[
IInvocationExpression ( Sub P.M2(x As System.Int32, ParamArray array As System.Int32())) (OperationKind.InvocationExpression, Type: System.Void) (Syntax: 'M2(1, New I ... r() {2, 3})')
  Instance Receiver: IInstanceReferenceExpression (InstanceReferenceKind.Implicit) (OperationKind.InstanceReferenceExpression, Type: P) (Syntax: 'M2')
G
Gen Lu 已提交
162
  Arguments(2): IArgument (ArgumentKind.Explicit Matching Parameter: x) (OperationKind.Argument) (Syntax: '1')
163
      ILiteralExpression (Text: 1) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 1) (Syntax: '1')
G
Gen Lu 已提交
164
    IArgument (ArgumentKind.Explicit Matching Parameter: array) (OperationKind.Argument) (Syntax: 'New Integer() {2, 3}')
165 166 167 168 169 170 171 172 173 174 175
      IArrayCreationExpression (Element Type: System.Int32) (OperationKind.ArrayCreationExpression, Type: System.Int32()) (Syntax: 'New Integer() {2, 3}')
        Dimension Sizes(1): ILiteralExpression (OperationKind.LiteralExpression, Type: System.Int32, Constant: 2) (Syntax: 'New Integer() {2, 3}')
        Initializer: IArrayInitializer (OperationKind.ArrayInitializer) (Syntax: '{2, 3}')
            Element Values(2): ILiteralExpression (Text: 2) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 2) (Syntax: '2')
              ILiteralExpression (Text: 3) (OperationKind.LiteralExpression, Type: System.Int32, Constant: 3) (Syntax: '3')
]]>.Value

            Dim expectedDiagnostics = String.Empty

            VerifyOperationTreeAndDiagnosticsForTest(Of InvocationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics)
        End Sub
176 177 178 179

    End Class
End Namespace