forked from IronLanguages/ironpython3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMethodParametersStubs.cs
More file actions
136 lines (109 loc) · 5.23 KB
/
MethodParametersStubs.cs
File metadata and controls
136 lines (109 loc) · 5.23 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Net.NetworkInformation;
using System.Runtime.InteropServices;
using Microsoft.Scripting;
namespace IronPythonTest {
public static class DefaultParams {
public static int FuncWithDefaults(int x=1,
int y=2,
int z=3) {
return x + y + z;
}
}
public static class SplatTest1 {
public static object FuncWithIDictKwargs([ParamDictionary] IDictionary kwargs)
=> kwargs.Count == 1 && (string)kwargs["bla"] == "bla";
public static object FuncWithIDictGenOOKwargs([ParamDictionary] IDictionary<object, object> kwargs)
=> kwargs.Count == 1 && (string)kwargs["bla"] == "bla";
public static object FuncWithIDictGenSOKwargs([ParamDictionary] IDictionary<string, object> kwargs)
=> kwargs.Count == 1 && (string)kwargs["bla"] == "bla";
}
public static class SplatTest2 {
public static object FuncWithIDictKwargs([ParamDictionary] IDictionary kwargs)
=> kwargs.Count == 1 && (string)kwargs["bla"] == "bla";
public static object FuncWithIDictGenOOKwargs([ParamDictionary] IDictionary<object, object> kwargs)
=> kwargs.Count == 1 && (string)kwargs["bla"] == "bla";
public static object FuncWithIDictGenSOKwargs([ParamDictionary] IDictionary<string, object> kwargs)
=> kwargs.Count == 1 && (string)kwargs["bla"] == "bla";
}
public static class Variadics {
public static object FuncWithIDictKwargs([ParamDictionary] IDictionary kwargs) {
foreach (DictionaryEntry kvp in kwargs) {
if (kvp.Value is string val && (string)kvp.Key != val) return kvp.Key;
}
int num = kwargs.Count;
// check that kwargs is mutable
kwargs["$"] = 1;
if ((int)kwargs["$"] != 1) return "$";
kwargs.Remove("$");
if (kwargs.Count != num) return "$-";
return num;
}
public static object FuncWithDictGenOOKwargs([ParamDictionary] Dictionary<object, object> kwargs)
=> FuncWithIDictGenOOKwargs(kwargs);
public static object FuncWithIDictGenOOKwargs([ParamDictionary] IDictionary<object, object> kwargs) {
foreach (KeyValuePair<object, object> kvp in kwargs) {
if (kvp.Value is string val && (string)kvp.Key != val) return kvp.Key;
}
int num = kwargs.Count;
// check that kwargs is mutable
kwargs["$"] = 1;
if ((int)kwargs["$"] != 1) return "$";
kwargs.Remove("$");
if (kwargs.Count != num) return "$-";
return num;
}
public static object FuncWithDictGenSOKwargs([ParamDictionary] Dictionary<string, object> kwargs)
=> FuncWithIDictGenSOKwargs(kwargs);
public static object FuncWithIDictGenSOKwargs([ParamDictionary] IDictionary<string, object> kwargs) {
foreach (KeyValuePair<string, object> kvp in kwargs) {
if (kvp.Value is string val && kvp.Key != val) return kvp.Key;
}
int num = kwargs.Count;
// check that kwargs is mutable
kwargs["$"] = 1;
if ((int)kwargs["$"] != 1) return "$";
kwargs.Remove("$");
if (kwargs.Count != num) return "$-";
return num;
}
public static object FuncWithIDictGenSIKwargs([ParamDictionary] IDictionary<string, int> kwargs) {
foreach (KeyValuePair<string, int> kvp in kwargs) {
if (kvp.Key != $"arg{kvp.Value}") return kvp.Key;
}
int num = kwargs.Count;
// check that kwargs is mutable
kwargs["$"] = 1;
if ((int)kwargs["$"] != 1) return "$";
kwargs.Remove("$");
if (kwargs.Count != num) return "$-";
return num;
}
public static object FuncWithIRoDictGenSOKwargs([ParamDictionary] IReadOnlyDictionary<string, object> kwargs) {
foreach (KeyValuePair<string, object> kvp in kwargs) {
if (kvp.Value is string val && kvp.Key != val) return kvp.Key;
}
return kwargs.Count;
}
public static object FuncWithIRoDictGenOOKwargs([ParamDictionary] IReadOnlyDictionary<object, object> kwargs) {
foreach (KeyValuePair<object, object> kvp in kwargs) {
if (kvp.Value is string val && (string)kvp.Key != val) return kvp.Key;
}
return kwargs.Count;
}
public static object FuncWithIRoDictGenSIKwargs([ParamDictionary] IReadOnlyDictionary<string, int> kwargs) {
foreach (KeyValuePair<string, int> kvp in kwargs) {
if (kvp.Key != $"arg{kvp.Value}") return kvp.Key;
}
return kwargs.Count;
}
public static object FuncWithAttribColKwargs([ParamDictionary] /*unsupported*/ AttributeCollection kwargs) {
return kwargs.Count;
}
}
}