PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
D | 84 lines | 70 code | 10 blank | 4 comment | 30 complexity | b78ba80d30f581c03a7d8da0a2675691 MD5 | raw file
 1module default_args_runme;
 2
 3import std.exception;
 4import default_args.default_args;
 5import default_args.ConstMethods;
 6import default_args.EnumClass;
 7import default_args.Except;
 8import default_args.Foo;
 9import default_args.Klass;
10import default_args.Statics;
11import default_args.Tricky;
12
13void main() {
14  enforce(anonymous() == 7771, "anonymous (1) failed");
15  enforce(anonymous(1234) == 1234,"anonymous (2) failed");
16  enforce(booltest() == true, "booltest (1) failed");
17  enforce(booltest(true) == true, "booltest (2) failed");
18  enforce(booltest(false) == false, "booltest (3) failed");
19  enforce((new EnumClass()).blah() == true, "EnumClass failed");
20  enforce(casts1() == null, "casts1 failed");
21  enforce(casts2() == "Hello", "casts2 failed");
22  enforce(casts1("Ciao") == "Ciao", "casts1 not default failed");
23  enforce(chartest1() == 'x', "chartest1 failed");
24  enforce(chartest2() == '\0', "chartest2 failed");
25  enforce(chartest1('y') == 'y', "chartest1 not default failed");
26  enforce(chartest1('y') == 'y', "chartest1 not default failed");
27  enforce(reftest1() == 42, "reftest1 failed");
28  enforce(reftest1(400) == 400, "reftest1 not default failed");
29  enforce(reftest2() == "hello", "reftest2 failed");
30
31  // rename
32  auto foo = new Foo();
33  foo.newname();
34  foo.newname(10);
35  foo.renamed3arg(10, 10.0);
36  foo.renamed2arg(10);
37  foo.renamed1arg();
38
39  // exception specifications
40  enforceThrows( (){ exceptionspec(); }, "exceptionspec 1" );
41  enforceThrows( (){ exceptionspec(-1); }, "exceptionspec 2" );
42  enforceThrows( (){ exceptionspec(100); }, "exceptionspec 3" );
43
44  auto ex = new Except(false);
45  enforceThrows( (){ ex.exspec(); }, "exspec 1" );
46  enforceThrows( (){ ex.exspec(-1); }, "exspec 2" );
47  enforceThrows( (){ ex.exspec(100); }, "exspec 3" );
48  enforceThrows( (){ ex = new Except(true); }, "Except constructor 1" );
49  enforceThrows( (){ ex = new Except(true, -2); }, "Except constructor 2" );
50
51  // Default parameters in static class methods
52  enforce(Statics.staticmethod() == 10+20+30, "staticmethod 1 failed");
53  enforce(Statics.staticmethod(100) == 100+20+30, "staticmethod 2 failed");
54  enforce(Statics.staticmethod(100,200,300) == 100+200+300, "staticmethod 3 failed");
55
56  auto tricky = new Tricky();
57  enforce(tricky.privatedefault() == 200, "privatedefault failed");
58  enforce(tricky.protectedint() == 2000, "protectedint failed");
59  enforce(tricky.protecteddouble() == 987.654, "protecteddouble failed");
60  enforce(tricky.functiondefault() == 500, "functiondefault failed");
61  enforce(tricky.contrived() == 'X', "contrived failed");
62
63  enforce(constructorcall().val == -1, "constructorcall test 1 failed");
64  enforce(constructorcall(new Klass(2222)).val == 2222, "constructorcall test 2 failed");
65  enforce(constructorcall(new Klass()).val == -1, "constructorcall test 3 failed");
66
67  // const methods
68  const cm = new ConstMethods();
69  enforce(cm.coo() == 20, "coo test 1 failed");
70  enforce(cm.coo(1.0) == 20, "coo test 2 failed");
71}
72
73private void enforceThrows(void delegate() dg, string errorMessage) {
74  bool hasThrown;
75  try {
76    dg();
77  } catch (Exception) {
78    hasThrown = true;
79  } finally {
80    if (!hasThrown) {
81      throw new Exception(errorMessage);
82    }
83  }
84}