-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtable_identifier_test.go
More file actions
33 lines (31 loc) · 1.17 KB
/
Copy pathtable_identifier_test.go
File metadata and controls
33 lines (31 loc) · 1.17 KB
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
package sqlparser
import (
"reflect"
"testing"
)
func TestTableIdentifierParts(t *testing.T) {
for _, tc := range []struct {
source string
want []string
}{
{"records", []string{"records"}}, {"RECORDS", []string{"RECORDS"}},
{"main.records", []string{"main", "records"}}, {" main . `records` ", []string{"main", "records"}},
{`"main"."odd.name"`, []string{"main", "odd.name"}},
{"[main].[odd name]", []string{"main", "odd name"}},
{`"a""b"`, []string{`a"b`}}, {"`a``b`", []string{"a`b"}},
{"'a''b'", []string{"a'b"}}, {"[a]]b]", []string{"a]b"}},
{"κατάλογος.πίνακας", []string{"κατάλογος", "πίνακας"}},
} {
t.Run(tc.source, func(t *testing.T) {
actual, err := TableIdentifierParts(tc.source)
if err != nil || !reflect.DeepEqual(actual, tc.want) {
t.Fatalf("parts=%v err=%v want=%v", actual, err, tc.want)
}
})
}
for _, source := range []string{"", "main.", ".records", "records alias", "records; DROP TABLE x", "(records)", "$TABLE", "records()", "records/*x*/", "\"unterminated", "[]", "a..b", "a/b"} {
if _, err := TableIdentifierParts(source); err == nil {
t.Fatalf("accepted invalid reference %q", source)
}
}
}