forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewLateBindingTests.cs
More file actions
117 lines (104 loc) · 7.29 KB
/
Copy pathNewLateBindingTests.cs
File metadata and controls
117 lines (104 loc) · 7.29 KB
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
115
116
117
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Collections.Generic;
using System.Dynamic;
using Xunit;
namespace Microsoft.VisualBasic.CompilerServices.Tests
{
public class NewLateBindingTests
{
private sealed class OptionalValuesType : DynamicObject
{
public object F1<T>(T p1 = default)
{
return $"{typeof(T)}, {ToString(p1)}";
}
public object F2<T>(T p1 = default, int? p2 = 2)
{
return $"{typeof(T)}, {ToString(p1)}, {ToString(p2)}";
}
public object F3<T>(object p1, T p2 = default, int? p3 = 3)
{
return $"{typeof(T)}, {ToString(p2)}, {ToString(p3)}";
}
public object F4<T>(object p1, object p2, T p3 = default, int? p4 = 4)
{
return $"{typeof(T)}, {ToString(p3)}, {ToString(p4)}";
}
public object F5<T>(object p1, object p2, object p3, T p4 = default, int? p5 = 5)
{
return $"{typeof(T)}, {ToString(p4)}, {ToString(p5)}";
}
public object F6<T>(object p1, object p2, object p3, object p4, T p5 = default, int? p6 = 6)
{
return $"{typeof(T)}, {ToString(p5)}, {ToString(p6)}";
}
public object F7<T>(object p1, object p2, object p3, object p4, object p5, T p6 = default, int? p7 = 7)
{
return $"{typeof(T)}, {ToString(p6)}, {ToString(p7)}";
}
public object F8<T>(object p1, object p2, object p3, object p4, object p5, object p6, T p7 = default, int? p8 = 8)
{
return $"{typeof(T)}, {ToString(p7)}, {ToString(p8)}";
}
private static string ToString(object obj) => obj?.ToString() ?? "null";
}
public static IEnumerable<object[]> LateCall_OptionalValues_Data()
{
// If System.Type.Missing is used for a parameter with type parameter type,
// System.Reflection.Missing is used in type inference. This matches .NET Framework behavior.
yield return CreateData("F1", new object[] { -1 }, null, "System.Int32, -1");
yield return CreateData("F1", new object[] { Type.Missing }, null, "System.Reflection.Missing, null");
yield return CreateData("F1", new object[] { Type.Missing }, new[] { typeof(int) }, "System.Int32, 0");
yield return CreateData("F2", new object[] { 1, -1 }, null, "System.Int32, 1, -1");
yield return CreateData("F2", new object[] { 1, Type.Missing }, null, "System.Int32, 1, 2");
yield return CreateData("F2", new object[] { Type.Missing, Type.Missing }, null, "System.Reflection.Missing, null, 2");
yield return CreateData("F2", new object[] { Type.Missing, Type.Missing }, new[] { typeof(int) }, "System.Int32, 0, 2");
yield return CreateData("F3", new object[] { 1, 2, -1 }, null, "System.Int32, 2, -1");
yield return CreateData("F3", new object[] { 1, 2, Type.Missing }, null, "System.Int32, 2, 3");
yield return CreateData("F3", new object[] { 1, Type.Missing, Type.Missing }, null, "System.Reflection.Missing, null, 3");
yield return CreateData("F3", new object[] { 1, Type.Missing, Type.Missing }, new[] { typeof(int) }, "System.Int32, 0, 3");
yield return CreateData("F4", new object[] { 1, 2, 3, -1 }, null, "System.Int32, 3, -1");
yield return CreateData("F4", new object[] { 1, 2, 3, Type.Missing }, null, "System.Int32, 3, 4");
yield return CreateData("F4", new object[] { 1, 2, Type.Missing, Type.Missing }, null, "System.Reflection.Missing, null, 4");
yield return CreateData("F4", new object[] { 1, 2, Type.Missing, Type.Missing }, new[] { typeof(int) }, "System.Int32, 0, 4");
yield return CreateData("F5", new object[] { 1, 2, 3, 4, -1 }, null, "System.Int32, 4, -1");
yield return CreateData("F5", new object[] { 1, 2, 3, 4, Type.Missing }, null, "System.Int32, 4, 5");
yield return CreateData("F5", new object[] { 1, 2, 3, Type.Missing, Type.Missing }, null, "System.Reflection.Missing, null, 5");
yield return CreateData("F5", new object[] { 1, 2, 3, Type.Missing, Type.Missing }, new[] { typeof(int) }, "System.Int32, 0, 5");
yield return CreateData("F6", new object[] { 1, 2, 3, 4, 5, -1 }, null, "System.Int32, 5, -1");
yield return CreateData("F6", new object[] { 1, 2, 3, 4, 5, Type.Missing }, null, "System.Int32, 5, 6");
yield return CreateData("F6", new object[] { 1, 2, 3, 4, Type.Missing, Type.Missing }, null, "System.Reflection.Missing, null, 6");
yield return CreateData("F6", new object[] { 1, 2, 3, 4, Type.Missing, Type.Missing }, new[] { typeof(int) }, "System.Int32, 0, 6");
yield return CreateData("F7", new object[] { 1, 2, 3, 4, 5, 6, -1 }, null, "System.Int32, 6, -1");
yield return CreateData("F7", new object[] { 1, 2, 3, 4, 5, 6, Type.Missing }, null, "System.Int32, 6, 7");
yield return CreateData("F7", new object[] { 1, 2, 3, 4, 5, Type.Missing, Type.Missing }, null, "System.Reflection.Missing, null, 7");
yield return CreateData("F7", new object[] { 1, 2, 3, 4, 5, Type.Missing, Type.Missing }, new[] { typeof(int) }, "System.Int32, 0, 7");
yield return CreateData("F8", new object[] { 1, 2, 3, 4, 5, 6, 7, -1 }, null, "System.Int32, 7, -1");
yield return CreateData("F8", new object[] { 1, 2, 3, 4, 5, 6, 7, Type.Missing }, null, "System.Int32, 7, 8");
yield return CreateData("F8", new object[] { 1, 2, 3, 4, 5, 6, Type.Missing, Type.Missing }, null, "System.Reflection.Missing, null, 8");
yield return CreateData("F8", new object[] { 1, 2, 3, 4, 5, 6, Type.Missing, Type.Missing }, new[] { typeof(int) }, "System.Int32, 0, 8");
static object[] CreateData(string memberName, object[] arguments, Type[] typeArguments, string expectedValue) => new object[] { memberName, arguments, typeArguments, expectedValue };
}
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotLinqExpressionsBuiltWithIsInterpretingOnly))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/51834", typeof(PlatformDetection), nameof(PlatformDetection.IsBuiltWithAggressiveTrimming), nameof(PlatformDetection.IsBrowser))]
[MemberData(nameof(LateCall_OptionalValues_Data))]
public void LateCall_OptionalValues(string memberName, object[] arguments, Type[] typeArguments, string expectedValue)
{
// NewLateBinding.LateCall() corresponds to a call to the member when using late binding:
// Dim instance = New OptionalValuesType()
// instance.Member(arguments)
var actualValue = NewLateBinding.LateCall(
Instance: new OptionalValuesType(),
Type: null,
MemberName: memberName,
Arguments: arguments,
ArgumentNames: null,
TypeArguments: typeArguments,
CopyBack: null,
IgnoreReturn: true);
Assert.Equal(expectedValue, actualValue);
}
}
}