PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/IronPython_Main/Languages/IronPython/IronPythonTest/DynamicRegressions.cs

#
C# | 90 lines | 61 code | 12 blank | 17 comment | 1 complexity | 02f6c3d33b95f714347e2c653f5207cd MD5 | raw file
 1/* ****************************************************************************
 2 *
 3 * Copyright (c) Microsoft Corporation. 
 4 *
 5 * This source code is subject to terms and conditions of the Apache License, Version 2.0. A 
 6 * copy of the license can be found in the License.html file at the root of this distribution. If 
 7 * you cannot locate the  Apache License, Version 2.0, please send an email to 
 8 * ironpy@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 9 * by the terms of the Apache License, Version 2.0.
10 *
11 * You must not remove this notice, or any other, from this software.
12 *
13 *
14 * ***************************************************************************/
15
16using System;
17
18#if !CLR2
19namespace IronPythonTest {
20    public static class DynamicRegressions {
21        
22        public static string cp24117(dynamic inputObj){
23            return inputObj.ToString();
24        }
25
26        public static void cp24118(dynamic pythonCode) {
27            dynamic testObj = pythonCode.GetMethodTest();
28
29            // calling method with normal params
30            NamedMethod01(testObj);
31            // calling method with optional params
32            NamedMethod02(testObj);
33        }
34
35        private static void NamedMethod01(dynamic testObj) {
36            try
37            {
38                System.Console.WriteLine("1)-1 Exp=33, Act={0}", testObj.Normal01(a: 11, b: 22));
39            }
40            catch (System.Exception e)
41            {
42                System.Console.WriteLine("1) a:v, b:v => {0}", e);
43                System.Console.WriteLine("=====================================");
44            }
45
46            System.Console.WriteLine("1)-2 Exp=38, Act={0}", testObj.Normal01(b: 33, a: 5)); // OK
47            System.Console.WriteLine("=====================================");
48        }
49
50        private static void NamedMethod02(dynamic testObj) {
51            // b=1
52            System.Console.WriteLine("2)-1 Exp=11, Act={0}", testObj.Optional01(a: 10)); // OK
53            try
54            {
55                System.Console.WriteLine("2)-2 Exp=33, Act={0}", testObj.Optional01(a: 11, b: 22));
56            }
57            catch (System.Exception e)
58            {
59                System.Console.WriteLine("2) a:v, b:v => {0}", e);
60                System.Console.WriteLine("=====================================");
61            }
62            System.Console.WriteLine("2)-3 Exp=38, Act={0}", testObj.Optional01(b: 33, a: 5)); // OK
63        }
64    
65
66        public static void cp24115(dynamic testObj) {
67            try {
68                dynamic d = testObj.x();
69                throw new Exception("Invoking non-existent method 'x' should have thrown");
70            }
71            catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException ex)
72            {
73                if (! ex.Message.Contains("'x'")) {
74                    throw new Exception("Error message didn't contain 'x'", ex);
75                }
76            }
77        }
78
79        public static bool cp24111(dynamic testObj)
80        {
81            return !testObj;
82        }
83
84        public static void cp24088(dynamic testObj)
85        {
86            testObj += 3;
87        }
88    }
89}
90#endif