aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2020-10-04 22:26:13 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2020-10-04 22:26:13 +0300
commit53a6076d05e264d6bed743032a63fd782e7caae9 (patch)
tree19da5e09fa387fdc2df4ffefd76c93410a3c7f44 /test
parentTravis: lint the config (diff)
downloadmath-server-53a6076d05e264d6bed743032a63fd782e7caae9.tar.gz
math-server-53a6076d05e264d6bed743032a63fd782e7caae9.zip
unit_tests: reorder code a little
Diffstat (limited to 'test')
-rw-r--r--test/unit_tests/lexer.cpp66
-rw-r--r--test/unit_tests/parser.cpp4
2 files changed, 35 insertions, 35 deletions
diff --git a/test/unit_tests/lexer.cpp b/test/unit_tests/lexer.cpp
index c43b879..1a8a29d 100644
--- a/test/unit_tests/lexer.cpp
+++ b/test/unit_tests/lexer.cpp
@@ -18,8 +18,6 @@
#include <string_view>
#include <vector>
-BOOST_AUTO_TEST_SUITE(lexer_tests)
-
namespace bdata = boost::unit_test::data;
using math::server::Lexer;
using math::server::LexerError;
@@ -27,37 +25,6 @@ using math::server::lexer::Token;
using math::server::lexer::token::Type;
namespace details = math::server::lexer::details;
-BOOST_AUTO_TEST_CASE(test_parse_number) {
- // These are valid numbers:
- BOOST_TEST(details::parse_number("0").value() == 0);
- BOOST_TEST(details::parse_number("1.").value() == 1.);
- BOOST_TEST(details::parse_number(".1").value() == .1);
- // parse_* functions only consume a single token:
- BOOST_TEST(details::parse_number(".1+1").value() == .1);
- BOOST_TEST(details::parse_number("1e3").value() == 1e3);
- BOOST_TEST(details::parse_number(".123e1").value() == .123e1);
- BOOST_TEST(details::parse_number("123e-1").value() == 123e-1);
- BOOST_TEST(details::parse_number("123e+1").value() == 123e+1);
- BOOST_TEST(details::parse_number("1.e6").value() == 1.e6);
- BOOST_TEST(details::parse_number("2.3e-4").value() == 2.3e-4);
- // These are not numbers, but perhaps something else?
- BOOST_TEST(!details::parse_number(".").has_value());
- BOOST_TEST(!details::parse_number(".e3").has_value());
- BOOST_TEST(!details::parse_number("e12").has_value());
- // This is definitely a number, but a malformed one (an exponent must be
- // followed by some digits).
- BOOST_CHECK_THROW(details::parse_number("12e"), LexerError);
-}
-
-BOOST_AUTO_TEST_CASE(test_parse_const_token) {
- BOOST_TEST(details::parse_const_token("+").value() == Type::PLUS);
- // parse_* functions only consume a single token:
- BOOST_TEST(details::parse_const_token("+/*").value() == Type::PLUS);
- BOOST_TEST(details::parse_const_token("-").value() == Type::MINUS);
- BOOST_TEST(details::parse_const_token("^^").value() == Type::CARET);
- BOOST_TEST(!details::parse_const_token("&+").has_value());
-}
-
namespace {
namespace get_tokens::valid {
@@ -152,6 +119,39 @@ const std::vector<std::string> error_msg{
} // namespace get_tokens::invalid
} // namespace
+BOOST_AUTO_TEST_SUITE(lexer_tests)
+
+BOOST_AUTO_TEST_CASE(test_parse_number) {
+ // These are valid numbers:
+ BOOST_TEST(details::parse_number("0").value() == 0);
+ BOOST_TEST(details::parse_number("1.").value() == 1.);
+ BOOST_TEST(details::parse_number(".1").value() == .1);
+ // parse_* functions only consume a single token:
+ BOOST_TEST(details::parse_number(".1+1").value() == .1);
+ BOOST_TEST(details::parse_number("1e3").value() == 1e3);
+ BOOST_TEST(details::parse_number(".123e1").value() == .123e1);
+ BOOST_TEST(details::parse_number("123e-1").value() == 123e-1);
+ BOOST_TEST(details::parse_number("123e+1").value() == 123e+1);
+ BOOST_TEST(details::parse_number("1.e6").value() == 1.e6);
+ BOOST_TEST(details::parse_number("2.3e-4").value() == 2.3e-4);
+ // These are not numbers, but perhaps something else?
+ BOOST_TEST(!details::parse_number(".").has_value());
+ BOOST_TEST(!details::parse_number(".e3").has_value());
+ BOOST_TEST(!details::parse_number("e12").has_value());
+ // This is definitely a number, but a malformed one (an exponent must be
+ // followed by some digits).
+ BOOST_CHECK_THROW(details::parse_number("12e"), LexerError);
+}
+
+BOOST_AUTO_TEST_CASE(test_parse_const_token) {
+ BOOST_TEST(details::parse_const_token("+").value() == Type::PLUS);
+ // parse_* functions only consume a single token:
+ BOOST_TEST(details::parse_const_token("+/*").value() == Type::PLUS);
+ BOOST_TEST(details::parse_const_token("-").value() == Type::MINUS);
+ BOOST_TEST(details::parse_const_token("^^").value() == Type::CARET);
+ BOOST_TEST(!details::parse_const_token("&+").has_value());
+}
+
BOOST_DATA_TEST_CASE(test_get_tokens_valid,
bdata::make(get_tokens::valid::input) ^ get_tokens::valid::expected,
input,
diff --git a/test/unit_tests/parser.cpp b/test/unit_tests/parser.cpp
index 2e90992..655ba39 100644
--- a/test/unit_tests/parser.cpp
+++ b/test/unit_tests/parser.cpp
@@ -14,8 +14,6 @@
#include <string_view>
#include <vector>
-BOOST_AUTO_TEST_SUITE(parser_tests)
-
namespace bdata = boost::unit_test::data;
using math::server::Parser;
using math::server::ParserError;
@@ -114,6 +112,8 @@ const std::vector<std::string> error_msg{
} // namespace exec::invalid
} // namespace
+BOOST_AUTO_TEST_SUITE(parser_tests)
+
BOOST_DATA_TEST_CASE(test_exec_valid,
bdata::make(exec::valid::input) ^ exec::valid::expected,
input,