| 1 | #include "duckdb/common/helper.hpp" | 
|---|---|
| 2 | #include "expression_helper.hpp" | 
| 3 | #include "duckdb/optimizer/rule/case_simplification.hpp" | 
| 4 | |
| 5 | using namespace duckdb; | 
| 6 | using namespace std; | 
| 7 | |
| 8 | TEST_CASE( "Test case simplification", "[optimizer]") { | 
| 9 | ExpressionHelper helper; | 
| 10 | |
| 11 | REQUIRE(helper.AddColumns( "X INTEGER").empty()); | 
| 12 | |
| 13 | helper.AddRule<CaseSimplificationRule>(); | 
| 14 | |
| 15 | string input, expected_output; | 
| 16 | |
| 17 | input = "CASE WHEN 1=1 THEN X+1 ELSE X+2 END"; | 
| 18 | expected_output = "X+1"; | 
| 19 | REQUIRE(helper.VerifyRewrite(input, expected_output)); | 
| 20 | |
| 21 | input = "CASE WHEN 1=0 THEN X+1 ELSE X+2 END"; | 
| 22 | expected_output = "X+2"; | 
| 23 | REQUIRE(helper.VerifyRewrite(input, expected_output)); | 
| 24 | |
| 25 | input = "CASE WHEN NULL>3 THEN X+1 ELSE X+2 END"; | 
| 26 | expected_output = "X+2"; | 
| 27 | REQUIRE(helper.VerifyRewrite(input, expected_output)); | 
| 28 | } | 
| 29 | 
