2019-01-26 17:35:16 +08:00
|
|
|
|
#include "tkc/expr_eval.h"
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
|
|
TEST(ExprEval, basic) {
|
2019-06-02 07:53:24 +08:00
|
|
|
|
ASSERT_EQ(0, tk_expr_eval("10%2"));
|
|
|
|
|
ASSERT_EQ(1, tk_expr_eval("11%2"));
|
|
|
|
|
ASSERT_EQ(1, tk_expr_eval("11%10"));
|
2019-05-29 11:13:59 +08:00
|
|
|
|
ASSERT_EQ(0, tk_expr_eval("(2-2) && 3 + 2 * 2"));
|
|
|
|
|
ASSERT_EQ(0, tk_expr_eval("(2-2) && (3 + 2 * 2)"));
|
|
|
|
|
ASSERT_EQ(1, tk_expr_eval("(2-2) || 3 + 2 * 2"));
|
|
|
|
|
ASSERT_EQ(1, tk_expr_eval("(2-2) || (3 + 2 * 2)"));
|
|
|
|
|
ASSERT_EQ(0, tk_expr_eval("2-2 && 3 + 2 * 2"));
|
|
|
|
|
ASSERT_EQ(0, tk_expr_eval("2-2 && (3 + 2 * 2)"));
|
|
|
|
|
ASSERT_EQ(1, tk_expr_eval("2-2 || 3 + 2 * 2"));
|
|
|
|
|
ASSERT_EQ(1, tk_expr_eval("2-2 || (3 + 2 * 2)"));
|
|
|
|
|
ASSERT_EQ(1, tk_expr_eval("2*3 && 3 + 2 * 2"));
|
|
|
|
|
ASSERT_EQ(1, tk_expr_eval("2*3 && (3 + 2 * 2)"));
|
|
|
|
|
ASSERT_EQ(1, tk_expr_eval("2*3 || 3 + 2 * 2"));
|
|
|
|
|
ASSERT_EQ(1, tk_expr_eval("2*3 || (3 + 2 * 2)"));
|
|
|
|
|
ASSERT_EQ(0, tk_expr_eval("2*3 > 3 + 2 * 2"));
|
|
|
|
|
ASSERT_EQ(0, tk_expr_eval("2-3 > 3 + 2 * 2"));
|
2019-01-26 17:35:16 +08:00
|
|
|
|
ASSERT_EQ(1, tk_expr_eval("1"));
|
|
|
|
|
ASSERT_EQ(2, tk_expr_eval("1 + 1"));
|
|
|
|
|
ASSERT_EQ(2, tk_expr_eval("1 * 2"));
|
|
|
|
|
ASSERT_EQ(2, tk_expr_eval("4/2"));
|
|
|
|
|
ASSERT_EQ(4, tk_expr_eval("(1+1)*2"));
|
2019-02-04 07:58:13 +08:00
|
|
|
|
ASSERT_EQ(1, tk_expr_eval("\"aa\"==\"aa\""));
|
|
|
|
|
ASSERT_EQ(0, tk_expr_eval("\"aa\"==\"bb\""));
|
2019-01-26 17:35:16 +08:00
|
|
|
|
}
|
2019-06-02 07:53:24 +08:00
|
|
|
|
|
|
|
|
|
TEST(ExprEval, func) {
|
|
|
|
|
ASSERT_EQ(11, tk_expr_eval("if(1, 11, 22)"));
|
|
|
|
|
ASSERT_EQ(22, tk_expr_eval("if(0, 11, 22)"));
|
|
|
|
|
ASSERT_EQ(11, tk_expr_eval("if(1, \"11\", \"22\")"));
|
|
|
|
|
ASSERT_EQ(22, tk_expr_eval("if(0, \"11\", \"22\")"));
|
|
|
|
|
}
|