18
18
import static org .assertj .core .api .Assertions .assertThatThrownBy ;
19
19
20
20
import com .google .common .collect .ImmutableList ;
21
+ import com .google .common .collect .ImmutableMap ;
21
22
import java .util .List ;
22
- import org . junit . jupiter . api . Disabled ;
23
+ import java . util . Map ;
23
24
import org .junit .jupiter .api .Test ;
24
25
import org .projectnessie .cel .Ast ;
25
26
import org .projectnessie .cel .Env ;
@@ -35,30 +36,25 @@ public class CustomOverloadTest {
35
36
36
37
@ Test
37
38
public void testIsInf () {
38
- boolean b = CustomOverload .isIPPrefix ("192.168.0.0/16" , 4L , true );
39
- assertThat (b ).isTrue ();
40
- // 127.0.0.1/16
41
- // Map<String, Boolean> testCases =
42
- // ImmutableMap.<String, Boolean>builder()
43
- // .put("0.0.isInf()", false)
44
- // .put("(1.0/0.0).isInf()", true)
45
- // .put("(1.0/0.0).isInf(0)", true)
46
- // .put("(1.0/0.0).isInf(1)", true)
47
- // .put("(1.0/0.0).isInf(-1)", false)
48
- // .put("(-1.0/0.0).isInf()", true)
49
- // .put("(-1.0/0.0).isInf(0)", true)
50
- // .put("(-1.0/0.0).isInf(1)", false)
51
- // .put("(-1.0/0.0).isInf(-1)", true)
52
- // .build();
53
- // for (Map.Entry<String, Boolean> testCase : testCases.entrySet()) {
54
- // Program.EvalResult result = eval(testCase.getKey());
55
- // assertThat(result.getVal().booleanValue()).isEqualTo(testCase.getValue());
56
- // }
57
-
39
+ Map <String , Boolean > testCases =
40
+ ImmutableMap .<String , Boolean >builder ()
41
+ .put ("0.0.isInf()" , false )
42
+ .put ("(1.0/0.0).isInf()" , true )
43
+ .put ("(1.0/0.0).isInf(0)" , true )
44
+ .put ("(1.0/0.0).isInf(1)" , true )
45
+ .put ("(1.0/0.0).isInf(-1)" , false )
46
+ .put ("(-1.0/0.0).isInf()" , true )
47
+ .put ("(-1.0/0.0).isInf(0)" , true )
48
+ .put ("(-1.0/0.0).isInf(1)" , false )
49
+ .put ("(-1.0/0.0).isInf(-1)" , true )
50
+ .build ();
51
+ for (Map .Entry <String , Boolean > testCase : testCases .entrySet ()) {
52
+ Program .EvalResult result = eval (testCase .getKey ());
53
+ assertThat (result .getVal ().booleanValue ()).isEqualTo (testCase .getValue ());
54
+ }
58
55
}
59
56
60
57
@ Test
61
- @ Disabled ("not today satan" )
62
58
public void testIsInfUnsupported () {
63
59
List <String > testCases = ImmutableList .of ("'abc'.isInf()" , "0.0.isInf('abc')" );
64
60
for (String testCase : testCases ) {
@@ -69,156 +65,155 @@ public void testIsInfUnsupported() {
69
65
}
70
66
}
71
67
72
- // @Test
73
- // public void testIsNan() {
74
- // Map<String, Boolean> testCases =
75
- // ImmutableMap.<String, Boolean>builder()
76
- // .put("0.0.isNan()", false)
77
- // .put("(0.0/0.0).isNan()", true)
78
- // .put("(1.0/0.0).isNan()", false)
79
- // .build();
80
- // for (Map.Entry<String, Boolean> testCase : testCases.entrySet()) {
81
- // Program.EvalResult result = eval(testCase.getKey());
82
- // assertThat(result.getVal().booleanValue()).isEqualTo(testCase.getValue());
83
- // }
84
- // }
85
-
86
- // @Test
87
- // public void testIsNanUnsupported() {
88
- // List<String> testCases = ImmutableList.of("'foo'.isNan()");
89
- // for (String testCase : testCases) {
90
- // Val val = eval(testCase).getVal();
91
- // assertThat(Err.isError(val)).isTrue();
92
- // assertThatThrownBy(() -> val.convertToNative(Exception.class))
93
- // .isInstanceOf(UnsupportedOperationException.class);
94
- // }
95
- // }
96
-
97
- // @Test
98
- // public void testUnique() {
99
- // Map<String, Boolean> testCases =
100
- // ImmutableMap.<String, Boolean>builder()
101
- // .put("[].unique()", true)
102
- // .put("[true].unique()", true)
103
- // .put("[true, false].unique()", true)
104
- // .put("[true, true].unique()", false)
105
- // .put("[1, 2, 3].unique()", true)
106
- // .put("[1, 2, 1].unique()", false)
107
- // .put("[1u, 2u, 3u].unique()", true)
108
- // .put("[1u, 2u, 2u].unique()", false)
109
- // .put("[1.0, 2.0, 3.0].unique()", true)
110
- // .put("[3.0,2.0,3.0].unique()", false)
111
- // .put("['abc', 'def'].unique()", true)
112
- // .put("['abc', 'abc'].unique()", false)
113
- // .put("[b'abc', b'123'].unique()", true)
114
- // .put("[b'123', b'123'].unique()", false)
115
- // // Previously, the unique() method returned false here as both bytes were converted
116
- // // to UTF-8. Since both contain invalid UTF-8, this would lead to them treated as
117
- // equal
118
- // // because they'd have the same substitution character.
119
- // .put("[b'\\xFF', b'\\xFE'].unique()", true)
120
- // .build();
121
- // for (Map.Entry<String, Boolean> testCase : testCases.entrySet()) {
122
- // Program.EvalResult result = eval(testCase.getKey());
123
- // assertThat(result.getVal().booleanValue()).isEqualTo(testCase.getValue());
124
- // }
125
- // }
126
-
127
- // @Test
128
- // public void testUniqueUnsupported() {
129
- // List<String> testCases = ImmutableList.of("1.unique()");
130
- // for (String testCase : testCases) {
131
- // Program.EvalResult result = eval(testCase);
132
- // Val val = result.getVal();
133
- // assertThat(Err.isError(val)).isTrue();
134
- // assertThatThrownBy(() -> val.convertToNative(Exception.class))
135
- // .isInstanceOf(UnsupportedOperationException.class);
136
- // }
137
- // }
138
-
139
- // @Test
140
- // public void testIsIpPrefix() {
141
- // Map<String, Boolean> testCases =
142
- // ImmutableMap.<String, Boolean>builder()
143
- // .put("'1.2.3.0/24'.isIpPrefix()", true)
144
- // .put("'1.2.3.4/24'.isIpPrefix()", true)
145
- // .put("'1.2.3.0/24'.isIpPrefix(true)", true)
146
- // .put("'1.2.3.4/24'.isIpPrefix(true)", false)
147
- // .put("'fd7a:115c:a1e0:ab12:4843:cd96:626b:4000/118'.isIpPrefix()", true)
148
- // .put("'fd7a:115c:a1e0:ab12:4843:cd96:626b:430b/118'.isIpPrefix()", true)
149
- // .put("'fd7a:115c:a1e0:ab12:4843:cd96:626b:4000/118'.isIpPrefix(true)", true)
150
- // .put("'fd7a:115c:a1e0:ab12:4843:cd96:626b:430b/118'.isIpPrefix(true)", false)
151
- // .put("'1.2.3.4'.isIpPrefix()", false)
152
- // .put("'fd7a:115c:a1e0:ab12:4843:cd96:626b:430b'.isIpPrefix()", false)
153
- // .put("'1.2.3.0/24'.isIpPrefix(4)", true)
154
- // .put("'1.2.3.4/24'.isIpPrefix(4)", true)
155
- // .put("'1.2.3.0/24'.isIpPrefix(4,true)", true)
156
- // .put("'1.2.3.4/24'.isIpPrefix(4,true)", false)
157
- // .put("'fd7a:115c:a1e0:ab12:4843:cd96:626b:4000/118'.isIpPrefix(4)", false)
158
- // .put("'fd7a:115c:a1e0:ab12:4843:cd96:626b:4000/118'.isIpPrefix(6)", true)
159
- // .put("'fd7a:115c:a1e0:ab12:4843:cd96:626b:430b/118'.isIpPrefix(6)", true)
160
- // .put("'fd7a:115c:a1e0:ab12:4843:cd96:626b:4000/118'.isIpPrefix(6,true)", true)
161
- // .put("'fd7a:115c:a1e0:ab12:4843:cd96:626b:430b/118'.isIpPrefix(6,true)", false)
162
- // .put("'1.2.3.0/24'.isIpPrefix(6)", false)
163
- // .build();
164
- // for (Map.Entry<String, Boolean> testCase : testCases.entrySet()) {
165
- // Program.EvalResult result = eval(testCase.getKey());
166
- // assertThat(result.getVal().booleanValue()).isEqualTo(testCase.getValue());
167
- // }
168
- // }
169
-
170
- // @Test
171
- // public void testIsIpPrefixUnsupported() {
172
- // List<String> testCases =
173
- // ImmutableList.of(
174
- // "1.isIpPrefix()",
175
- // "'1.2.3.0/24'.isIpPrefix('foo')",
176
- // "'1.2.3.0/24'.isIpPrefix(4,'foo')",
177
- // "'1.2.3.0/24'.isIpPrefix('foo',true)");
178
- // for (String testCase : testCases) {
179
- // Program.EvalResult result = eval(testCase);
180
- // Val val = result.getVal();
181
- // assertThat(Err.isError(val)).isTrue();
182
- // assertThatThrownBy(() -> val.convertToNative(Exception.class))
183
- // .isInstanceOf(UnsupportedOperationException.class);
184
- // }
185
- // }
186
-
187
- // @Test
188
- // public void testIsHostname() {
189
- // Map<String, Boolean> testCases =
190
- // ImmutableMap.<String, Boolean>builder()
191
- // .put("'example.com'.isHostname()", true)
192
- // .put("'example.123'.isHostname()", false)
193
- // .build();
194
- // for (Map.Entry<String, Boolean> testCase : testCases.entrySet()) {
195
- // Program.EvalResult result = eval(testCase.getKey());
196
- // assertThat(result.getVal().booleanValue())
197
- // .as(
198
- // "expected %s=%s, got=%s",
199
- // testCase.getKey(), testCase.getValue(), !testCase.getValue())
200
- // .isEqualTo(testCase.getValue());
201
- // }
202
- // }
203
-
204
- // @Test
205
- // public void testIsEmail() {
206
- // Map<String, Boolean> testCases =
207
- // ImmutableMap.<String, Boolean>builder()
208
- // .put("'[email protected] '.isEmail()", true)
209
- // .put("'<[email protected] >'.isEmail()", false)
210
- // .put("' [email protected] '.isEmail()", false)
211
- // .put("'[email protected] '.isEmail()", false)
212
- // .build();
213
- // for (Map.Entry<String, Boolean> testCase : testCases.entrySet()) {
214
- // Program.EvalResult result = eval(testCase.getKey());
215
- // assertThat(result.getVal().booleanValue())
216
- // .as(
217
- // "expected %s=%s, got=%s",
218
- // testCase.getKey(), testCase.getValue(), !testCase.getValue())
219
- // .isEqualTo(testCase.getValue());
220
- // }
221
- // }
68
+ @ Test
69
+ public void testIsNan () {
70
+ Map <String , Boolean > testCases =
71
+ ImmutableMap .<String , Boolean >builder ()
72
+ .put ("0.0.isNan()" , false )
73
+ .put ("(0.0/0.0).isNan()" , true )
74
+ .put ("(1.0/0.0).isNan()" , false )
75
+ .build ();
76
+ for (Map .Entry <String , Boolean > testCase : testCases .entrySet ()) {
77
+ Program .EvalResult result = eval (testCase .getKey ());
78
+ assertThat (result .getVal ().booleanValue ()).isEqualTo (testCase .getValue ());
79
+ }
80
+ }
81
+
82
+ @ Test
83
+ public void testIsNanUnsupported () {
84
+ List <String > testCases = ImmutableList .of ("'foo'.isNan()" );
85
+ for (String testCase : testCases ) {
86
+ Val val = eval (testCase ).getVal ();
87
+ assertThat (Err .isError (val )).isTrue ();
88
+ assertThatThrownBy (() -> val .convertToNative (Exception .class ))
89
+ .isInstanceOf (UnsupportedOperationException .class );
90
+ }
91
+ }
92
+
93
+ @ Test
94
+ public void testUnique () {
95
+ Map <String , Boolean > testCases =
96
+ ImmutableMap .<String , Boolean >builder ()
97
+ .put ("[].unique()" , true )
98
+ .put ("[true].unique()" , true )
99
+ .put ("[true, false].unique()" , true )
100
+ .put ("[true, true].unique()" , false )
101
+ .put ("[1, 2, 3].unique()" , true )
102
+ .put ("[1, 2, 1].unique()" , false )
103
+ .put ("[1u, 2u, 3u].unique()" , true )
104
+ .put ("[1u, 2u, 2u].unique()" , false )
105
+ .put ("[1.0, 2.0, 3.0].unique()" , true )
106
+ .put ("[3.0,2.0,3.0].unique()" , false )
107
+ .put ("['abc', 'def'].unique()" , true )
108
+ .put ("['abc', 'abc'].unique()" , false )
109
+ .put ("[b'abc', b'123'].unique()" , true )
110
+ .put ("[b'123', b'123'].unique()" , false )
111
+ // Previously, the unique() method returned false here as both bytes were converted
112
+ // to UTF-8. Since both contain invalid UTF-8, this would lead to them treated as equal
113
+ // because they'd have the same substitution character.
114
+ .put ("[b'\\ xFF', b'\\ xFE'].unique()" , true )
115
+ .build ();
116
+ for (Map .Entry <String , Boolean > testCase : testCases .entrySet ()) {
117
+ Program .EvalResult result = eval (testCase .getKey ());
118
+ assertThat (result .getVal ().booleanValue ()).isEqualTo (testCase .getValue ());
119
+ }
120
+ }
121
+
122
+ @ Test
123
+ public void testUniqueUnsupported () {
124
+ List <String > testCases = ImmutableList .of ("1.unique()" );
125
+ for (String testCase : testCases ) {
126
+ Program .EvalResult result = eval (testCase );
127
+ Val val = result .getVal ();
128
+ assertThat (Err .isError (val )).isTrue ();
129
+ assertThatThrownBy (() -> val .convertToNative (Exception .class ))
130
+ .isInstanceOf (UnsupportedOperationException .class );
131
+ }
132
+ }
133
+
134
+ @ Test
135
+ public void testIsIpPrefix () {
136
+ Map <String , Boolean > testCases =
137
+ ImmutableMap .<String , Boolean >builder ()
138
+ .put ("'1.2.3.0/24'.isIpPrefix()" , true )
139
+ .put ("'1.2.3.4/24'.isIpPrefix()" , true )
140
+ .put ("'1.2.3.0/24'.isIpPrefix(true)" , true )
141
+ .put ("'1.2.3.4/24'.isIpPrefix(true)" , false )
142
+ .put ("'fd7a:115c:a1e0:ab12:4843:cd96:626b:4000/118'.isIpPrefix()" , true )
143
+ .put ("'fd7a:115c:a1e0:ab12:4843:cd96:626b:430b/118'.isIpPrefix()" , true )
144
+ .put ("'fd7a:115c:a1e0:ab12:4843:cd96:626b:4000/118'.isIpPrefix(true)" , true )
145
+ .put ("'fd7a:115c:a1e0:ab12:4843:cd96:626b:430b/118'.isIpPrefix(true)" , false )
146
+ .put ("'1.2.3.4'.isIpPrefix()" , false )
147
+ .put ("'fd7a:115c:a1e0:ab12:4843:cd96:626b:430b'.isIpPrefix()" , false )
148
+ .put ("'1.2.3.0/24'.isIpPrefix(4)" , true )
149
+ .put ("'1.2.3.4/24'.isIpPrefix(4)" , true )
150
+ .put ("'1.2.3.0/24'.isIpPrefix(4,true)" , true )
151
+ .put ("'1.2.3.4/24'.isIpPrefix(4,true)" , false )
152
+ .put ("'fd7a:115c:a1e0:ab12:4843:cd96:626b:4000/118'.isIpPrefix(4)" , false )
153
+ .put ("'fd7a:115c:a1e0:ab12:4843:cd96:626b:4000/118'.isIpPrefix(6)" , true )
154
+ .put ("'fd7a:115c:a1e0:ab12:4843:cd96:626b:430b/118'.isIpPrefix(6)" , true )
155
+ .put ("'fd7a:115c:a1e0:ab12:4843:cd96:626b:4000/118'.isIpPrefix(6,true)" , true )
156
+ .put ("'fd7a:115c:a1e0:ab12:4843:cd96:626b:430b/118'.isIpPrefix(6,true)" , false )
157
+ .put ("'1.2.3.0/24'.isIpPrefix(6)" , false )
158
+ .build ();
159
+ for (Map .Entry <String , Boolean > testCase : testCases .entrySet ()) {
160
+ Program .EvalResult result = eval (testCase .getKey ());
161
+ assertThat (result .getVal ().booleanValue ()).isEqualTo (testCase .getValue ());
162
+ }
163
+ }
164
+
165
+ @ Test
166
+ public void testIsIpPrefixUnsupported () {
167
+ List <String > testCases =
168
+ ImmutableList .of (
169
+ "1.isIpPrefix()" ,
170
+ "'1.2.3.0/24'.isIpPrefix('foo')" ,
171
+ "'1.2.3.0/24'.isIpPrefix(4,'foo')" ,
172
+ "'1.2.3.0/24'.isIpPrefix('foo',true)" );
173
+ for (String testCase : testCases ) {
174
+ Program .EvalResult result = eval (testCase );
175
+ Val val = result .getVal ();
176
+ assertThat (Err .isError (val )).isTrue ();
177
+ assertThatThrownBy (() -> val .convertToNative (Exception .class ))
178
+ .isInstanceOf (UnsupportedOperationException .class );
179
+ }
180
+ }
181
+
182
+ @ Test
183
+ public void testIsHostname () {
184
+ Map <String , Boolean > testCases =
185
+ ImmutableMap .<String , Boolean >builder ()
186
+ .put ("'example.com'.isHostname()" , true )
187
+ .put ("'example.123'.isHostname()" , false )
188
+ .build ();
189
+ for (Map .Entry <String , Boolean > testCase : testCases .entrySet ()) {
190
+ Program .EvalResult result = eval (testCase .getKey ());
191
+ assertThat (result .getVal ().booleanValue ())
192
+ .as (
193
+ "expected %s=%s, got=%s" ,
194
+ testCase .getKey (), testCase .getValue (), !testCase .getValue ())
195
+ .isEqualTo (testCase .getValue ());
196
+ }
197
+ }
198
+
199
+ @ Test
200
+ public void testIsEmail () {
201
+ Map <String , Boolean > testCases =
202
+ ImmutableMap .<String , Boolean >builder ()
203
+ .
put (
"'[email protected] '.isEmail()" ,
true )
204
+ .
put (
"'<[email protected] >'.isEmail()" ,
false )
205
+ .
put (
"' [email protected] '.isEmail()" ,
false )
206
+ .
put (
"'[email protected] '.isEmail()" ,
false )
207
+ .build ();
208
+ for (Map .Entry <String , Boolean > testCase : testCases .entrySet ()) {
209
+ Program .EvalResult result = eval (testCase .getKey ());
210
+ assertThat (result .getVal ().booleanValue ())
211
+ .as (
212
+ "expected %s=%s, got=%s" ,
213
+ testCase .getKey (), testCase .getValue (), !testCase .getValue ())
214
+ .isEqualTo (testCase .getValue ());
215
+ }
216
+ }
222
217
223
218
private Program .EvalResult eval (String source ) {
224
219
return eval (source , Activation .emptyActivation ());
0 commit comments