aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test/unit_tests/lexer.cpp
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2019-12-30 13:06:13 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2019-12-31 19:43:25 +0300
commit372064af20a456989c2a9ea2fda6e535d74dbafd (patch)
tree9cc9039586252bda5ef44a68db9f53627a87ce4b /test/unit_tests/lexer.cpp
parentadd .dockerignore (diff)
downloadmath-server-372064af20a456989c2a9ea2fda6e535d74dbafd.tar.gz
math-server-372064af20a456989c2a9ea2fda6e535d74dbafd.zip
support the power (^) operator
It doesn't work with the unary minus currently (as is reflected in the tests), it should have a higher precedence.
Diffstat (limited to 'test/unit_tests/lexer.cpp')
-rw-r--r--test/unit_tests/lexer.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/test/unit_tests/lexer.cpp b/test/unit_tests/lexer.cpp
index aa4011c..0f65979 100644
--- a/test/unit_tests/lexer.cpp
+++ b/test/unit_tests/lexer.cpp
@@ -53,6 +53,7 @@ BOOST_AUTO_TEST_CASE(test_parse_const_token) {
// 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());
}
@@ -63,6 +64,7 @@ const std::vector<std::string_view> input{
"",
" + - ",
"1+2",
+ ".5^-1 ^ 4",
"1+2 * (3- 4e-2)",
" 2 * (1 + 3 * (1 - -3)) ",
};
@@ -93,6 +95,14 @@ const std::vector<Expected> expected{
Token{2},
}},
{{
+ Token{.5},
+ Token{Type::CARET},
+ Token{Type::MINUS},
+ Token{1},
+ Token{Type::CARET},
+ Token{4},
+ }},
+ {{
Token{1},
Token{Type::PLUS},
Token{2},