PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms 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
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception, CPL-1.0, CC-BY-SA-3.0, BSD-3-Clause, ISC, AGPL-3.0, LGPL-2.1, Apache-2.0
  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. using System;
  16. #if !CLR2
  17. namespace IronPythonTest {
  18. public static class DynamicRegressions {
  19. public static string cp24117(dynamic inputObj){
  20. return inputObj.ToString();
  21. }
  22. public static void cp24118(dynamic pythonCode) {
  23. dynamic testObj = pythonCode.GetMethodTest();
  24. // calling method with normal params
  25. NamedMethod01(testObj);
  26. // calling method with optional params
  27. NamedMethod02(testObj);
  28. }
  29. private static void NamedMethod01(dynamic testObj) {
  30. try
  31. {
  32. System.Console.WriteLine("1)-1 Exp=33, Act={0}", testObj.Normal01(a: 11, b: 22));
  33. }
  34. catch (System.Exception e)
  35. {
  36. System.Console.WriteLine("1) a:v, b:v => {0}", e);
  37. System.Console.WriteLine("=====================================");
  38. }
  39. System.Console.WriteLine("1)-2 Exp=38, Act={0}", testObj.Normal01(b: 33, a: 5)); // OK
  40. System.Console.WriteLine("=====================================");
  41. }
  42. private static void NamedMethod02(dynamic testObj) {
  43. // b=1
  44. System.Console.WriteLine("2)-1 Exp=11, Act={0}", testObj.Optional01(a: 10)); // OK
  45. try
  46. {
  47. System.Console.WriteLine("2)-2 Exp=33, Act={0}", testObj.Optional01(a: 11, b: 22));
  48. }
  49. catch (System.Exception e)
  50. {
  51. System.Console.WriteLine("2) a:v, b:v => {0}", e);
  52. System.Console.WriteLine("=====================================");
  53. }
  54. System.Console.WriteLine("2)-3 Exp=38, Act={0}", testObj.Optional01(b: 33, a: 5)); // OK
  55. }
  56. public static void cp24115(dynamic testObj) {
  57. try {
  58. dynamic d = testObj.x();
  59. throw new Exception("Invoking non-existent method 'x' should have thrown");
  60. }
  61. catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException ex)
  62. {
  63. if (! ex.Message.Contains("'x'")) {
  64. throw new Exception("Error message didn't contain 'x'", ex);
  65. }
  66. }
  67. }
  68. public static bool cp24111(dynamic testObj)
  69. {
  70. return !testObj;
  71. }
  72. public static void cp24088(dynamic testObj)
  73. {
  74. testObj += 3;
  75. }
  76. }
  77. }
  78. #endif