From: Daniel Karbach Date: Thu, 10 Nov 2016 15:11:18 +0000 (+0100) Subject: test for Token X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=7d462272350926dca8e1a8c94fdb527d0c9f6dc1;p=blank.git test for Token --- diff --git a/tst/io/TokenTest.cpp b/tst/io/TokenTest.cpp new file mode 100644 index 0000000..52fcfcd --- /dev/null +++ b/tst/io/TokenTest.cpp @@ -0,0 +1,110 @@ +#include "TokenTest.hpp" + +#include + +CPPUNIT_TEST_SUITE_REGISTRATION(blank::test::TokenTest); + +using namespace std; + +namespace blank { +namespace test { + +void TokenTest::setUp() { + +} + +void TokenTest::tearDown() { + +} + + +void TokenTest::testTypeIO() { + AssertStreamOutput(Token::UNKNOWN, "UNKNOWN"); + AssertStreamOutput(Token::ANGLE_BRACKET_OPEN, "ANGLE_BRACKET_OPEN"); + AssertStreamOutput(Token::ANGLE_BRACKET_CLOSE, "ANGLE_BRACKET_CLOSE"); + AssertStreamOutput(Token::CHEVRON_OPEN, "CHEVRON_OPEN"); + AssertStreamOutput(Token::CHEVRON_CLOSE, "CHEVRON_CLOSE"); + AssertStreamOutput(Token::BRACKET_OPEN, "BRACKET_OPEN"); + AssertStreamOutput(Token::BRACKET_CLOSE, "BRACKET_CLOSE"); + AssertStreamOutput(Token::PARENTHESIS_OPEN, "PARENTHESIS_OPEN"); + AssertStreamOutput(Token::PARENTHESIS_CLOSE, "PARENTHESIS_CLOSE"); + AssertStreamOutput(Token::COLON, "COLON"); + AssertStreamOutput(Token::SEMICOLON, "SEMICOLON"); + AssertStreamOutput(Token::COMMA, "COMMA"); + AssertStreamOutput(Token::EQUALS, "EQUALS"); + AssertStreamOutput(Token::NUMBER, "NUMBER"); + AssertStreamOutput(Token::STRING, "STRING"); + AssertStreamOutput(Token::IDENTIFIER, "IDENTIFIER"); + AssertStreamOutput(Token::COMMENT, "COMMENT"); +} + +void TokenTest::testTokenIO() { + Token t; + t.value = "why oh why"; + AssertStreamOutput(t, "UNKNOWN(why oh why)"); + t.type = Token::UNKNOWN; + t.value = "do I have no purpose"; + AssertStreamOutput(t, "UNKNOWN(do I have no purpose)"); + t.type = Token::ANGLE_BRACKET_OPEN; + AssertStreamOutput(t, "ANGLE_BRACKET_OPEN"); + t.type = Token::ANGLE_BRACKET_CLOSE; + AssertStreamOutput(t, "ANGLE_BRACKET_CLOSE"); + t.type = Token::CHEVRON_OPEN; + AssertStreamOutput(t, "CHEVRON_OPEN"); + t.type = Token::CHEVRON_CLOSE; + AssertStreamOutput(t, "CHEVRON_CLOSE"); + t.type = Token::BRACKET_OPEN; + AssertStreamOutput(t, "BRACKET_OPEN"); + t.type = Token::BRACKET_CLOSE; + AssertStreamOutput(t, "BRACKET_CLOSE"); + t.type = Token::PARENTHESIS_OPEN; + AssertStreamOutput(t, "PARENTHESIS_OPEN"); + t.type = Token::PARENTHESIS_CLOSE; + AssertStreamOutput(t, "PARENTHESIS_CLOSE"); + t.type = Token::COLON; + AssertStreamOutput(t, "COLON"); + t.type = Token::SEMICOLON; + AssertStreamOutput(t, "SEMICOLON"); + t.type = Token::COMMA; + AssertStreamOutput(t, "COMMA"); + t.type = Token::EQUALS; + AssertStreamOutput(t, "EQUALS"); + t.type = Token::NUMBER; + t.value = "15"; + AssertStreamOutput(t, "NUMBER(15)"); + t.type = Token::STRING; + t.value = "hello world"; + AssertStreamOutput(t, "STRING(hello world)"); + t.type = Token::IDENTIFIER; + t.value = "foo"; + AssertStreamOutput(t, "IDENTIFIER(foo)"); + t.type = Token::COMMENT; + t.value = "WITHOUT ANY WARRANTY"; + AssertStreamOutput(t, "COMMENT(WITHOUT ANY WARRANTY)"); +} + + +void TokenTest::AssertStreamOutput( + Token::Type t, + string expected +) { + stringstream conv; + conv << t; + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "unexpected std::ostream << Token::Type result", + expected, conv.str()); +} + +void TokenTest::AssertStreamOutput( + const Token &t, + string expected +) { + stringstream conv; + conv << t; + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "unexpected std::ostream << Token result", + expected, conv.str()); +} + +} +} diff --git a/tst/io/TokenTest.hpp b/tst/io/TokenTest.hpp new file mode 100644 index 0000000..0b78952 --- /dev/null +++ b/tst/io/TokenTest.hpp @@ -0,0 +1,41 @@ +#ifndef BLANK_TEST_IO_TOKENTEST_HPP +#define BLANK_TEST_IO_TOKENTEST_HPP + +#include "io/Token.hpp" + +#include +#include + + +namespace blank { + +namespace test { + +class TokenTest +: public CppUnit::TestFixture { + +CPPUNIT_TEST_SUITE(TokenTest); + +CPPUNIT_TEST(testTypeIO); +CPPUNIT_TEST(testTokenIO); + +CPPUNIT_TEST_SUITE_END(); + +public: + void setUp(); + void tearDown(); + + void testTypeIO(); + void testTokenIO(); + + static void AssertStreamOutput( + Token::Type, std::string expected); + static void AssertStreamOutput( + const Token &, std::string expected); + +}; + +} +} + +#endif