@@ -29,34 +29,46 @@ const COLUMN_UNDEFINED: SingleColumnConfig = {
29
29
type : undefined
30
30
} ;
31
31
32
+ const COLUMN_CASE_INSENSITIVE : SingleColumnConfig = {
33
+ id : 'a' ,
34
+ type : ColumnType . Text ,
35
+ filter_case_insensitive : true
36
+ } ;
37
+
38
+ const COLUMN_CASE_SENSITIVE : SingleColumnConfig = {
39
+ id : 'a' ,
40
+ type : ColumnType . Text ,
41
+ filter_case_sensitive : true
42
+ } ;
43
+
32
44
describe ( 'Single Column Syntax Tree' , ( ) => {
33
45
it ( 'cannot have operand' , ( ) => {
34
- const tree = new SingleColumnSyntaxTree ( '{a} <= 1' , COLUMN_UNDEFINED , Case . Insensitive ) ;
46
+ const tree = new SingleColumnSyntaxTree ( '{a} <= 1' , COLUMN_UNDEFINED , Case . Sensitive ) ;
35
47
36
48
expect ( tree . isValid ) . to . equal ( false ) ;
37
49
} ) ;
38
50
39
51
it ( 'cannot have binary dangle' , ( ) => {
40
- const tree = new SingleColumnSyntaxTree ( '<=' , COLUMN_UNDEFINED , Case . Insensitive ) ;
52
+ const tree = new SingleColumnSyntaxTree ( '<=' , COLUMN_UNDEFINED , Case . Sensitive ) ;
41
53
42
54
expect ( tree . isValid ) . to . equal ( false ) ;
43
55
} ) ;
44
56
45
57
it ( 'cannot be unary + expression' , ( ) => {
46
- const tree = new SingleColumnSyntaxTree ( 'is prime "a"' , COLUMN_UNDEFINED , Case . Insensitive ) ;
58
+ const tree = new SingleColumnSyntaxTree ( 'is prime "a"' , COLUMN_UNDEFINED , Case . Sensitive ) ;
47
59
48
60
expect ( tree . isValid ) . to . equal ( false ) ;
49
61
} ) ;
50
62
51
63
it ( 'can be empty' , ( ) => {
52
- const tree = new SingleColumnSyntaxTree ( '' , COLUMN_UNDEFINED , Case . Insensitive ) ;
64
+ const tree = new SingleColumnSyntaxTree ( '' , COLUMN_UNDEFINED , Case . Sensitive ) ;
53
65
54
66
expect ( tree . isValid ) . to . equal ( true ) ;
55
67
expect ( tree . evaluate ( { a : 0 } ) ) . to . equal ( true ) ;
56
68
} ) ;
57
69
58
70
it ( 'can be binary + expression' , ( ) => {
59
- const tree = new SingleColumnSyntaxTree ( '<= 1' , COLUMN_UNDEFINED , Case . Insensitive ) ;
71
+ const tree = new SingleColumnSyntaxTree ( '<= 1' , COLUMN_UNDEFINED , Case . Sensitive ) ;
60
72
61
73
expect ( tree . isValid ) . to . equal ( true ) ;
62
74
expect ( tree . evaluate ( { a : 0 } ) ) . to . equal ( true ) ;
@@ -66,7 +78,7 @@ describe('Single Column Syntax Tree', () => {
66
78
} ) ;
67
79
68
80
it ( 'can be unary' , ( ) => {
69
- const tree = new SingleColumnSyntaxTree ( 'is prime' , COLUMN_UNDEFINED , Case . Insensitive ) ;
81
+ const tree = new SingleColumnSyntaxTree ( 'is prime' , COLUMN_UNDEFINED , Case . Sensitive ) ;
70
82
71
83
expect ( tree . isValid ) . to . equal ( true ) ;
72
84
expect ( tree . evaluate ( { a : 5 } ) ) . to . equal ( true ) ;
@@ -76,7 +88,7 @@ describe('Single Column Syntax Tree', () => {
76
88
} ) ;
77
89
78
90
it ( 'can be expression with undefined column type' , ( ) => {
79
- const tree = new SingleColumnSyntaxTree ( '1' , COLUMN_UNDEFINED , Case . Insensitive ) ;
91
+ const tree = new SingleColumnSyntaxTree ( '1' , COLUMN_UNDEFINED , Case . Sensitive ) ;
80
92
81
93
expect ( tree . isValid ) . to . equal ( true ) ;
82
94
expect ( tree . evaluate ( { a : '1' } ) ) . to . equal ( true ) ;
@@ -88,7 +100,7 @@ describe('Single Column Syntax Tree', () => {
88
100
} ) ;
89
101
90
102
it ( 'can be expression with numeric column type' , ( ) => {
91
- const tree = new SingleColumnSyntaxTree ( '1' , COLUMN_NUMERIC , Case . Insensitive ) ;
103
+ const tree = new SingleColumnSyntaxTree ( '1' , COLUMN_NUMERIC , Case . Sensitive ) ;
92
104
93
105
expect ( tree . isValid ) . to . equal ( true ) ;
94
106
expect ( tree . evaluate ( { a : 1 } ) ) . to . equal ( true ) ;
@@ -98,7 +110,7 @@ describe('Single Column Syntax Tree', () => {
98
110
} ) ;
99
111
100
112
it . only ( 'can be permissive value expression' , ( ) => {
101
- const tree = new SingleColumnSyntaxTree ( 'Hello world' , COLUMN_TEXT , Case . Insensitive ) ;
113
+ const tree = new SingleColumnSyntaxTree ( 'Hello world' , COLUMN_TEXT , Case . Sensitive ) ;
102
114
103
115
expect ( tree . isValid ) . to . equal ( true ) ;
104
116
expect ( tree . evaluate ( { a : 'Hello world' } ) ) . to . equal ( true ) ;
@@ -107,25 +119,25 @@ describe('Single Column Syntax Tree', () => {
107
119
} ) ;
108
120
109
121
it ( '`undefined` column type can use `contains`' , ( ) => {
110
- const tree = new SingleColumnSyntaxTree ( 'contains 1' , COLUMN_UNDEFINED , Case . Insensitive ) ;
122
+ const tree = new SingleColumnSyntaxTree ( 'contains 1' , COLUMN_UNDEFINED , Case . Sensitive ) ;
111
123
112
124
expect ( tree . isValid ) . to . equal ( true ) ;
113
125
} ) ;
114
126
115
127
it ( '`any` column type can use `contains`' , ( ) => {
116
- const tree = new SingleColumnSyntaxTree ( 'contains 1' , COLUMN_ANY , Case . Insensitive ) ;
128
+ const tree = new SingleColumnSyntaxTree ( 'contains 1' , COLUMN_ANY , Case . Sensitive ) ;
117
129
118
130
expect ( tree . isValid ) . to . equal ( true ) ;
119
131
} ) ;
120
132
121
133
it ( '`numeric` column type can use `contains`' , ( ) => {
122
- const tree = new SingleColumnSyntaxTree ( 'contains 1' , COLUMN_NUMERIC , Case . Insensitive ) ;
134
+ const tree = new SingleColumnSyntaxTree ( 'contains 1' , COLUMN_NUMERIC , Case . Sensitive ) ;
123
135
124
136
expect ( tree . isValid ) . to . equal ( true ) ;
125
137
} ) ;
126
138
127
139
it ( 'can be expression with text column type' , ( ) => {
128
- const tree = new SingleColumnSyntaxTree ( '"1"' , COLUMN_TEXT , Case . Insensitive ) ;
140
+ const tree = new SingleColumnSyntaxTree ( '"1"' , COLUMN_TEXT , Case . Sensitive ) ;
129
141
130
142
expect ( tree . isValid ) . to . equal ( true ) ;
131
143
expect ( tree . evaluate ( { a : 1 } ) ) . to . equal ( true ) ;
@@ -138,7 +150,7 @@ describe('Single Column Syntax Tree', () => {
138
150
139
151
[ '1975' , '"1975"' ] . forEach ( value => {
140
152
it ( `can be expression '${ value } ' with datetime column type` , ( ) => {
141
- const tree = new SingleColumnSyntaxTree ( value , COLUMN_DATE , Case . Insensitive ) ;
153
+ const tree = new SingleColumnSyntaxTree ( value , COLUMN_DATE , Case . Sensitive ) ;
142
154
143
155
expect ( tree . evaluate ( { a : 1975 } ) ) . to . equal ( true ) ;
144
156
expect ( tree . evaluate ( { a : '1975' } ) ) . to . equal ( true ) ;
@@ -160,7 +172,7 @@ describe('Single Column Syntax Tree', () => {
160
172
{ type : COLUMN_TEXT , name : 'text' }
161
173
] . forEach ( ( { type, name } ) => {
162
174
it ( `returns the correct relational operator lexeme for '${ name } ' column type` , ( ) => {
163
- const tree = new SingleColumnSyntaxTree ( '1' , type , Case . Insensitive ) ;
175
+ const tree = new SingleColumnSyntaxTree ( '1' , type , Case . Sensitive ) ;
164
176
const structure = tree . toStructure ( ) ;
165
177
166
178
expect ( tree . toQueryString ( ) ) . to . equal ( '{a} contains 1' ) ;
@@ -189,7 +201,7 @@ describe('Single Column Syntax Tree', () => {
189
201
} ) ;
190
202
191
203
it ( `returns the correct relational operator lexeme for 'date' column type` , ( ) => {
192
- const tree = new SingleColumnSyntaxTree ( '1975' , COLUMN_DATE , Case . Insensitive ) ;
204
+ const tree = new SingleColumnSyntaxTree ( '1975' , COLUMN_DATE , Case . Sensitive ) ;
193
205
const structure = tree . toStructure ( ) ;
194
206
195
207
expect ( tree . toQueryString ( ) ) . to . equal ( '{a} datestartswith 1975' ) ;
@@ -217,7 +229,7 @@ describe('Single Column Syntax Tree', () => {
217
229
} ) ;
218
230
219
231
it ( `returns the correct relational operator lexeme for 'numeric' column type` , ( ) => {
220
- const tree = new SingleColumnSyntaxTree ( '1' , COLUMN_NUMERIC , Case . Insensitive ) ;
232
+ const tree = new SingleColumnSyntaxTree ( '1' , COLUMN_NUMERIC , Case . Default ) ;
221
233
const structure = tree . toStructure ( ) ;
222
234
223
235
expect ( tree . toQueryString ( ) ) . to . equal ( '{a} = 1' ) ;
@@ -243,4 +255,40 @@ describe('Single Column Syntax Tree', () => {
243
255
}
244
256
}
245
257
} ) ;
258
+
259
+ it ( 'can have case-insensitive column' , ( ) => {
260
+ const tree = new SingleColumnSyntaxTree ( '= Hello world' , COLUMN_CASE_INSENSITIVE , Case . Default ) ;
261
+
262
+ expect ( tree . isValid ) . to . equal ( true ) ;
263
+ expect ( tree . evaluate ( { a : 'Hello world' } ) ) . to . equal ( true ) ;
264
+ expect ( tree . evaluate ( { a : 'Helloworld' } ) ) . to . equal ( false ) ;
265
+ expect ( tree . toQueryString ( ) ) . to . equal ( '{a} i= "Hello world"' ) ;
266
+ } ) ;
267
+
268
+ it ( 'can have forced case-sensitive column in case-insensitive table' , ( ) => {
269
+ const tree = new SingleColumnSyntaxTree ( '= Hello world' , COLUMN_CASE_SENSITIVE , Case . Insensitive ) ;
270
+
271
+ expect ( tree . isValid ) . to . equal ( true ) ;
272
+ expect ( tree . evaluate ( { a : 'Hello world' } ) ) . to . equal ( true ) ;
273
+ expect ( tree . evaluate ( { a : 'Helloworld' } ) ) . to . equal ( false ) ;
274
+ expect ( tree . toQueryString ( ) ) . to . equal ( '{a} = "Hello world"' ) ;
275
+ } ) ;
276
+
277
+ it ( 'can have forced case-sensitive operator in case-insensitive column' , ( ) => {
278
+ const tree = new SingleColumnSyntaxTree ( 'c= Hello world' , COLUMN_CASE_INSENSITIVE , Case . Default ) ;
279
+
280
+ expect ( tree . isValid ) . to . equal ( true ) ;
281
+ expect ( tree . evaluate ( { a : 'Hello world' } ) ) . to . equal ( true ) ;
282
+ expect ( tree . evaluate ( { a : 'Helloworld' } ) ) . to . equal ( false ) ;
283
+ expect ( tree . toQueryString ( ) ) . to . equal ( '{a} = "Hello world"' ) ;
284
+ } ) ;
285
+
286
+ it ( 'can have forced case-sensitive operator in case-insensitive table' , ( ) => {
287
+ const tree = new SingleColumnSyntaxTree ( 'c= Hello world' , COLUMN_CASE_SENSITIVE , Case . Insensitive ) ;
288
+
289
+ expect ( tree . isValid ) . to . equal ( true ) ;
290
+ expect ( tree . evaluate ( { a : 'Hello world' } ) ) . to . equal ( true ) ;
291
+ expect ( tree . evaluate ( { a : 'Helloworld' } ) ) . to . equal ( false ) ;
292
+ expect ( tree . toQueryString ( ) ) . to . equal ( '{a} = "Hello world"' ) ;
293
+ } ) ;
246
294
} ) ;
0 commit comments