]> git.localhorst.tv Git - blank.git/blob - tst/io/TokenTest.cpp
test for Token
[blank.git] / tst / io / TokenTest.cpp
1 #include "TokenTest.hpp"
2
3 #include <sstream>
4
5 CPPUNIT_TEST_SUITE_REGISTRATION(blank::test::TokenTest);
6
7 using namespace std;
8
9 namespace blank {
10 namespace test {
11
12 void TokenTest::setUp() {
13
14 }
15
16 void TokenTest::tearDown() {
17
18 }
19
20
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");
39 }
40
41 void TokenTest::testTokenIO() {
42         Token t;
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;
73         t.value = "15";
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;
79         t.value = "foo";
80         AssertStreamOutput(t, "IDENTIFIER(foo)");
81         t.type = Token::COMMENT;
82         t.value = "WITHOUT ANY WARRANTY";
83         AssertStreamOutput(t, "COMMENT(WITHOUT ANY WARRANTY)");
84 }
85
86
87 void TokenTest::AssertStreamOutput(
88         Token::Type t,
89         string expected
90 ) {
91         stringstream conv;
92         conv << t;
93         CPPUNIT_ASSERT_EQUAL_MESSAGE(
94                 "unexpected std::ostream << Token::Type result",
95                 expected, conv.str());
96 }
97
98 void TokenTest::AssertStreamOutput(
99         const Token &t,
100         string expected
101 ) {
102         stringstream conv;
103         conv << t;
104         CPPUNIT_ASSERT_EQUAL_MESSAGE(
105                 "unexpected std::ostream << Token result",
106                 expected, conv.str());
107 }
108
109 }
110 }