1 | #include "catch.hpp" |
2 | #include "duckdb/common/helper.hpp" |
3 | #include "expression_helper.hpp" |
4 | #include "duckdb/optimizer/rule/constant_folding.hpp" |
5 | |
6 | using namespace duckdb; |
7 | using namespace std; |
8 | |
9 | TEST_CASE("Constant folding test" , "[optimizer]" ) { |
10 | ExpressionHelper helper; |
11 | helper.AddRule<ConstantFoldingRule>(); |
12 | |
13 | string input, expected_output; |
14 | |
15 | input = "1+1" ; |
16 | expected_output = "2" ; |
17 | REQUIRE(helper.VerifyRewrite(input, expected_output)); |
18 | |
19 | input = "(1+1+1)*2" ; |
20 | expected_output = "6" ; |
21 | REQUIRE(helper.VerifyRewrite(input, expected_output)); |
22 | |
23 | input = "CASE WHEN 1 IN (1, 2, 3, 4) THEN 3 ELSE 5 END" ; |
24 | expected_output = "3" ; |
25 | REQUIRE(helper.VerifyRewrite(input, expected_output)); |
26 | |
27 | input = "CASE WHEN 1 IN (1+1, 2, 3, 4) THEN 3 ELSE 5 END" ; |
28 | expected_output = "5" ; |
29 | REQUIRE(helper.VerifyRewrite(input, expected_output)); |
30 | |
31 | input = "1 IN (1+1, 2, 3, 4, NULL)" ; |
32 | expected_output = "NULL" ; |
33 | REQUIRE(helper.VerifyRewrite(input, expected_output)); |
34 | |
35 | input = "CASE WHEN 1 IN (1+1, 2, 3, 4, NULL, 1) THEN (3+4) ELSE 2+2+2 END" ; |
36 | expected_output = "7" ; |
37 | REQUIRE(helper.VerifyRewrite(input, expected_output)); |
38 | } |
39 | |