PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/test-suite/d/li_attribute_runme.1.d

#
D | 75 lines | 60 code | 12 blank | 3 comment | 36 complexity | 1a7742b943c61a3f0a4d62f55936ffad MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. module li_attribute_runme;
  2. import li_attribute.A;
  3. import li_attribute.B;
  4. import li_attribute.MyClass;
  5. import li_attribute.MyClassVal;
  6. import li_attribute.MyStringyClass;
  7. import li_attribute.MyFoo;
  8. import li_attribute.Param_i;
  9. void main() {
  10. auto aa = new A(1,2,3);
  11. if (aa.a != 1)
  12. throw new Exception("error");
  13. aa.a = 3;
  14. if (aa.a != 3)
  15. throw new Exception("error");
  16. if (aa.b != 2)
  17. throw new Exception("error");
  18. aa.b = 5;
  19. if (aa.b != 5)
  20. throw new Exception("error");
  21. if (aa.d != aa.b)
  22. throw new Exception("error");
  23. if (aa.c != 3)
  24. throw new Exception("error");
  25. auto pi = new Param_i(7);
  26. if (pi.value != 7)
  27. throw new Exception("error");
  28. pi.value=3;
  29. if (pi.value != 3)
  30. throw new Exception("error");
  31. auto b = new B(aa);
  32. if (b.a.c != 3)
  33. throw new Exception("error");
  34. // class/struct attribute with get/set methods using return/pass by reference
  35. auto myFoo = new MyFoo();
  36. myFoo.x = 8;
  37. auto myClass = new MyClass();
  38. myClass.Foo = myFoo;
  39. if (myClass.Foo.x != 8)
  40. throw new Exception("error");
  41. // class/struct attribute with get/set methods using return/pass by value
  42. auto myClassVal = new MyClassVal();
  43. if (myClassVal.ReadWriteFoo.x != -1)
  44. throw new Exception("error");
  45. if (myClassVal.ReadOnlyFoo.x != -1)
  46. throw new Exception("error");
  47. myClassVal.ReadWriteFoo = myFoo;
  48. if (myClassVal.ReadWriteFoo.x != 8)
  49. throw new Exception("error");
  50. if (myClassVal.ReadOnlyFoo.x != 8)
  51. throw new Exception("error");
  52. // string attribute with get/set methods using return/pass by value
  53. auto myStringClass = new MyStringyClass("initial string");
  54. if (myStringClass.ReadWriteString != "initial string")
  55. throw new Exception("error");
  56. if (myStringClass.ReadOnlyString != "initial string")
  57. throw new Exception("error");
  58. myStringClass.ReadWriteString = "changed string";
  59. if (myStringClass.ReadWriteString != "changed string")
  60. throw new Exception("error");
  61. if (myStringClass.ReadOnlyString != "changed string")
  62. throw new Exception("error");
  63. }