Skip to content

Commit 04ed212

Browse files
Merge pull request #1010 from Cali0707/sync-tck-tests
Sync CESQL tck tests
2 parents f1f87df + 06b0321 commit 04ed212

File tree

5 files changed

+242
-1
lines changed

5 files changed

+242
-1
lines changed

sql/v2/expression/like_expression.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ func convertLikePatternToRegex(pattern string) (*regexp.Regexp, error) {
7070
chunk.Reset()
7171
i++
7272
continue
73+
} else {
74+
// if there is an actual literal \ character, we need to include that in the string
75+
chunk.WriteRune('\\')
7376
}
7477
} else if pattern[i] == '_' {
7578
// replace with .

sql/v2/test/tck/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# CloudEvents Expression Language TCK
2+
3+
Each file of this TCK contains a set of test cases, testing one or more specific features of the language.
4+
5+
The root file structure is composed by:
6+
7+
* `name`: Name of the test suite contained in the file
8+
* `tests`: List of tests
9+
10+
Each test definition includes:
11+
12+
* `name`: Name of the test case
13+
* `expression`: Expression to test.
14+
* `result`: Expected result (OPTIONAL). Can be a boolean, an integer or a string.
15+
* `error`: Expected error (OPTIONAL). If absent, no error is expected.
16+
* `event`: Input event (OPTIONAL). If present, this is a valid event serialized in JSON format. If absent, when testing
17+
the expression, any valid event can be passed.
18+
* `eventOverrides`: Overrides to the input event (OPTIONAL). This might be used when `event` is missing, in order to
19+
define only some specific values, while the other (REQUIRED) attributes can be any value.
20+
21+
The `error` values could be any of the following:
22+
23+
* `parse`: Error while parsing the expression
24+
* `math`: Math error while evaluating a math operator
25+
* `cast`: Casting error
26+
* `missingAttribute`: Addressed a missing attribute
27+
* `missingFunction`: Addressed a missing function
28+
* `functionEvaluation`: Error while evaluating a function

sql/v2/test/tck/like_expression.yaml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
name: Like expression
22
tests:
3-
- name: Exact match
3+
- name: Exact match (1)
44
expression: "'abc' LIKE 'abc'"
55
result: true
6+
- name: Exact match (2)
7+
expression: "'ab\\c' LIKE 'ab\\c'"
8+
result: true
69
- name: Exact match (negate)
710
expression: "'abc' NOT LIKE 'abc'"
811
result: false
@@ -25,6 +28,12 @@ tests:
2528
- name: Percentage operator (6)
2629
expression: "'' LIKE 'abc'"
2730
result: false
31+
- name: Percentage operator (7)
32+
expression: "'.ab.cde.' LIKE '.%.%.'"
33+
result: true
34+
- name: Percentage operator (8)
35+
expression: "'ab.cde' LIKE '.%.%.'"
36+
result: false
2837

2938
- name: Underscore operator (1)
3039
expression: "'abc' LIKE 'a_b_c'"
@@ -41,6 +50,12 @@ tests:
4150
- name: Underscore operator (5)
4251
expression: "'azbzc' LIKE 'a_b_c'"
4352
result: true
53+
- name: Underscore operator (6)
54+
expression: "'.a.b.' LIKE '._._.'"
55+
result: true
56+
- name: Underscore operator (7)
57+
expression: "'abcd.' LIKE '._._.'"
58+
result: false
4459

4560
- name: Escaped underscore wildcards (1)
4661
expression: "'a_b_c' LIKE 'a\\_b\\_c'"
@@ -78,3 +93,26 @@ tests:
7893
eventOverrides:
7994
myext: "abc123123%456_dzf"
8095
result: false
96+
97+
- name: With type coercion from int (1)
98+
expression: "234 LIKE '23_'"
99+
result: true
100+
- name: With type coercion from int (2)
101+
expression: "2344 LIKE '23%'"
102+
result: true
103+
- name: With type coercion from int (3)
104+
expression: "2344 LIKE '23_'"
105+
result: false
106+
107+
- name: With type coercion from bool (1)
108+
expression: "TRUE LIKE 'tr%'"
109+
result: true
110+
- name: With type coercion from bool (2)
111+
expression: "TRUE LIKE '%ue'"
112+
result: true
113+
- name: With type coercion from bool (3)
114+
expression: "FALSE LIKE 'tr%'"
115+
result: false
116+
- name: With type coercion from bool (4)
117+
expression: "FALSE LIKE 'fal%'"
118+
result: true
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
name: SubscriptionsAPI Recreations
2+
tests:
3+
- name: Prefix filter (1)
4+
expression: "source LIKE 'https://%'"
5+
result: true
6+
eventOverrides:
7+
source: "https://example.com"
8+
- name: Prefix filter (2)
9+
expression: "source LIKE 'https://%'"
10+
result: false
11+
eventOverrides:
12+
source: "http://example.com"
13+
- name: Prefix filter on string extension
14+
expression: "myext LIKE 'custom%'"
15+
result: true
16+
eventOverrides:
17+
myext: "customext"
18+
- name: Prefix filter on missing string extension
19+
expression: "myext LIKE 'custom%'"
20+
error: missingAttribute
21+
22+
- name: Suffix filter (1)
23+
expression: "type like '%.error'"
24+
result: true
25+
eventOverrides:
26+
type: "com.github.error"
27+
- name: Suffix filter (2)
28+
expression: "type like '%.error'"
29+
result: false
30+
eventOverrides:
31+
type: "com.github.success"
32+
- name: Suffix filter on string extension
33+
expression: "myext LIKE '%ext'"
34+
result: true
35+
eventOverrides:
36+
myext: "customext"
37+
- name: Suffix filter on missing string extension
38+
expression: "myext LIKE '%ext'"
39+
error: missingAttribute
40+
41+
- name: Exact filter (1)
42+
expression: "id = 'myId'"
43+
result: true
44+
eventOverrides:
45+
id: "myId"
46+
- name: Exact filter (2)
47+
expression: "id = 'myId'"
48+
result: false
49+
eventOverrides:
50+
id: "notmyId"
51+
- name: Exact filter on string extension
52+
expression: "myext = 'customext'"
53+
result: true
54+
eventOverrides:
55+
myext: "customext"
56+
- name: Exact filter on missing string extension
57+
expression: "myext = 'customext'"
58+
error: missingAttribute
59+
60+
- name: Prefix filter AND Suffix filter (1)
61+
expression: "id LIKE 'my%' AND source LIKE '%.ca'"
62+
result: true
63+
eventOverrides:
64+
id: "myId"
65+
source: "http://www.some-website.ca"
66+
- name: Prefix filter AND Suffix filter (2)
67+
expression: "id LIKE 'my%' AND source LIKE '%.ca'"
68+
result: false
69+
eventOverrides:
70+
id: "myId"
71+
source: "http://www.some-website.com"
72+
- name: Prefix filter AND Suffix filter (3)
73+
expression: "myext LIKE 'custom%' AND type LIKE '%.error'"
74+
result: true
75+
eventOverrides:
76+
myext: "customext"
77+
type: "com.github.error"
78+
- name: Prefix AND Suffix filter (4)
79+
expression: "type LIKE 'example.%' AND myext LIKE 'custom%'"
80+
error: missingAttribute
81+
eventOverrides:
82+
type: "example.event.type"
83+
84+
- name: Prefix OR Suffix filter (1)
85+
expression: "id LIKE 'my%' OR source LIKE '%.ca'"
86+
result: true
87+
eventOverrides:
88+
id: "myId"
89+
source: "http://www.some-website.ca"
90+
- name: Prefix OR Suffix filter (2)
91+
expression: "id LIKE 'my%' OR source LIKE '%.ca'"
92+
result: true
93+
eventOverrides:
94+
id: "myId"
95+
source: "http://www.some-website.com"
96+
- name: Prefix OR Suffix filter (3)
97+
expression: "id LIKE 'my%' OR source LIKE '%.ca'"
98+
result: true
99+
eventOverrides:
100+
id: "notmyId"
101+
source: "http://www.some-website.ca"
102+
- name: Prefix OR Suffix filter (4)
103+
expression: "id LIKE 'my%' OR source LIKE '%.ca'"
104+
result: false
105+
eventOverrides:
106+
id: "notmyId"
107+
source: "http://www.some-website.com"
108+
109+
- name: Disjunctive Normal Form (1)
110+
expression: "(id = 'myId' AND type LIKE '%.success') OR (id = 'notmyId' AND source LIKE 'http://%' AND type LIKE '%.warning')"
111+
result: true
112+
eventOverrides:
113+
id: "myId"
114+
type: "example.event.success"
115+
- name: Disjunctive Normal Form (2)
116+
expression: "(id = 'myId' AND type LIKE '%.success') OR (id = 'notmyId' AND source LIKE 'http://%' AND type LIKE '%.warning')"
117+
result: true
118+
eventOverrides:
119+
id: "notmyId"
120+
type: "example.event.warning"
121+
source: "http://localhost.localdomain"
122+
- name: Disjunctive Normal Form (3)
123+
expression: "(id = 'myId' AND type LIKE '%.success') OR (id = 'notmyId' AND source LIKE 'http://%' AND type LIKE '%.warning')"
124+
result: false
125+
eventOverrides:
126+
id: "notmyId"
127+
type: "example.event.warning"
128+
source: "https://localhost.localdomain"
129+
130+
- name: Conjunctive Normal Form (1)
131+
expression: "(id = 'myId' OR type LIKE '%.success') AND (id = 'notmyId' OR source LIKE 'https://%' OR type LIKE '%.warning')"
132+
result: true
133+
eventOverrides:
134+
id: "myId"
135+
type: "example.event.warning"
136+
source: "http://localhost.localdomain"
137+
- name: Conjunctive Normal Form (2)
138+
expression: "(id = 'myId' OR type LIKE '%.success') AND (id = 'notmyId' OR source LIKE 'https://%' OR type LIKE '%.warning')"
139+
result: true
140+
eventOverrides:
141+
id: "notmyId"
142+
type: "example.event.success"
143+
source: "http://localhost.localdomain"
144+
- name: Conjunctive Normal Form (3)
145+
expression: "(id = 'myId' OR type LIKE '%.success') AND (id = 'notmyId' OR source LIKE 'https://%' OR type LIKE '%.warning')"
146+
result: false
147+
eventOverrides:
148+
id: "notmyId"
149+
type: "example.event.warning"
150+
source: "http://localhost.localdomain"
151+
- name: Conjunctive Normal Form (4)
152+
expression: "(id = 'myId' OR type LIKE '%.success') AND (id = 'notmyId' OR source LIKE 'https://%' OR type LIKE '%.warning')"
153+
result: false
154+
eventOverrides:
155+
id: "myId"
156+
type: "example.event.success"
157+
source: "http://localhost.localdomain"
158+
- name: Conjunctive Normal Form (5)
159+
expression: "(id = 'myId' OR type LIKE '%.success') AND (id = 'notmyId' OR source LIKE 'https://%' OR type LIKE '%.warning') AND (myext = 'customext')"
160+
error: missingAttribute
161+
eventOverrides:
162+
id: "myId"
163+
type: "example.event.warning"
164+
source: "http://localhost.localdomain"
165+
166+
167+
168+

sql/v2/test/tck_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var TCKFileNames = []string{
4040
"spec_examples",
4141
"string_builtin_functions",
4242
"sub_expression",
43+
"subscriptions_api_recreations",
4344
}
4445

4546
type ErrorType string
@@ -93,6 +94,8 @@ func (tc TckTestCase) ExpectedResult() interface{} {
9394
return int32(tc.Result.(int))
9495
case float64:
9596
return int32(tc.Result.(float64))
97+
case bool:
98+
return tc.Result.(bool)
9699
}
97100
return tc.Result
98101
}
@@ -125,6 +128,7 @@ func TestTCK(t *testing.T) {
125128
t.Run(file.Name, func(t *testing.T) {
126129
for j, testCase := range tckFiles[i].Tests {
127130
j := j
131+
testCase := testCase
128132
t.Run(testCase.Name, func(t *testing.T) {
129133
t.Parallel()
130134
testCase := tckFiles[i].Tests[j]

0 commit comments

Comments
 (0)