1 #include "TokenTest.hpp"
5 CPPUNIT_TEST_SUITE_REGISTRATION(blank::test::TokenTest);
12 void TokenTest::setUp() {
16 void TokenTest::tearDown() {
21 void TokenTest::testTypeIO() {
22 AssertStreamOutput(Token::UNKNOWN, "UNKNOWN");
23 AssertStreamOutput(Token::ANGLE_BRACKET_OPEN, "ANGLE_BRACKET_OPEN");
24 AssertStreamOutput(Token::ANGLE_BRACKET_CLOSE, "ANGLE_BRACKET_CLOSE");
25 AssertStreamOutput(Token::CHEVRON_OPEN, "CHEVRON_OPEN");
26 AssertStreamOutput(Token::CHEVRON_CLOSE, "CHEVRON_CLOSE");
27 AssertStreamOutput(Token::BRACKET_OPEN, "BRACKET_OPEN");
28 AssertStreamOutput(Token::BRACKET_CLOSE, "BRACKET_CLOSE");
29 AssertStreamOutput(Token::PARENTHESIS_OPEN, "PARENTHESIS_OPEN");
30 AssertStreamOutput(Token::PARENTHESIS_CLOSE, "PARENTHESIS_CLOSE");
31 AssertStreamOutput(Token::COLON, "COLON");
32 AssertStreamOutput(Token::SEMICOLON, "SEMICOLON");
33 AssertStreamOutput(Token::COMMA, "COMMA");
34 AssertStreamOutput(Token::EQUALS, "EQUALS");
35 AssertStreamOutput(Token::NUMBER, "NUMBER");
36 AssertStreamOutput(Token::STRING, "STRING");
37 AssertStreamOutput(Token::IDENTIFIER, "IDENTIFIER");
38 AssertStreamOutput(Token::COMMENT, "COMMENT");
41 void TokenTest::testTokenIO() {
43 t.value = "why oh why";
44 AssertStreamOutput(t, "UNKNOWN(why oh why)");
45 t.type = Token::UNKNOWN;
46 t.value = "do I have no purpose";
47 AssertStreamOutput(t, "UNKNOWN(do I have no purpose)");
48 t.type = Token::ANGLE_BRACKET_OPEN;
49 AssertStreamOutput(t, "ANGLE_BRACKET_OPEN");
50 t.type = Token::ANGLE_BRACKET_CLOSE;
51 AssertStreamOutput(t, "ANGLE_BRACKET_CLOSE");
52 t.type = Token::CHEVRON_OPEN;
53 AssertStreamOutput(t, "CHEVRON_OPEN");
54 t.type = Token::CHEVRON_CLOSE;
55 AssertStreamOutput(t, "CHEVRON_CLOSE");
56 t.type = Token::BRACKET_OPEN;
57 AssertStreamOutput(t, "BRACKET_OPEN");
58 t.type = Token::BRACKET_CLOSE;
59 AssertStreamOutput(t, "BRACKET_CLOSE");
60 t.type = Token::PARENTHESIS_OPEN;
61 AssertStreamOutput(t, "PARENTHESIS_OPEN");
62 t.type = Token::PARENTHESIS_CLOSE;
63 AssertStreamOutput(t, "PARENTHESIS_CLOSE");
64 t.type = Token::COLON;
65 AssertStreamOutput(t, "COLON");
66 t.type = Token::SEMICOLON;
67 AssertStreamOutput(t, "SEMICOLON");
68 t.type = Token::COMMA;
69 AssertStreamOutput(t, "COMMA");
70 t.type = Token::EQUALS;
71 AssertStreamOutput(t, "EQUALS");
72 t.type = Token::NUMBER;
74 AssertStreamOutput(t, "NUMBER(15)");
75 t.type = Token::STRING;
76 t.value = "hello world";
77 AssertStreamOutput(t, "STRING(hello world)");
78 t.type = Token::IDENTIFIER;
80 AssertStreamOutput(t, "IDENTIFIER(foo)");
81 t.type = Token::COMMENT;
82 t.value = "WITHOUT ANY WARRANTY";
83 AssertStreamOutput(t, "COMMENT(WITHOUT ANY WARRANTY)");
87 void TokenTest::AssertStreamOutput(
93 CPPUNIT_ASSERT_EQUAL_MESSAGE(
94 "unexpected std::ostream << Token::Type result",
95 expected, conv.str());
98 void TokenTest::AssertStreamOutput(
104 CPPUNIT_ASSERT_EQUAL_MESSAGE(
105 "unexpected std::ostream << Token result",
106 expected, conv.str());