PageRenderTime 23ms CodeModel.GetById 13ms app.highlight 8ms RepoModel.GetById 1ms 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
 1module li_attribute_runme;
 2
 3import li_attribute.A;
 4import li_attribute.B;
 5import li_attribute.MyClass;
 6import li_attribute.MyClassVal;
 7import li_attribute.MyStringyClass;
 8import li_attribute.MyFoo;
 9import li_attribute.Param_i;
10
11void main() {
12  auto aa = new A(1,2,3);
13
14  if (aa.a != 1)
15    throw new Exception("error");
16  aa.a = 3;
17  if (aa.a != 3)
18    throw new Exception("error");
19
20  if (aa.b != 2)
21    throw new Exception("error");
22  aa.b = 5;
23  if (aa.b != 5)
24    throw new Exception("error");
25
26  if (aa.d != aa.b)
27    throw new Exception("error");
28
29  if (aa.c != 3)
30    throw new Exception("error");
31
32  auto pi = new Param_i(7);
33  if (pi.value != 7)
34    throw new Exception("error");
35
36  pi.value=3;
37  if (pi.value != 3)
38    throw new Exception("error");
39
40  auto b = new B(aa);
41  if (b.a.c != 3)
42    throw new Exception("error");
43
44  // class/struct attribute with get/set methods using return/pass by reference
45  auto myFoo = new MyFoo();
46  myFoo.x = 8;
47  auto myClass = new MyClass();
48  myClass.Foo = myFoo;
49  if (myClass.Foo.x != 8)
50    throw new Exception("error");
51
52  // class/struct attribute with get/set methods using return/pass by value
53  auto myClassVal = new MyClassVal();
54  if (myClassVal.ReadWriteFoo.x != -1)
55    throw new Exception("error");
56  if (myClassVal.ReadOnlyFoo.x != -1)
57    throw new Exception("error");
58  myClassVal.ReadWriteFoo = myFoo;
59  if (myClassVal.ReadWriteFoo.x != 8)
60    throw new Exception("error");
61  if (myClassVal.ReadOnlyFoo.x != 8)
62    throw new Exception("error");
63
64  // string attribute with get/set methods using return/pass by value
65  auto myStringClass = new MyStringyClass("initial string");
66  if (myStringClass.ReadWriteString != "initial string")
67    throw new Exception("error");
68  if (myStringClass.ReadOnlyString != "initial string")
69    throw new Exception("error");
70  myStringClass.ReadWriteString = "changed string";
71  if (myStringClass.ReadWriteString != "changed string")
72    throw new Exception("error");
73  if (myStringClass.ReadOnlyString != "changed string")
74    throw new Exception("error");
75}