-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathregexp_test.go
More file actions
28 lines (21 loc) · 844 Bytes
/
regexp_test.go
File metadata and controls
28 lines (21 loc) · 844 Bytes
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
package stdlib
import "testing"
func Test_regexp(t *testing.T) {
assertQuery(t, "SELECT 'ZaB' REGEXP '[a-zA-Z]+'", "1")
assertQuery(t, "SELECT 'ZaB0' REGEXP '[a-zA-Z]+$'", "0")
// bad regexp
assertQuery(t, "SELECT 'ZaB0' REGEXP ']['", "0")
}
func Test_regexp_split_part(t *testing.T) {
assertQuery(t, "SELECT regexp_split_part('ab12', '[a-zA-Z]1', 1)", "2")
assertQuery(t, "SELECT regexp_split_part('ab12', '[a-zA-Z]1', -1)", "2")
assertQuery(t, "SELECT regexp_split_part('ab12', '[a-zA-Z]1', 100)", "")
// bad regexp
assertQuery(t, "SELECT regexp_split_part('ab12', '][', 1)", "")
}
func Test_regexp_count(t *testing.T) {
assertQuery(t, "SELECT regexp_count('ab12', '[a-zA-Z]1')", "1")
assertQuery(t, "SELECT regexp_count('ac22', '[a-zA-Z]1')", "0")
// bad regexp
assertQuery(t, "SELECT regexp_count('ab12', '][')", "0")
}