|
| 1 | +package sqlancer.mysql; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | +import org.junit.jupiter.params.ParameterizedTest; |
| 5 | +import org.junit.jupiter.params.provider.EnumSource; |
| 6 | + |
| 7 | +import sqlancer.mysql.ast.MySQLAggregate; |
| 8 | +import sqlancer.mysql.ast.MySQLColumnReference; |
| 9 | + |
| 10 | +public class MySQLToStringVisitorTest { |
| 11 | + |
| 12 | + @ParameterizedTest |
| 13 | + @EnumSource(MySQLAggregate.MySQLAggregateFunction.class) |
| 14 | + void visitAggregateWithOptions(MySQLAggregate.MySQLAggregateFunction function) { |
| 15 | + MySQLSchema.MySQLColumn aCol = new MySQLSchema.MySQLColumn("a", |
| 16 | + MySQLSchema.MySQLDataType.INT, false, 0); |
| 17 | + MySQLColumnReference aRef = new MySQLColumnReference(aCol, null); |
| 18 | + |
| 19 | + MySQLToStringVisitor visitor = new MySQLToStringVisitor(); |
| 20 | + |
| 21 | + for (String option : function.getOptions()) { |
| 22 | + visitor.visit(new MySQLAggregate(aRef, function, option)); |
| 23 | + assertEquals(String.format("%s(%s a)", function, option), visitor.get()); |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + @ParameterizedTest |
| 28 | + @EnumSource(MySQLAggregate.MySQLAggregateFunction.class) |
| 29 | + void visitAggregateWithoutOptions(MySQLAggregate.MySQLAggregateFunction function) { |
| 30 | + MySQLSchema.MySQLColumn aCol = new MySQLSchema.MySQLColumn("a", |
| 31 | + MySQLSchema.MySQLDataType.INT, false, 0); |
| 32 | + MySQLColumnReference aRef = new MySQLColumnReference(aCol, null); |
| 33 | + |
| 34 | + MySQLToStringVisitor visitor = new MySQLToStringVisitor(); |
| 35 | + |
| 36 | + visitor.visit(new MySQLAggregate(aRef, function, null)); |
| 37 | + assertEquals(String.format("%s(a)", function), visitor.get()); |
| 38 | + } |
| 39 | +} |
0 commit comments