Skip to content

Commit e68539d

Browse files
nish-dmrigger
authored andcommitted
Adds Binary Comparsion and Binary arithmetic expressions
1 parent 58508fe commit e68539d

1 file changed

Lines changed: 55 additions & 3 deletions

File tree

src/sqlancer/hsqldb/gen/HSQLDBExpressionGenerator.java

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public final class HSQLDBExpressionGenerator extends
2020
TypedExpressionGenerator<Node<HSQLDBExpression>, HSQLDBSchema.HSQLDBColumn, HSQLDBSchema.HSQLDBCompositeDataType> {
2121

2222
private enum Expression {
23-
BINARY_LOGICAL;
23+
BINARY_LOGICAL, BINARY_COMPARISON, BINARY_ARITHMETIC;
2424
}
2525

2626
HSQLDBProvider.HSQLDBGlobalState hsqldbGlobalState;
@@ -90,13 +90,23 @@ protected Node<HSQLDBExpression> generateExpression(HSQLDBSchema.HSQLDBComposite
9090
Arrays.asList(HSQLDBExpressionGenerator.Expression.values()));
9191

9292
HSQLDBExpressionGenerator.Expression expr = Randomly.fromList(possibleOptions);
93+
BinaryOperatorNode.Operator op;
9394
switch (expr) {
9495
case BINARY_LOGICAL:
95-
BinaryOperatorNode.Operator op = HSQLDBExpressionGenerator.HSQLDBBinaryLogicalOperator.getRandom();
96-
return new NewBinaryOperatorNode<>(generateExpression(type), generateExpression(type), op);
96+
op = HSQLDBExpressionGenerator.HSQLDBBinaryLogicalOperator.getRandom();
97+
break;
98+
case BINARY_COMPARISON:
99+
op = HSQLDBDBBinaryComparisonOperator.getRandom();
100+
break;
101+
case BINARY_ARITHMETIC:
102+
op = HSQLDBDBBinaryArithmeticOperator.getRandom();
103+
break;
97104
default:
98105
throw new AssertionError();
99106
}
107+
108+
return new NewBinaryOperatorNode<>(generateExpression(type), generateExpression(type), op);
109+
100110
}
101111

102112
@Override
@@ -128,4 +138,46 @@ public static BinaryOperatorNode.Operator getRandom() {
128138
}
129139

130140
}
141+
142+
public enum HSQLDBDBBinaryComparisonOperator implements BinaryOperatorNode.Operator {
143+
EQUALS("="), GREATER(">"), GREATER_EQUALS(">="), SMALLER("<"), SMALLER_EQUALS("<="), NOT_EQUALS("!="),
144+
LIKE("LIKE"), NOT_LIKE("NOT LIKE"), SIMILAR_TO("SIMILAR TO"), NOT_SIMILAR_TO("NOT SIMILAR TO"),
145+
REGEX_POSIX("~"), REGEX_POSIT_NOT("!~");
146+
147+
private String textRepr;
148+
149+
HSQLDBDBBinaryComparisonOperator(String textRepr) {
150+
this.textRepr = textRepr;
151+
}
152+
153+
public static BinaryOperatorNode.Operator getRandom() {
154+
return Randomly.fromOptions(values());
155+
}
156+
157+
@Override
158+
public String getTextRepresentation() {
159+
return textRepr;
160+
}
161+
162+
}
163+
164+
public enum HSQLDBDBBinaryArithmeticOperator implements BinaryOperatorNode.Operator {
165+
CONCAT("||"), ADD("+"), SUB("-"), MULT("*"), DIV("/"), MOD("%"), AND("&"), OR("|"), LSHIFT("<<"), RSHIFT(">>");
166+
167+
private String textRepr;
168+
169+
HSQLDBDBBinaryArithmeticOperator(String textRepr) {
170+
this.textRepr = textRepr;
171+
}
172+
173+
public static BinaryOperatorNode.Operator getRandom() {
174+
return Randomly.fromOptions(values());
175+
}
176+
177+
@Override
178+
public String getTextRepresentation() {
179+
return textRepr;
180+
}
181+
182+
}
131183
}

0 commit comments

Comments
 (0)