forked from sijms/go-ora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_test.go
58 lines (51 loc) · 1.27 KB
/
command_test.go
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
package go_ora
import "testing"
func TestNewStmt_WithComments(t *testing.T) {
t.Run("SELECT", func(t *testing.T) {
querySelectWithComments := `
-- comment #1
-- comment #2
/* comment #3 */
/* comment #4 */ select * from dual
`
stmt := NewStmt(querySelectWithComments, nil)
if stmt == nil {
t.Errorf("no stmt returned")
} else if stmt.stmtType != SELECT {
t.Errorf("expected stmt.stmtType to be %v but was %v", SELECT, stmt.stmtType)
}
})
t.Run("UPDATE", func(t *testing.T) {
querySelectWithComments := `
-- comment #1
-- comment #2
/* comment #3 */
/* comment #4 */ update foo set bar = 1 where baz = 1
`
stmt := NewStmt(querySelectWithComments, nil)
if stmt == nil {
t.Errorf("no stmt returned")
} else if stmt.stmtType != DML {
t.Errorf("expected stmt.stmtType to be %v but was %v", DML, stmt.stmtType)
}
})
t.Run("DECLARE", func(t *testing.T) {
querySelectWithComments := `
-- comment #1
-- comment #2
/* comment #3 */
/* comment #4 */
DECLARE
foo NUMBER := 42;
BEGIN
INSERT INTO bar VALUES (foo);
END;
`
stmt := NewStmt(querySelectWithComments, nil)
if stmt == nil {
t.Errorf("no stmt returned")
} else if stmt.stmtType != PLSQL {
t.Errorf("expected stmt.stmtType to be %v but was %v", PLSQL, stmt.stmtType)
}
})
}