Differences From Artifact [e43d60d2bdfc662b]:
- File
polemy/lex.d
- 2010-11-07 15:03:38 - part of checkin [820e7198cc] on branch trunk - Made helloworld work. (user: kinaba) [annotate]
To Artifact [783ee3b0fe58558e]:
- File
polemy/lex.d
- 2010-11-08 06:19:57 - part of checkin [61998c472a] on branch trunk - Introduced unittest helpers (assert_eq, assert_throw, etc). Mmigration to it is not done yet. (user: kinaba) [annotate]
27 } 27 }
28 28
29 unittest 29 unittest
30 { 30 {
31 auto p = new LexPosition("hello.cpp", 123, 45); 31 auto p = new LexPosition("hello.cpp", 123, 45);
32 auto q = new LexPosition("hello.cpp", 123, 46); 32 auto q = new LexPosition("hello.cpp", 123, 46);
33 33
34 assert( p.filename == "hello.cpp" ); | 34 assert_eq( p.filename, "hello.cpp" );
35 assert( p.lineno == 123 ); | 35 assert_eq( p.lineno, 123 );
36 assert( p.column == 45 ); | 36 assert_eq( p.column, 45 );
37 assert( to!string(p) == "hello.cpp:123:45" ); | 37 assert_eq( to!string(p), "hello.cpp:123:45" );
38 assert( p < q ); | 38 assert_lt( p, q );
39 assert( p != q ); | 39 assert_ne( p, q );
40 40
41 assert( !__traits(compiles, new LexPosition) ); 41 assert( !__traits(compiles, new LexPosition) );
42 assert( !__traits(compiles, p.filename="foo") ); 42 assert( !__traits(compiles, p.filename="foo") );
43 assert( !__traits(compiles, p.lineno =789) ); 43 assert( !__traits(compiles, p.lineno =789) );
44 assert( !__traits(compiles, p.column =222) ); 44 assert( !__traits(compiles, p.column =222) );
45 } 45 }
46 46
................................................................................................................................................................................
63 } 63 }
64 64
65 unittest 65 unittest
66 { 66 {
67 auto p = new immutable(LexPosition)("hello.cpp", 123, 45); 67 auto p = new immutable(LexPosition)("hello.cpp", 123, 45);
68 auto t = new Token(p, "class", Token.Kind.identifier); 68 auto t = new Token(p, "class", Token.Kind.identifier);
69 69
70 assert( t.pos == p ); | 70 assert_eq( t.pos, p );
71 assert( t.str == "class" ); | 71 assert_eq( t.str, "class" );
72 assert( t == new Token(p, "class", Token.Kind.identifier) ); | 72 assert_eq( t, new Token(p, "class", Token.Kind.identifier) );
73 assert( t < new Token(p, "struct", Token.Kind.identifier) ); | 73 assert_lt( t, new Token(p, "struct", Token.Kind.identifier) );
74 74
75 assert( !__traits(compiles, new Token) ); 75 assert( !__traits(compiles, new Token) );
76 assert( !__traits(compiles, t.pos=p) ); 76 assert( !__traits(compiles, t.pos=p) );
77 assert( !__traits(compiles, t.str=789) ); 77 assert( !__traits(compiles, t.str=789) );
78 } 78 }
79 79
80 /// Named Construtor for Lexer 80 /// Named Construtor for Lexer