forked from IronLanguages/ironpython3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDynamicRegressions.cs
More file actions
77 lines (65 loc) · 2.6 KB
/
DynamicRegressions.cs
File metadata and controls
77 lines (65 loc) · 2.6 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
// 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;
namespace IronPythonTest {
public static class DynamicRegressions {
public static string cp24117(dynamic inputObj){
return inputObj.ToString();
}
public static void cp24118(dynamic pythonCode) {
dynamic testObj = pythonCode.GetMethodTest();
// calling method with normal params
NamedMethod01(testObj);
// calling method with optional params
NamedMethod02(testObj);
}
private static void NamedMethod01(dynamic testObj) {
try
{
System.Console.WriteLine("1)-1 Exp=33, Act={0}", testObj.Normal01(a: 11, b: 22));
}
catch (System.Exception e)
{
System.Console.WriteLine("1) a:v, b:v => {0}", e);
System.Console.WriteLine("=====================================");
}
System.Console.WriteLine("1)-2 Exp=38, Act={0}", testObj.Normal01(b: 33, a: 5)); // OK
System.Console.WriteLine("=====================================");
}
private static void NamedMethod02(dynamic testObj) {
// b=1
System.Console.WriteLine("2)-1 Exp=11, Act={0}", testObj.Optional01(a: 10)); // OK
try
{
System.Console.WriteLine("2)-2 Exp=33, Act={0}", testObj.Optional01(a: 11, b: 22));
}
catch (System.Exception e)
{
System.Console.WriteLine("2) a:v, b:v => {0}", e);
System.Console.WriteLine("=====================================");
}
System.Console.WriteLine("2)-3 Exp=38, Act={0}", testObj.Optional01(b: 33, a: 5)); // OK
}
public static void cp24115(dynamic testObj) {
try {
testObj.x();
throw new Exception("Invoking non-existent method 'x' should have thrown");
}
catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException ex)
{
if (!ex.Message.Contains("'x'")) {
throw new Exception("Error message didn't contain 'x'", ex);
}
}
}
public static bool cp24111(dynamic testObj)
{
return !testObj;
}
public static void cp24088(dynamic testObj)
{
testObj += 3;
}
}
}