mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-12 04:27:39 +00:00
(improvement)(headless)Add unit test case for variable if statement.
This commit is contained in:
@@ -34,6 +34,18 @@ public class SqlVariableParseUtilsTest {
|
|||||||
Assertions.assertEquals(expectedSql, actualSql);
|
Assertions.assertEquals(expectedSql, actualSql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testParseSql_if() {
|
||||||
|
String sql = "select * from t_$interval$ where id = $id$ $if(name)$and name = $name$$endif$";
|
||||||
|
List<SqlVariable> variables = Lists.newArrayList(mockNumSqlVariable(),
|
||||||
|
mockExprSqlVariable(), mockStrSqlVariable());
|
||||||
|
List<Param> params =
|
||||||
|
Lists.newArrayList(mockIdParam(), mockNameParam(), mockIntervalParam());
|
||||||
|
String actualSql = SqlVariableParseUtils.parse(sql, variables, params);
|
||||||
|
String expectedSql = "select * from t_wk where id = 2 and name = 'alice'";
|
||||||
|
Assertions.assertEquals(expectedSql, actualSql);
|
||||||
|
}
|
||||||
|
|
||||||
private SqlVariable mockNumSqlVariable() {
|
private SqlVariable mockNumSqlVariable() {
|
||||||
return mockSqlVariable("id", VariableValueType.NUMBER, 1);
|
return mockSqlVariable("id", VariableValueType.NUMBER, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user