-
Notifications
You must be signed in to change notification settings - Fork 397
Expand file tree
/
Copy pathMySQLCaseOperatorTest.java
More file actions
67 lines (53 loc) · 3.28 KB
/
MySQLCaseOperatorTest.java
File metadata and controls
67 lines (53 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package sqlancer.mysql.ast;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
import org.junit.jupiter.api.Test;
import sqlancer.mysql.MySQLSchema;
import sqlancer.mysql.ast.MySQLConstant.MySQLIntConstant;
public class MySQLCaseOperatorTest {
@Test
void getExpectedValue_switchConditionMatchesWhen_ReturnsThen() {
MySQLSchema.MySQLColumn aCol = new MySQLSchema.MySQLColumn("a", MySQLSchema.MySQLDataType.INT, false, 0);
MySQLColumnReference switchExpr = new MySQLColumnReference(aCol, MySQLIntConstant.createIntConstant(1));
List<MySQLExpression> whenExprs = List.of(MySQLIntConstant.createIntConstant(1),
MySQLIntConstant.createIntConstant(2));
List<MySQLExpression> thenExprs = List.of(MySQLIntConstant.createIntConstant(11),
MySQLIntConstant.createIntConstant(22));
MySQLConstant elseExpr = MySQLConstant.createIntConstant(0);
MySQLCaseOperator caseOperator = new MySQLCaseOperator(switchExpr, whenExprs, thenExprs, elseExpr);
assertEquals(11, caseOperator.getExpectedValue().getInt());
}
@Test
void getExpectedValue_switchConditionHasNoMatches_ReturnsElse() {
MySQLSchema.MySQLColumn aCol = new MySQLSchema.MySQLColumn("a", MySQLSchema.MySQLDataType.INT, false, 0);
MySQLColumnReference switchExpr = new MySQLColumnReference(aCol, MySQLIntConstant.createNullConstant());
List<MySQLExpression> whenExprs = List.of(MySQLIntConstant.createIntConstant(1),
MySQLIntConstant.createIntConstant(2));
List<MySQLExpression> thenExprs = List.of(MySQLIntConstant.createIntConstant(11),
MySQLIntConstant.createIntConstant(22));
MySQLConstant elseExpr = MySQLConstant.createIntConstant(0);
assertEquals(0, new MySQLCaseOperator(switchExpr, whenExprs, thenExprs, elseExpr).getExpectedValue().getInt());
assertTrue(new MySQLCaseOperator(switchExpr, whenExprs, thenExprs, null).getExpectedValue().isNull());
}
@Test
void getExpectedValue_whenTrue_ReturnsThen() {
List<MySQLExpression> whenExprs = List.of(MySQLIntConstant.createIntConstant(1),
MySQLIntConstant.createIntConstant(2));
List<MySQLExpression> thenExprs = List.of(MySQLIntConstant.createIntConstant(11),
MySQLIntConstant.createIntConstant(22));
MySQLConstant elseExpr = MySQLConstant.createIntConstant(0);
MySQLCaseOperator caseOperator = new MySQLCaseOperator(null, whenExprs, thenExprs, elseExpr);
assertEquals(11, caseOperator.getExpectedValue().getInt());
}
@Test
void getExpectedValue_whenAllFalse_ReturnsElse() {
List<MySQLExpression> whenExprs = List.of(MySQLIntConstant.createBoolean(false),
MySQLIntConstant.createBoolean(false));
List<MySQLExpression> thenExprs = List.of(MySQLIntConstant.createIntConstant(11),
MySQLIntConstant.createIntConstant(22));
MySQLConstant elseExpr = MySQLConstant.createIntConstant(0);
assertEquals(0, new MySQLCaseOperator(null, whenExprs, thenExprs, elseExpr).getExpectedValue().getInt());
assertTrue(new MySQLCaseOperator(null, whenExprs, thenExprs, null).getExpectedValue().isNull());
}
}