Skip to content

Commit 111e528

Browse files
committed
Add a test case for formatting SQL using bind variables
1 parent 4eab34c commit 111e528

File tree

8 files changed

+96
-1
lines changed

8 files changed

+96
-1
lines changed

src/test/kotlin/org/domaframework/doma/intellij/formatter/SqlFormatterTest.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,22 @@ class SqlFormatterTest : BasePlatformTestCase() {
5757
formatSqlFime("Insert.sql", "FormattedInsert.sql")
5858
}
5959

60+
fun testInsertWithBindVariableFormatter() {
61+
formatSqlFime("InsertWithBindVariable.sql", "FormattedInsertWithBindVariable.sql")
62+
}
63+
64+
fun testUpdateFormatter() {
65+
formatSqlFime("Update.sql", "FormattedUpdate.sql")
66+
}
67+
68+
fun testUpdateBindVariableFormatter() {
69+
formatSqlFime("UpdateBindVariable.sql", "FormattedUpdateBindVariable.sql")
70+
}
71+
72+
fun testUpdateTupleAssignmentFormatter() {
73+
formatSqlFime("UpdateTupleAssignment.sql", "FormattedUpdateTupleAssignment.sql")
74+
}
75+
6076
fun testDeleteFormatter() {
6177
formatSqlFime("Delete.sql", "FormattedDelete.sql")
6278
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
INSERT INTO /*# tableName */
2+
(x1
3+
, x2
4+
/*%for entity : entities */
5+
, /*# entity.itemIdentifier */
6+
/*%end*/
7+
, x3
8+
, x4)
9+
VALUES ( /* reportId */1
10+
, /* @tenantId() */1
11+
/*%for entity : entities */
12+
, /* entity.value */'abc'
13+
/*%end*/
14+
, /* @userId() */1
15+
, x5
16+
, /* @userId() */1
17+
, x6
18+
, 1
19+
, /* @maxDateTime() */'9999-12-31')
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
UPDATE USER
1+
UPDATE user
22
SET name = /* user.name */'name'
33
, rank = /*user.rank */3
44
WHERE id = /* user.id */1
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
UPDATE /*# tableName */
2+
SET X1 = 1
3+
, X2 = 2
4+
, X3 = 3
5+
/*%for entity : entities */
6+
, /*# entity.itemIdentifier */= /* entity.value */'abc'
7+
/*%end*/
8+
WHERE X = /* reportId */1
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
UPDATE /*# tableName */
2+
SET (x1
3+
, x2
4+
, x3
5+
/*%for entity : entities */
6+
, /*# entity.itemIdentifier */
7+
/*%end*/
8+
)
9+
= ( /* @userId() */1
10+
, x
11+
, x + 1
12+
/*%for entity : entities */
13+
, /* entity.value */'abc'
14+
/*%end*/
15+
)
16+
WHERE x = /* reportId */1
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
INSERT INTO /*# tableName */
2+
(x1
3+
, x2
4+
/*%for entity : entities */
5+
, /*# entity.itemIdentifier */
6+
/*%end*/
7+
, x3
8+
, x4)
9+
VALUES ( /* reportId */1, /* @tenantId() */1 /*%for entity : entities */, /* entity.value */'abc'
10+
/*%end*/
11+
, /* @userId() */1
12+
, x5
13+
, /* @userId() */1
14+
, x6
15+
, 1
16+
, /* @maxDateTime() */'9999-12-31')
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
UPDATE /*# tableName */
2+
SET X1 = 1
3+
, X2 = 2
4+
, X3 = 3
5+
/*%for entity : entities */
6+
, /*# entity.itemIdentifier */= /* entity.value */'abc'
7+
/*%end*/
8+
WHERE X = /* reportId */1
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
UPDATE /*# tableName */
2+
SET (x1
3+
, x2
4+
, x3
5+
/*%for entity : entities */
6+
, /*# entity.itemIdentifier */
7+
/*%end*/) = ( /* @userId() */1
8+
, x
9+
, x + 1
10+
/*%for entity : entities */
11+
, /* entity.value */'abc'
12+
/*%end*/) WHERE x = /* reportId */1

0 commit comments

Comments
 (0)