Differences From Artifact [aa60c34591041ca2]:
- File
polemy/tricks.d
- 2010-11-08 08:01:27 - part of checkin [b0d8d7875b] on branch trunk - polemy.runtime renamed into polemy.value. Also, in process of changes to use unittest helpers. (user: kinaba) [annotate]
To Artifact [e911a30d1f923777]:
- File
polemy/tricks.d
- 2010-11-08 11:42:14 - part of checkin [5e407d7cf8] on branch trunk - Lexer Refactored so that it can accpet multi-symbol token (user: kinaba) [annotate]
16 16 auto writer = appender!string();
17 17 formattedWrite(writer, fmt, params);
18 18 return writer.data;
19 19 }
20 20
21 21 unittest
22 22 {
23 - assert( sprintf!"%s == %d"("1+2", 3) == "1+2 == 3" );
23 + assert( sprintf!"%s == %d"("1+2", 3) == "1+2 == 3" );
24 24 assert( sprintf!"%s == %04d"("1+2", 3) == "1+2 == 0003" );
25 25 }
26 26
27 27 /// Unittest helper that asserts an expression must throw something
28 28
29 29 void assert_throw(ExceptionType, T, string fn=__FILE__, int ln=__LINE__)(lazy T t, string msg="")
30 30 {
................................................................................
85 85 alias assertOp!(`<`) assert_lt;
86 86 alias assertOp!(`<=`) assert_le;
87 87 alias assertOp!(`>`) assert_gt;
88 88 alias assertOp!(`>=`) assert_ge;
89 89
90 90 unittest
91 91 {
92 - assert_nothrow( assert_eq("foo", "foo") );
93 - assert_nothrow( assert_ne("foo", "bar") );
94 - assert_nothrow( assert_lt("bar", "foo") );
95 - assert_nothrow( assert_le("bar", "foo") );
96 - assert_nothrow( assert_le("bar", "bar") );
97 - assert_nothrow( assert_gt("foo", "bar") );
98 - assert_nothrow( assert_ge("foo", "bar") );
99 - assert_nothrow( assert_ge("bar", "bar") );
92 + assert_nothrow( assert_eq(1, 1) );
93 + assert_nothrow( assert_ne(1, 0) );
94 + assert_nothrow( assert_lt(0, 1) );
95 + assert_nothrow( assert_le(0, 1) );
96 + assert_nothrow( assert_le(0, 0) );
97 + assert_nothrow( assert_gt(1, 0) );
98 + assert_nothrow( assert_ge(1, 0) );
99 + assert_nothrow( assert_ge(0, 0) );
100 100
101 - assert_throw!AssertError( assert_eq("foo", "bar") );
102 - assert_throw!AssertError( assert_ne("foo", "foo") );
103 - assert_throw!AssertError( assert_lt("foo", "foo") );
104 - assert_throw!AssertError( assert_lt("foo", "bar") );
105 - assert_throw!AssertError( assert_le("foo", "bar") );
106 - assert_throw!AssertError( assert_gt("bar", "bar") );
107 - assert_throw!AssertError( assert_gt("bar", "foo") );
108 - assert_throw!AssertError( assert_ge("bar", "foo") );
101 + assert_throw!AssertError( assert_eq(1, 0) );
102 + assert_throw!AssertError( assert_ne(1, 1) );
103 + assert_throw!AssertError( assert_lt(1, 1) );
104 + assert_throw!AssertError( assert_lt(1, 0) );
105 + assert_throw!AssertError( assert_le(1, 0) );
106 + assert_throw!AssertError( assert_gt(0, 0) );
107 + assert_throw!AssertError( assert_gt(0, 1) );
108 + assert_throw!AssertError( assert_ge(0, 1) );
109 109
110 110 class Temp { bool opEquals(int x){return x/x==x;} }
111 111 assert_throw!AssertError( assert_eq(new Temp, 0) );
112 112 assert_nothrow ( assert_eq(new Temp, 1) );
113 113 assert_throw!AssertError( assert_eq(new Temp, 2) );
114 114 }
115 115