PageRenderTime 24ms CodeModel.GetById 1ms app.highlight 18ms RepoModel.GetById 1ms app.codeStats 0ms

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

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