|
1 | | -import { getQueryExprVariableRegExp } from './regExpOperator'; |
2 | | - |
3 | | -describe('getQueryExprVariableRegExp', () => { |
4 | | - it('should fing fieldName:~$var', () => { |
5 | | - const result = getQueryExprVariableRegExp(' fieldName:~$var '); |
6 | | - expect(result?.[0]).toEqual(' fieldName:~$var'); |
7 | | - }); |
8 | | - |
9 | | - it('should find fieldName:~$var without spaces', () => { |
10 | | - const result = getQueryExprVariableRegExp('fieldName:~$var'); |
11 | | - expect(result?.[0]).toEqual('fieldName:~$var'); |
12 | | - }); |
13 | | - |
14 | | - it('should find fieldName:~$var at the start of string', () => { |
15 | | - const result = getQueryExprVariableRegExp('fieldName:~$var and more'); |
16 | | - expect(result?.[0]).toEqual('fieldName:~$var'); |
17 | | - }); |
18 | | - |
19 | | - it('should find fieldName:~$var at the end of string', () => { |
20 | | - const result = getQueryExprVariableRegExp('some query fieldName:~$var'); |
21 | | - expect(result?.[0]).toEqual(' fieldName:~$var'); |
22 | | - }); |
23 | | - |
24 | | - it('should find variable with underscores', () => { |
25 | | - const result = getQueryExprVariableRegExp('fieldName:~$my_var_name'); |
26 | | - expect(result?.[0]).toEqual('fieldName:~$my_var_name'); |
27 | | - }); |
28 | | - |
29 | | - it('should find variable with numbers', () => { |
30 | | - const result = getQueryExprVariableRegExp('fieldName:~$var123'); |
31 | | - expect(result?.[0]).toEqual('fieldName:~$var123'); |
32 | | - }); |
33 | | - |
34 | | - it('should find complex field name with variable', () => { |
35 | | - const result = getQueryExprVariableRegExp('complex_field_name:~$variable'); |
36 | | - expect(result?.[0]).toEqual('complex_field_name:~$variable'); |
37 | | - }); |
38 | | - |
39 | | - it('should return null for query without variables', () => { |
40 | | - const result = getQueryExprVariableRegExp('fieldName:value'); |
41 | | - expect(result).toBeNull(); |
42 | | - }); |
43 | | - |
44 | | - it('should return null for empty string', () => { |
45 | | - const result = getQueryExprVariableRegExp(''); |
46 | | - expect(result).toBeNull(); |
47 | | - }); |
48 | | - |
49 | | - it('should return null for string with only spaces', () => { |
50 | | - const result = getQueryExprVariableRegExp(' '); |
51 | | - expect(result).toBeNull(); |
52 | | - }); |
53 | | - |
54 | | - it('should find first variable when multiple variables exist', () => { |
55 | | - const result = getQueryExprVariableRegExp('field1:~$var1 field2:~$var2'); |
56 | | - expect(result?.[0]).toEqual('field1:~$var1'); |
57 | | - }); |
58 | | - |
59 | | - it('should find variable with special characters in field name', () => { |
60 | | - const result = getQueryExprVariableRegExp('field-name:~$var'); |
61 | | - expect(result?.[0]).toEqual('field-name:~$var'); |
62 | | - }); |
63 | | - |
64 | | - it('should not handle variable without field name prefix', () => { |
65 | | - const result = getQueryExprVariableRegExp('~$var'); |
66 | | - expect(result).toBeNull(); |
67 | | - }); |
68 | | - |
69 | | - it('should handle multiple spaces around variable', () => { |
70 | | - const result = getQueryExprVariableRegExp(' fieldName:~$var '); |
71 | | - expect(result?.[0]).toEqual(' fieldName:~$var'); |
72 | | - }); |
73 | | - |
74 | | - it('should find variable with mixed case field name', () => { |
75 | | - const result = getQueryExprVariableRegExp('fieldName:~$MyVariable'); |
76 | | - expect(result?.[0]).toEqual('fieldName:~$MyVariable'); |
77 | | - }); |
78 | | - |
79 | | - it('should find variable with dot separated field name', () => { |
80 | | - const result = getQueryExprVariableRegExp('someField: Some value | field.name.with.some.dot.separated:~$MyVariable'); |
81 | | - expect(result?.[0]).toEqual(' field.name.with.some.dot.separated:~$MyVariable'); |
| 1 | +import { getQueryExprVariableRegExp, replaceRegExpOperatorToOperator } from './regExpOperator'; |
| 2 | + |
| 3 | + |
| 4 | +describe('regExpOperator', () => { |
| 5 | + describe('getQueryExprVariableRegExp', () => { |
| 6 | + it('should fing fieldName:~$var', () => { |
| 7 | + const result = getQueryExprVariableRegExp(' fieldName:~$var '); |
| 8 | + expect(result?.[0]).toEqual(' fieldName:~$var'); |
| 9 | + }); |
| 10 | + |
| 11 | + it('should find fieldName:~$var without spaces', () => { |
| 12 | + const result = getQueryExprVariableRegExp('fieldName:~$var'); |
| 13 | + expect(result?.[0]).toEqual('fieldName:~$var'); |
| 14 | + }); |
| 15 | + |
| 16 | + it('should find fieldName:~$var at the start of string', () => { |
| 17 | + const result = getQueryExprVariableRegExp('fieldName:~$var and more'); |
| 18 | + expect(result?.[0]).toEqual('fieldName:~$var'); |
| 19 | + }); |
| 20 | + |
| 21 | + it('should find fieldName:~$var at the end of string', () => { |
| 22 | + const result = getQueryExprVariableRegExp('some query fieldName:~$var'); |
| 23 | + expect(result?.[0]).toEqual(' fieldName:~$var'); |
| 24 | + }); |
| 25 | + |
| 26 | + it('should find variable with underscores', () => { |
| 27 | + const result = getQueryExprVariableRegExp('fieldName:~$my_var_name'); |
| 28 | + expect(result?.[0]).toEqual('fieldName:~$my_var_name'); |
| 29 | + }); |
| 30 | + |
| 31 | + it('should find variable with numbers', () => { |
| 32 | + const result = getQueryExprVariableRegExp('fieldName:~$var123'); |
| 33 | + expect(result?.[0]).toEqual('fieldName:~$var123'); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should find complex field name with variable', () => { |
| 37 | + const result = getQueryExprVariableRegExp('complex_field_name:~$variable'); |
| 38 | + expect(result?.[0]).toEqual('complex_field_name:~$variable'); |
| 39 | + }); |
| 40 | + |
| 41 | + it('should return null for query without variables', () => { |
| 42 | + const result = getQueryExprVariableRegExp('fieldName:value'); |
| 43 | + expect(result).toBeNull(); |
| 44 | + }); |
| 45 | + |
| 46 | + it('should return null for empty string', () => { |
| 47 | + const result = getQueryExprVariableRegExp(''); |
| 48 | + expect(result).toBeNull(); |
| 49 | + }); |
| 50 | + |
| 51 | + it('should return null for string with only spaces', () => { |
| 52 | + const result = getQueryExprVariableRegExp(' '); |
| 53 | + expect(result).toBeNull(); |
| 54 | + }); |
| 55 | + |
| 56 | + it('should find first variable when multiple variables exist', () => { |
| 57 | + const result = getQueryExprVariableRegExp('field1:~$var1 field2:~$var2'); |
| 58 | + expect(result?.[0]).toEqual('field1:~$var1'); |
| 59 | + }); |
| 60 | + |
| 61 | + it('should find variable with special characters in field name', () => { |
| 62 | + const result = getQueryExprVariableRegExp('field-name:~$var'); |
| 63 | + expect(result?.[0]).toEqual('field-name:~$var'); |
| 64 | + }); |
| 65 | + |
| 66 | + it('should not handle variable without field name prefix', () => { |
| 67 | + const result = getQueryExprVariableRegExp('~$var'); |
| 68 | + expect(result).toBeNull(); |
| 69 | + }); |
| 70 | + |
| 71 | + it('should handle multiple spaces around variable', () => { |
| 72 | + const result = getQueryExprVariableRegExp(' fieldName:~$var '); |
| 73 | + expect(result?.[0]).toEqual(' fieldName:~$var'); |
| 74 | + }); |
| 75 | + |
| 76 | + it('should find variable with mixed case field name', () => { |
| 77 | + const result = getQueryExprVariableRegExp('fieldName:~$MyVariable'); |
| 78 | + expect(result?.[0]).toEqual('fieldName:~$MyVariable'); |
| 79 | + }); |
| 80 | + |
| 81 | + it('should find variable with dot separated field name', () => { |
| 82 | + const result = getQueryExprVariableRegExp('someField: Some value | field.name.with.some.dot.separated:~$MyVariable'); |
| 83 | + expect(result?.[0]).toEqual(' field.name.with.some.dot.separated:~$MyVariable'); |
| 84 | + }); |
| 85 | + }); |
| 86 | + |
| 87 | + describe('replaceRegExpOperatorToOperator', () => { |
| 88 | + it('should replace :~ with :', () => { |
| 89 | + const result = replaceRegExpOperatorToOperator('fieldName:~$var'); |
| 90 | + expect(result).toEqual('fieldName:$var'); |
| 91 | + }); |
| 92 | + |
| 93 | + it('should replace :~ with a custom operator', () => { |
| 94 | + const result = replaceRegExpOperatorToOperator('fieldName:~$var', '!='); |
| 95 | + expect(result).toEqual('fieldName!=$var'); |
| 96 | + }); |
| 97 | + |
| 98 | + it('should ignore queries without :~', () => { |
| 99 | + const result = replaceRegExpOperatorToOperator('fieldName:value'); |
| 100 | + expect(result).toEqual('fieldName:value'); |
| 101 | + }); |
| 102 | + |
| 103 | + it('should handle queries with spaces around :~', () => { |
| 104 | + const result = replaceRegExpOperatorToOperator('fieldName : ~ $var'); |
| 105 | + expect(result).toEqual('fieldName:$var'); |
| 106 | + }); |
| 107 | + |
| 108 | + it('should return the same string if no match is found', () => { |
| 109 | + const result = replaceRegExpOperatorToOperator(''); |
| 110 | + expect(result).toEqual(''); |
| 111 | + }); |
| 112 | + |
| 113 | + it('should handle multiple spaces in the query string', () => { |
| 114 | + const result = replaceRegExpOperatorToOperator(' fieldName :~ $var '); |
| 115 | + expect(result).toEqual(' fieldName:$var '); |
| 116 | + }); |
| 117 | + |
| 118 | + it('should replace variable with underscores', () => { |
| 119 | + const result = replaceRegExpOperatorToOperator('fieldName:~$my_var_name'); |
| 120 | + expect(result).toEqual('fieldName:$my_var_name'); |
| 121 | + }); |
| 122 | + |
| 123 | + it('should replace variables with numbers', () => { |
| 124 | + const result = replaceRegExpOperatorToOperator('fieldName:~$var123'); |
| 125 | + expect(result).toEqual('fieldName:$var123'); |
| 126 | + }); |
| 127 | + |
| 128 | + it('should replace complex field names with a variable', () => { |
| 129 | + const result = replaceRegExpOperatorToOperator('complex_field_name:~$variable'); |
| 130 | + expect(result).toEqual('complex_field_name:$variable'); |
| 131 | + }); |
| 132 | + |
| 133 | + it('should handle fields with special characters', () => { |
| 134 | + const result = replaceRegExpOperatorToOperator('field-name:~$var'); |
| 135 | + expect(result).toEqual('field-name:$var'); |
| 136 | + }); |
| 137 | + |
| 138 | + it('should replace dot-separated field names with variables', () => { |
| 139 | + const result = replaceRegExpOperatorToOperator('field.name.with.dots:~$variable'); |
| 140 | + expect(result).toEqual('field.name.with.dots:$variable'); |
| 141 | + }); |
82 | 142 | }); |
83 | 143 | }); |
0 commit comments