aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test/unit_tests/parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit_tests/parser.cpp')
-rw-r--r--test/unit_tests/parser.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/test/unit_tests/parser.cpp b/test/unit_tests/parser.cpp
new file mode 100644
index 0000000..11f48d3
--- /dev/null
+++ b/test/unit_tests/parser.cpp
@@ -0,0 +1,48 @@
+#include <server/parser.hpp>
+
+#include <boost/test/unit_test.hpp>
+
+BOOST_AUTO_TEST_CASE(test_parser_exec) {
+ using namespace math::server;
+
+ {
+ Parser parser{""};
+ BOOST_CHECK_THROW(parser.exec(), parser::Error);
+ }
+ {
+ Parser parser{"1"};
+ BOOST_TEST(parser.exec() == 1);
+ }
+ {
+ Parser parser{" 1 + "};
+ BOOST_CHECK_THROW(parser.exec(), parser::Error);
+ }
+ {
+ Parser parser{" 1 + 2 "};
+ BOOST_TEST(parser.exec() == 3);
+ }
+ {
+ Parser parser{" 2 * 1 + 3 "};
+ BOOST_TEST(parser.exec() == 5);
+ }
+ {
+ Parser parser{" 2 * (1 + 3) "};
+ BOOST_TEST(parser.exec() == 8);
+ }
+ {
+ Parser parser{" 2 * (1 + 3 "};
+ BOOST_CHECK_THROW(parser.exec(), parser::Error);
+ }
+ {
+ Parser parser{" 2 * (1 + 3) )"};
+ BOOST_CHECK_THROW(parser.exec(), parser::Error);
+ }
+ {
+ Parser parser{" 2 * (1 + 3 * (1 - -3)) "};
+ BOOST_TEST(parser.exec() == 26);
+ }
+ {
+ Parser parser{" -2 * ---- (3 + -100e-1) "}; // Looks weird, but also works in e.g. Python
+ BOOST_TEST(parser.exec() == 14);
+ }
+}