PageRenderTime 49ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Examples/test-suite/d/nspace_runme.2.d

#
D | 77 lines | 54 code | 12 blank | 11 comment | 11 complexity | 83f1392fcba013c6be7cb56d26a32d5d MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. module nspace_runme;
  2. import std.exception;
  3. import nspace.nspace;
  4. static import nspace.NoNSpacePlease;
  5. static import nspace.Outer.namespce;
  6. static import nspace.Outer.Inner1.Channel;
  7. static import oi1c = nspace.Outer.Inner1.Color;
  8. static import nspace.Outer.Inner2.Channel;
  9. static import nspace.Outer.Inner2.Color;
  10. static import nspace.Outer.Inner3.Blue;
  11. static import nspace.Outer.Inner4.Blue;
  12. static import nspace.Outer.SomeClass;
  13. void main() {
  14. // constructors and destructors
  15. auto color1 = new oi1c.Color();
  16. auto color = new oi1c.Color(color1);
  17. // class methods
  18. color.colorInstanceMethod(20.0);
  19. oi1c.Color.colorStaticMethod(20.0);
  20. auto created = oi1c.Color.create();
  21. // class enums
  22. auto someClass = new nspace.Outer.SomeClass.SomeClass();
  23. auto channel = someClass.GetInner1ColorChannel();
  24. enforce(channel == oi1c.Color.Channel.Transmission,
  25. "Transmission wrong");
  26. // class anonymous enums
  27. int val1 = oi1c.Color.ColorEnumVal1;
  28. int val2 = oi1c.Color.ColorEnumVal2;
  29. enforce(val1 == 0 && val2 == 0x22, "ColorEnumVal wrong");
  30. // instance member variables
  31. color.instanceMemberVariable = 123;
  32. enforce(color.instanceMemberVariable == 123,
  33. "instance member variable failed");
  34. // static member variables
  35. oi1c.Color.staticMemberVariable = 789;
  36. enforce(oi1c.Color.staticMemberVariable == 789,
  37. "static member variable failed");
  38. enforce(oi1c.Color.staticConstMemberVariable == 222,
  39. "static const member variable failed");
  40. enforce(oi1c.Color.staticConstEnumMemberVariable == oi1c.Color.Channel.Transmission,
  41. "static const enum member variable failed");
  42. // check globals in a namespace don't get mangled with the nspace option
  43. nspace.nspace.namespaceFunction(color);
  44. nspace.nspace.namespaceVar = 111;
  45. enforce(nspace.nspace.namespaceVar == 111, "global var failed");
  46. // Same class different namespaces
  47. auto col1 = new oi1c.Color();
  48. auto col2 = nspace.Outer.Inner2.Color.Color.create();
  49. col2.colors(col1, col1, col2, col2, col2);
  50. // global enums
  51. auto outerChannel1 = someClass.GetInner1Channel();
  52. enforce(outerChannel1 == nspace.Outer.Inner1.Channel.Channel.Transmission1,
  53. "Transmission1 wrong");
  54. auto outerChannel2 = someClass.GetInner2Channel();
  55. enforce(outerChannel2 == nspace.Outer.Inner2.Channel.Channel.Transmission2,
  56. "Transmission2 wrong");
  57. // turn feature off / ignoring
  58. auto ns = new nspace.Outer.namespce.namespce();
  59. auto nons = new nspace.NoNSpacePlease.NoNSpacePlease();
  60. // Derived class
  61. auto blue3 = new nspace.Outer.Inner3.Blue.Blue();
  62. blue3.blueInstanceMethod();
  63. auto blue4 = new nspace.Outer.Inner4.Blue.Blue();
  64. blue4.blueInstanceMethod();
  65. }