From 05d9b03a4093098a15fdaff3befa8b01340597c6 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 4 Oct 2020 23:08:25 +0300 Subject: unit_tests: get rid of an ugly hack --- test/unit_tests/lexer.cpp | 53 ++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 28 deletions(-) (limited to 'test') diff --git a/test/unit_tests/lexer.cpp b/test/unit_tests/lexer.cpp index 1a8a29d..9a3fc26 100644 --- a/test/unit_tests/lexer.cpp +++ b/test/unit_tests/lexer.cpp @@ -25,6 +25,17 @@ using math::server::lexer::Token; using math::server::lexer::token::Type; namespace details = math::server::lexer::details; +namespace std { + +ostream& operator<<(ostream& os, const vector& tokens) { + for (const auto& token : tokens) { + os << token; + } + return os; +} + +} // namespace std + namespace { namespace get_tokens::valid { @@ -40,40 +51,26 @@ const std::vector input{ }; // clang-format on -// Some black magic-fuckery to resolve operator<< for std::vector. -// See https://stackoverflow.com/a/18817428/514684. - -struct Expected { - std::vector m_tokens; -}; - -std::ostream& operator<<(std::ostream& os, const Expected& expected) { - for (const auto& token : expected.m_tokens) { - os << token; - } - return os; -} - -const std::vector expected{ - {{}}, - {{ +const std::vector> expected{ + {}, + { Token{Type::PLUS}, Token{Type::MINUS}, - }}, - {{ + }, + { Token{1}, Token{Type::PLUS}, Token{2}, - }}, - {{ + }, + { Token{.5}, Token{Type::CARET}, Token{Type::MINUS}, Token{1}, Token{Type::CARET}, Token{4}, - }}, - {{ + }, + { Token{1}, Token{Type::PLUS}, Token{2}, @@ -83,8 +80,8 @@ const std::vector expected{ Token{Type::MINUS}, Token{4e-2}, Token{Type::RIGHT_PAREN}, - }}, - {{ + }, + { Token{2}, Token{Type::ASTERISK}, Token{Type::LEFT_PAREN}, @@ -99,7 +96,7 @@ const std::vector expected{ Token{3}, Token{Type::RIGHT_PAREN}, Token{Type::RIGHT_PAREN}, - }}, + }, }; } // namespace get_tokens::valid @@ -158,8 +155,8 @@ BOOST_DATA_TEST_CASE(test_get_tokens_valid, expected) { Lexer lexer{input}; const auto actual = lexer.get_tokens(); - BOOST_CHECK_EQUAL_COLLECTIONS(actual.cbegin(), actual.cend(), expected.m_tokens.cbegin(), - expected.m_tokens.cend()); + BOOST_CHECK_EQUAL_COLLECTIONS(actual.cbegin(), actual.cend(), expected.cbegin(), + expected.cend()); } BOOST_DATA_TEST_CASE(test_get_tokens_invalid, -- cgit v1.2.3