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