Debian Codegraph @

tests/core/variant/test_variant.h

raw symbols SCIP
1 /**************************************************************************/
2 /* test_variant.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "core/variant/variant.h"
34 #include "core/variant/variant_parser.h"
35
36 #include "tests/test_macros.h"
37
38 namespace TestVariant {
39 TEST_CASE("[Variant] Writer and parser integer") {
40 int64_t a32 = 2147483648; // 2^31, so out of bounds for 32-bit signed int [-2^31, +2^31-1].
41 String a32_str;
42 VariantWriter::write_to_string(a32, a32_str);
43
44 CHECK_MESSAGE(a32_str != "-2147483648", "Should not wrap around");
45
46 int64_t b64 = 9223372036854775807; // 2^63-1, upper bound for signed 64-bit int.
47 String b64_str;
48 VariantWriter::write_to_string(b64, b64_str);
49
50 CHECK_MESSAGE(b64_str == "9223372036854775807", "Should not wrap around.");
51
52 VariantParser::StreamString ss;
53 String errs;
54 int line;
55 Variant b64_parsed;
56 int64_t b64_int_parsed;
57
58 ss.s = b64_str;
59 VariantParser::parse(&ss, b64_parsed, errs, line);
60 b64_int_parsed = b64_parsed;
61
62 CHECK_MESSAGE(b64_int_parsed == 9223372036854775807, "Should parse back.");
63
64 ss.s = "9223372036854775808"; // Overflowed by one.
65 VariantParser::parse(&ss, b64_parsed, errs, line);
66 b64_int_parsed = b64_parsed;
67
68 CHECK_MESSAGE(b64_int_parsed == 9223372036854775807, "The result should be clamped to max value.");
69
70 ss.s = "1e100"; // Googol! Scientific notation.
71 VariantParser::parse(&ss, b64_parsed, errs, line);
72 b64_int_parsed = b64_parsed;
73
74 CHECK_MESSAGE(b64_int_parsed == 9223372036854775807, "The result should be clamped to max value.");
75 }
76
77 TEST_CASE("[Variant] Writer and parser Variant::FLOAT") {
78 // Variant::FLOAT is always 64-bit (C++ double).
79 // This is the maximum non-infinity double-precision float.
80 double a64 = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;
81 String a64_str;
82 VariantWriter::write_to_string(a64, a64_str);
83
84 CHECK_MESSAGE(a64_str == "1.7976931348623157e+308", "Writes in scientific notation.");
85 CHECK_MESSAGE(a64_str != "inf", "Should not overflow.");
86 CHECK_MESSAGE(a64_str != "nan", "The result should be defined.");
87
88 String errs;
89 int line;
90 Variant variant_parsed;
91 double float_parsed;
92
93 VariantParser::StreamString bss;
94 bss.s = a64_str;
95 VariantParser::parse(&bss, variant_parsed, errs, line);
96 float_parsed = variant_parsed;
97 // Loses precision, but that's alright.
98 CHECK_MESSAGE(float_parsed == 1.797693134862315708145274237317e+308, "Should parse back.");
99
100 // Approximation of Googol with a double-precision float.
101 VariantParser::StreamString css;
102 css.s = "1.0e+100";
103 VariantParser::parse(&css, variant_parsed, errs, line);
104 float_parsed = variant_parsed;
105 CHECK_MESSAGE(float_parsed == 1.0e+100, "Should match the double literal.");
106 }
107
108 TEST_CASE("[Variant] Assignment To Bool from Int,Float,String,Vec2,Vec2i,Vec3,Vec3i,Vec4,Vec4i,Rect2,Rect2i,Trans2d,Trans3d,Color,Call,Plane,Basis,AABB,Quant,Proj,RID,and Object") {
109 Variant int_v = 0;
110 Variant bool_v = true;
111 int_v = bool_v; // int_v is now a bool
112 CHECK(int_v == Variant(true));
113 bool_v = false;
114 int_v = bool_v;
115 CHECK(int_v.get_type() == Variant::BOOL);
116
117 Variant float_v = 0.0f;
118 bool_v = true;
119 float_v = bool_v;
120 CHECK(float_v == Variant(true));
121 bool_v = false;
122 float_v = bool_v;
123 CHECK(float_v.get_type() == Variant::BOOL);
124
125 Variant string_v = "";
126 bool_v = true;
127 string_v = bool_v;
128 CHECK(string_v == Variant(true));
129 bool_v = false;
130 string_v = bool_v;
131 CHECK(string_v.get_type() == Variant::BOOL);
132
133 Variant vec2_v = Vector2(0, 0);
134 bool_v = true;
135 vec2_v = bool_v;
136 CHECK(vec2_v == Variant(true));
137 bool_v = false;
138 vec2_v = bool_v;
139 CHECK(vec2_v.get_type() == Variant::BOOL);
140
141 Variant vec2i_v = Vector2i(0, 0);
142 bool_v = true;
143 vec2i_v = bool_v;
144 CHECK(vec2i_v == Variant(true));
145 bool_v = false;
146 vec2i_v = bool_v;
147 CHECK(vec2i_v.get_type() == Variant::BOOL);
148
149 Variant vec3_v = Vector3(0, 0, 0);
150 bool_v = true;
151 vec3_v = bool_v;
152 CHECK(vec3_v == Variant(true));
153 bool_v = false;
154 vec3_v = bool_v;
155 CHECK(vec3_v.get_type() == Variant::BOOL);
156
157 Variant vec3i_v = Vector3i(0, 0, 0);
158 bool_v = true;
159 vec3i_v = bool_v;
160 CHECK(vec3i_v == Variant(true));
161 bool_v = false;
162 vec3i_v = bool_v;
163 CHECK(vec3i_v.get_type() == Variant::BOOL);
164
165 Variant vec4_v = Vector4(0, 0, 0, 0);
166 bool_v = true;
167 vec4_v = bool_v;
168 CHECK(vec4_v == Variant(true));
169 bool_v = false;
170 vec4_v = bool_v;
171 CHECK(vec4_v.get_type() == Variant::BOOL);
172
173 Variant vec4i_v = Vector4i(0, 0, 0, 0);
174 bool_v = true;
175 vec4i_v = bool_v;
176 CHECK(vec4i_v == Variant(true));
177 bool_v = false;
178 vec4i_v = bool_v;
179 CHECK(vec4i_v.get_type() == Variant::BOOL);
180
181 Variant rect2_v = Rect2();
182 bool_v = true;
183 rect2_v = bool_v;
184 CHECK(rect2_v == Variant(true));
185 bool_v = false;
186 rect2_v = bool_v;
187 CHECK(rect2_v.get_type() == Variant::BOOL);
188
189 Variant rect2i_v = Rect2i();
190 bool_v = true;
191 rect2i_v = bool_v;
192 CHECK(rect2i_v == Variant(true));
193 bool_v = false;
194 rect2i_v = bool_v;
195 CHECK(rect2i_v.get_type() == Variant::BOOL);
196
197 Variant transform2d_v = Transform2D();
198 bool_v = true;
199 transform2d_v = bool_v;
200 CHECK(transform2d_v == Variant(true));
201 bool_v = false;
202 transform2d_v = bool_v;
203 CHECK(transform2d_v.get_type() == Variant::BOOL);
204
205 Variant transform3d_v = Transform3D();
206 bool_v = true;
207 transform3d_v = bool_v;
208 CHECK(transform3d_v == Variant(true));
209 bool_v = false;
210 transform3d_v = bool_v;
211 CHECK(transform3d_v.get_type() == Variant::BOOL);
212
213 Variant col_v = Color(0.5f, 0.2f, 0.75f);
214 bool_v = true;
215 col_v = bool_v;
216 CHECK(col_v == Variant(true));
217 bool_v = false;
218 col_v = bool_v;
219 CHECK(col_v.get_type() == Variant::BOOL);
220
221 Variant call_v = Callable();
222 bool_v = true;
223 call_v = bool_v;
224 CHECK(call_v == Variant(true));
225 bool_v = false;
226 call_v = bool_v;
227 CHECK(call_v.get_type() == Variant::BOOL);
228
229 Variant plane_v = Plane();
230 bool_v = true;
231 plane_v = bool_v;
232 CHECK(plane_v == Variant(true));
233 bool_v = false;
234 plane_v = bool_v;
235 CHECK(plane_v.get_type() == Variant::BOOL);
236
237 Variant basis_v = Basis();
238 bool_v = true;
239 basis_v = bool_v;
240 CHECK(basis_v == Variant(true));
241 bool_v = false;
242 basis_v = bool_v;
243 CHECK(basis_v.get_type() == Variant::BOOL);
244
245 Variant aabb_v = AABB();
246 bool_v = true;
247 aabb_v = bool_v;
248 CHECK(aabb_v == Variant(true));
249 bool_v = false;
250 aabb_v = bool_v;
251 CHECK(aabb_v.get_type() == Variant::BOOL);
252
253 Variant quaternion_v = Quaternion();
254 bool_v = true;
255 quaternion_v = bool_v;
256 CHECK(quaternion_v == Variant(true));
257 bool_v = false;
258 quaternion_v = bool_v;
259 CHECK(quaternion_v.get_type() == Variant::BOOL);
260
261 Variant projection_v = Projection();
262 bool_v = true;
263 projection_v = bool_v;
264 CHECK(projection_v == Variant(true));
265 bool_v = false;
266 projection_v = bool_v;
267 CHECK(projection_v.get_type() == Variant::BOOL);
268
269 Variant rid_v = RID();
270 bool_v = true;
271 rid_v = bool_v;
272 CHECK(rid_v == Variant(true));
273 bool_v = false;
274 rid_v = bool_v;
275 CHECK(rid_v.get_type() == Variant::BOOL);
276
277 Object obj_one = Object();
278 Variant object_v = &obj_one;
279 bool_v = true;
280 object_v = bool_v;
281 CHECK(object_v == Variant(true));
282 bool_v = false;
283 object_v = bool_v;
284 CHECK(object_v.get_type() == Variant::BOOL);
285 }
286
287 TEST_CASE("[Variant] Assignment To Int from Bool,Float,String,Vec2,Vec2i,Vec3,Vec3i Vec4,Vec4i,Rect2,Rect2i,Trans2d,Trans3d,Color,Call,Plane,Basis,AABB,Quant,Proj,RID,and Object") {
288 Variant bool_v = false;
289 Variant int_v = 2;
290 bool_v = int_v; // Now bool_v is int
291 CHECK(bool_v == Variant(2));
292 int_v = -3;
293 bool_v = int_v;
294 CHECK(bool_v.get_type() == Variant::INT);
295
296 Variant float_v = 0.0f;
297 int_v = 2;
298 float_v = int_v;
299 CHECK(float_v == Variant(2));
300 int_v = -3;
301 float_v = int_v;
302 CHECK(float_v.get_type() == Variant::INT);
303
304 Variant string_v = "";
305 int_v = 2;
306 string_v = int_v;
307 CHECK(string_v == Variant(2));
308 int_v = -3;
309 string_v = int_v;
310 CHECK(string_v.get_type() == Variant::INT);
311
312 Variant vec2_v = Vector2(0, 0);
313 int_v = 2;
314 vec2_v = int_v;
315 CHECK(vec2_v == Variant(2));
316 int_v = -3;
317 vec2_v = int_v;
318 CHECK(vec2_v.get_type() == Variant::INT);
319
320 Variant vec2i_v = Vector2i(0, 0);
321 int_v = 2;
322 vec2i_v = int_v;
323 CHECK(vec2i_v == Variant(2));
324 int_v = -3;
325 vec2i_v = int_v;
326 CHECK(vec2i_v.get_type() == Variant::INT);
327
328 Variant vec3_v = Vector3(0, 0, 0);
329 int_v = 2;
330 vec3_v = int_v;
331 CHECK(vec3_v == Variant(2));
332 int_v = -3;
333 vec3_v = int_v;
334 CHECK(vec3_v.get_type() == Variant::INT);
335
336 Variant vec3i_v = Vector3i(0, 0, 0);
337 int_v = 2;
338 vec3i_v = int_v;
339 CHECK(vec3i_v == Variant(2));
340 int_v = -3;
341 vec3i_v = int_v;
342 CHECK(vec3i_v.get_type() == Variant::INT);
343
344 Variant vec4_v = Vector4(0, 0, 0, 0);
345 int_v = 2;
346 vec4_v = int_v;
347 CHECK(vec4_v == Variant(2));
348 int_v = -3;
349 vec4_v = int_v;
350 CHECK(vec4_v.get_type() == Variant::INT);
351
352 Variant vec4i_v = Vector4i(0, 0, 0, 0);
353 int_v = 2;
354 vec4i_v = int_v;
355 CHECK(vec4i_v == Variant(2));
356 int_v = -3;
357 vec4i_v = int_v;
358 CHECK(vec4i_v.get_type() == Variant::INT);
359
360 Variant rect2_v = Rect2();
361 int_v = 2;
362 rect2_v = int_v;
363 CHECK(rect2_v == Variant(2));
364 int_v = -3;
365 rect2_v = int_v;
366 CHECK(rect2_v.get_type() == Variant::INT);
367
368 Variant rect2i_v = Rect2i();
369 int_v = 2;
370 rect2i_v = int_v;
371 CHECK(rect2i_v == Variant(2));
372 int_v = -3;
373 rect2i_v = int_v;
374 CHECK(rect2i_v.get_type() == Variant::INT);
375
376 Variant transform2d_v = Transform2D();
377 int_v = 2;
378 transform2d_v = int_v;
379 CHECK(transform2d_v == Variant(2));
380 int_v = -3;
381 transform2d_v = int_v;
382 CHECK(transform2d_v.get_type() == Variant::INT);
383
384 Variant transform3d_v = Transform3D();
385 int_v = 2;
386 transform3d_v = int_v;
387 CHECK(transform3d_v == Variant(2));
388 int_v = -3;
389 transform3d_v = int_v;
390 CHECK(transform3d_v.get_type() == Variant::INT);
391
392 Variant col_v = Color(0.5f, 0.2f, 0.75f);
393 int_v = 2;
394 col_v = int_v;
395 CHECK(col_v == Variant(2));
396 int_v = -3;
397 col_v = int_v;
398 CHECK(col_v.get_type() == Variant::INT);
399
400 Variant call_v = Callable();
401 int_v = 2;
402 call_v = int_v;
403 CHECK(call_v == Variant(2));
404 int_v = -3;
405 call_v = int_v;
406 CHECK(call_v.get_type() == Variant::INT);
407
408 Variant plane_v = Plane();
409 int_v = 2;
410 plane_v = int_v;
411 CHECK(plane_v == Variant(2));
412 int_v = -3;
413 plane_v = int_v;
414 CHECK(plane_v.get_type() == Variant::INT);
415
416 Variant basis_v = Basis();
417 int_v = 2;
418 basis_v = int_v;
419 CHECK(basis_v == Variant(2));
420 int_v = -3;
421 basis_v = int_v;
422 CHECK(basis_v.get_type() == Variant::INT);
423
424 Variant aabb_v = AABB();
425 int_v = 2;
426 aabb_v = int_v;
427 CHECK(aabb_v == Variant(2));
428 int_v = -3;
429 aabb_v = int_v;
430 CHECK(aabb_v.get_type() == Variant::INT);
431
432 Variant quaternion_v = Quaternion();
433 int_v = 2;
434 quaternion_v = int_v;
435 CHECK(quaternion_v == Variant(2));
436 int_v = -3;
437 quaternion_v = int_v;
438 CHECK(quaternion_v.get_type() == Variant::INT);
439
440 Variant projection_v = Projection();
441 int_v = 2;
442 projection_v = int_v;
443 CHECK(projection_v == Variant(2));
444 int_v = -3;
445 projection_v = int_v;
446 CHECK(projection_v.get_type() == Variant::INT);
447
448 Variant rid_v = RID();
449 int_v = 2;
450 rid_v = int_v;
451 CHECK(rid_v == Variant(2));
452 bool_v = -3;
453 rid_v = int_v;
454 CHECK(rid_v.get_type() == Variant::INT);
455
456 Object obj_one = Object();
457 Variant object_v = &obj_one;
458 int_v = 2;
459 object_v = int_v;
460 CHECK(object_v == Variant(2));
461 int_v = -3;
462 object_v = int_v;
463 CHECK(object_v.get_type() == Variant::INT);
464 }
465
466 TEST_CASE("[Variant] Assignment To Float from Bool,Int,String,Vec2,Vec2i,Vec3,Vec3i,Vec4,Vec4i,Rect2,Rect2i,Trans2d,Trans3d,Color,Call,Plane,Basis,AABB,Quant,Proj,RID,and Object") {
467 Variant bool_v = false;
468 Variant float_v = 1.5f;
469 bool_v = float_v; // Now bool_v is float
470 CHECK(bool_v == Variant(1.5f));
471 float_v = -4.6f;
472 bool_v = float_v;
473 CHECK(bool_v.get_type() == Variant::FLOAT);
474
475 Variant int_v = 1;
476 float_v = 1.5f;
477 int_v = float_v;
478 CHECK(int_v == Variant(1.5f));
479 float_v = -4.6f;
480 int_v = float_v;
481 CHECK(int_v.get_type() == Variant::FLOAT);
482
483 Variant string_v = "";
484 float_v = 1.5f;
485 string_v = float_v;
486 CHECK(string_v == Variant(1.5f));
487 float_v = -4.6f;
488 string_v = float_v;
489 CHECK(string_v.get_type() == Variant::FLOAT);
490
491 Variant vec2_v = Vector2(0, 0);
492 float_v = 1.5f;
493 vec2_v = float_v;
494 CHECK(vec2_v == Variant(1.5f));
495 float_v = -4.6f;
496 vec2_v = float_v;
497 CHECK(vec2_v.get_type() == Variant::FLOAT);
498
499 Variant vec2i_v = Vector2i(0, 0);
500 float_v = 1.5f;
501 vec2i_v = float_v;
502 CHECK(vec2i_v == Variant(1.5f));
503 float_v = -4.6f;
504 vec2i_v = float_v;
505 CHECK(vec2i_v.get_type() == Variant::FLOAT);
506
507 Variant vec3_v = Vector3(0, 0, 0);
508 float_v = 1.5f;
509 vec3_v = float_v;
510 CHECK(vec3_v == Variant(1.5f));
511 float_v = -4.6f;
512 vec3_v = float_v;
513 CHECK(vec3_v.get_type() == Variant::FLOAT);
514
515 Variant vec3i_v = Vector3i(0, 0, 0);
516 float_v = 1.5f;
517 vec3i_v = float_v;
518 CHECK(vec3i_v == Variant(1.5f));
519 float_v = -4.6f;
520 vec3i_v = float_v;
521 CHECK(vec3i_v.get_type() == Variant::FLOAT);
522
523 Variant vec4_v = Vector4(0, 0, 0, 0);
524 float_v = 1.5f;
525 vec4_v = float_v;
526 CHECK(vec4_v == Variant(1.5f));
527 float_v = -4.6f;
528 vec4_v = float_v;
529 CHECK(vec4_v.get_type() == Variant::FLOAT);
530
531 Variant vec4i_v = Vector4i(0, 0, 0, 0);
532 float_v = 1.5f;
533 vec4i_v = float_v;
534 CHECK(vec4i_v == Variant(1.5f));
535 float_v = -4.6f;
536 vec4i_v = float_v;
537 CHECK(vec4i_v.get_type() == Variant::FLOAT);
538
539 Variant rect2_v = Rect2();
540 float_v = 1.5f;
541 rect2_v = float_v;
542 CHECK(rect2_v == Variant(1.5f));
543 float_v = -4.6f;
544 rect2_v = float_v;
545 CHECK(rect2_v.get_type() == Variant::FLOAT);
546
547 Variant rect2i_v = Rect2i();
548 float_v = 1.5f;
549 rect2i_v = float_v;
550 CHECK(rect2i_v == Variant(1.5f));
551 float_v = -4.6f;
552 rect2i_v = float_v;
553 CHECK(rect2i_v.get_type() == Variant::FLOAT);
554
555 Variant transform2d_v = Transform2D();
556 float_v = 1.5f;
557 transform2d_v = float_v;
558 CHECK(transform2d_v == Variant(1.5f));
559 float_v = -4.6f;
560 transform2d_v = float_v;
561 CHECK(transform2d_v.get_type() == Variant::FLOAT);
562
563 Variant transform3d_v = Transform3D();
564 float_v = 1.5f;
565 transform3d_v = float_v;
566 CHECK(transform3d_v == Variant(1.5f));
567 float_v = -4.6f;
568 transform3d_v = float_v;
569 CHECK(transform2d_v.get_type() == Variant::FLOAT);
570
571 Variant col_v = Color(0.5f, 0.2f, 0.75f);
572 float_v = 1.5f;
573 col_v = float_v;
574 CHECK(col_v == Variant(1.5f));
575 float_v = -4.6f;
576 col_v = float_v;
577 CHECK(col_v.get_type() == Variant::FLOAT);
578
579 Variant call_v = Callable();
580 float_v = 1.5f;
581 call_v = float_v;
582 CHECK(call_v == Variant(1.5f));
583 float_v = -4.6f;
584 call_v = float_v;
585 CHECK(call_v.get_type() == Variant::FLOAT);
586
587 Variant plane_v = Plane();
588 float_v = 1.5f;
589 plane_v = float_v;
590 CHECK(plane_v == Variant(1.5f));
591 float_v = -4.6f;
592 plane_v = float_v;
593 CHECK(plane_v.get_type() == Variant::FLOAT);
594
595 Variant basis_v = Basis();
596 float_v = 1.5f;
597 basis_v = float_v;
598 CHECK(basis_v == Variant(1.5f));
599 float_v = -4.6f;
600 basis_v = float_v;
601 CHECK(basis_v.get_type() == Variant::FLOAT);
602
603 Variant aabb_v = AABB();
604 float_v = 1.5f;
605 aabb_v = float_v;
606 CHECK(aabb_v == Variant(1.5f));
607 float_v = -4.6f;
608 aabb_v = float_v;
609 CHECK(aabb_v.get_type() == Variant::FLOAT);
610
611 Variant quaternion_v = Quaternion();
612 float_v = 1.5f;
613 quaternion_v = float_v;
614 CHECK(quaternion_v == Variant(1.5f));
615 float_v = -4.6f;
616 quaternion_v = float_v;
617 CHECK(quaternion_v.get_type() == Variant::FLOAT);
618
619 Variant projection_v = Projection();
620 float_v = 1.5f;
621 projection_v = float_v;
622 CHECK(projection_v == Variant(1.5f));
623 float_v = -4.6f;
624 projection_v = float_v;
625 CHECK(projection_v.get_type() == Variant::FLOAT);
626
627 Variant rid_v = RID();
628 float_v = 1.5f;
629 rid_v = float_v;
630 CHECK(rid_v == Variant(1.5f));
631 float_v = -4.6f;
632 rid_v = float_v;
633 CHECK(rid_v.get_type() == Variant::FLOAT);
634
635 Object obj_one = Object();
636 Variant object_v = &obj_one;
637 float_v = 1.5f;
638 object_v = float_v;
639 CHECK(object_v == Variant(1.5f));
640 float_v = -4.6f;
641 object_v = float_v;
642 CHECK(object_v.get_type() == Variant::FLOAT);
643 }
644
645 TEST_CASE("[Variant] Assignment To String from Bool,Int,Float,Vec2,Vec2i,Vec3,Vec3i,Vec4,Vec4i,Rect2,Rect2i,Trans2d,Trans3d,Color,Call,Plane,Basis,AABB,Quant,Proj,RID,and Object") {
646 Variant bool_v = false;
647 Variant string_v = "Hello";
648 bool_v = string_v; // Now bool_v is string
649 CHECK(bool_v == Variant("Hello"));
650 string_v = "Hello there";
651 bool_v = string_v;
652 CHECK(bool_v.get_type() == Variant::STRING);
653
654 Variant int_v = 0;
655 string_v = "Hello";
656 int_v = string_v;
657 CHECK(int_v == Variant("Hello"));
658 string_v = "Hello there";
659 int_v = string_v;
660 CHECK(int_v.get_type() == Variant::STRING);
661
662 Variant float_v = 0.0f;
663 string_v = "Hello";
664 float_v = string_v;
665 CHECK(float_v == Variant("Hello"));
666 string_v = "Hello there";
667 float_v = string_v;
668 CHECK(float_v.get_type() == Variant::STRING);
669
670 Variant vec2_v = Vector2(0, 0);
671 string_v = "Hello";
672 vec2_v = string_v;
673 CHECK(vec2_v == Variant("Hello"));
674 string_v = "Hello there";
675 vec2_v = string_v;
676 CHECK(vec2_v.get_type() == Variant::STRING);
677
678 Variant vec2i_v = Vector2i(0, 0);
679 string_v = "Hello";
680 vec2i_v = string_v;
681 CHECK(vec2i_v == Variant("Hello"));
682 string_v = "Hello there";
683 vec2i_v = string_v;
684 CHECK(vec2i_v.get_type() == Variant::STRING);
685
686 Variant vec3_v = Vector3(0, 0, 0);
687 string_v = "Hello";
688 vec3_v = string_v;
689 CHECK(vec3_v == Variant("Hello"));
690 string_v = "Hello there";
691 vec3_v = string_v;
692 CHECK(vec3_v.get_type() == Variant::STRING);
693
694 Variant vec3i_v = Vector3i(0, 0, 0);
695 string_v = "Hello";
696 vec3i_v = string_v;
697 CHECK(vec3i_v == Variant("Hello"));
698 string_v = "Hello there";
699 vec3i_v = string_v;
700 CHECK(vec3i_v.get_type() == Variant::STRING);
701
702 Variant vec4_v = Vector4(0, 0, 0, 0);
703 string_v = "Hello";
704 vec4_v = string_v;
705 CHECK(vec4_v == Variant("Hello"));
706 string_v = "Hello there";
707 vec4_v = string_v;
708 CHECK(vec4_v.get_type() == Variant::STRING);
709
710 Variant vec4i_v = Vector4i(0, 0, 0, 0);
711 string_v = "Hello";
712 vec4i_v = string_v;
713 CHECK(vec4i_v == Variant("Hello"));
714 string_v = "Hello there";
715 vec4i_v = string_v;
716 CHECK(vec4i_v.get_type() == Variant::STRING);
717
718 Variant rect2_v = Rect2();
719 string_v = "Hello";
720 rect2_v = string_v;
721 CHECK(rect2_v == Variant("Hello"));
722 string_v = "Hello there";
723 rect2_v = string_v;
724 CHECK(rect2_v.get_type() == Variant::STRING);
725
726 Variant rect2i_v = Rect2i();
727 string_v = "Hello";
728 rect2i_v = string_v;
729 CHECK(rect2i_v == Variant("Hello"));
730 string_v = "Hello there";
731 rect2i_v = string_v;
732 CHECK(rect2i_v.get_type() == Variant::STRING);
733
734 Variant transform2d_v = Transform2D();
735 string_v = "Hello";
736 transform2d_v = string_v;
737 CHECK(transform2d_v == Variant("Hello"));
738 string_v = "Hello there";
739 transform2d_v = string_v;
740 CHECK(transform2d_v.get_type() == Variant::STRING);
741
742 Variant transform3d_v = Transform3D();
743 string_v = "Hello";
744 transform3d_v = string_v;
745 CHECK(transform3d_v == Variant("Hello"));
746 string_v = "Hello there";
747 transform3d_v = string_v;
748 CHECK(transform3d_v.get_type() == Variant::STRING);
749
750 Variant col_v = Color(0.5f, 0.2f, 0.75f);
751 string_v = "Hello";
752 col_v = string_v;
753 CHECK(col_v == Variant("Hello"));
754 string_v = "Hello there";
755 col_v = string_v;
756 CHECK(col_v.get_type() == Variant::STRING);
757
758 Variant call_v = Callable();
759 string_v = "Hello";
760 call_v = string_v;
761 CHECK(call_v == Variant("Hello"));
762 string_v = "Hello there";
763 call_v = string_v;
764 CHECK(call_v.get_type() == Variant::STRING);
765
766 Variant plane_v = Plane();
767 string_v = "Hello";
768 plane_v = string_v;
769 CHECK(plane_v == Variant("Hello"));
770 string_v = "Hello there";
771 plane_v = string_v;
772 CHECK(plane_v.get_type() == Variant::STRING);
773
774 Variant basis_v = Basis();
775 string_v = "Hello";
776 basis_v = string_v;
777 CHECK(basis_v == Variant("Hello"));
778 string_v = "Hello there";
779 basis_v = string_v;
780 CHECK(basis_v.get_type() == Variant::STRING);
781
782 Variant aabb_v = AABB();
783 string_v = "Hello";
784 aabb_v = string_v;
785 CHECK(aabb_v == Variant("Hello"));
786 string_v = "Hello there";
787 aabb_v = string_v;
788 CHECK(aabb_v.get_type() == Variant::STRING);
789
790 Variant quaternion_v = Quaternion();
791 string_v = "Hello";
792 quaternion_v = string_v;
793 CHECK(quaternion_v == Variant("Hello"));
794 string_v = "Hello there";
795 quaternion_v = string_v;
796 CHECK(quaternion_v.get_type() == Variant::STRING);
797
798 Variant projection_v = Projection();
799 string_v = "Hello";
800 projection_v = string_v;
801 CHECK(projection_v == Variant("Hello"));
802 string_v = "Hello there";
803 projection_v = string_v;
804 CHECK(projection_v.get_type() == Variant::STRING);
805
806 Variant rid_v = RID();
807 string_v = "Hello";
808 rid_v = string_v;
809 CHECK(rid_v == Variant("Hello"));
810 string_v = "Hello there";
811 rid_v = string_v;
812 CHECK(rid_v.get_type() == Variant::STRING);
813
814 Object obj_one = Object();
815 Variant object_v = &obj_one;
816 string_v = "Hello";
817 object_v = string_v;
818 CHECK(object_v == Variant("Hello"));
819 string_v = "Hello there";
820 object_v = string_v;
821 CHECK(object_v.get_type() == Variant::STRING);
822 }
823
824 TEST_CASE("[Variant] Assignment To Vec2 from Bool,Int,Float,String,Vec2i,Vec3,Vec3i,Vec4,Vec4i,Rect2,Rect2i,Trans2d,Trans3d,Color,Call,Plane,Basis,AABB,Quant,Proj,RID,and Object") {
825 Variant bool_v = false;
826 Variant vec2_v = Vector2(2.2f, 3.5f);
827 bool_v = vec2_v; // Now bool_v is Vector2
828 CHECK(bool_v == Variant(Vector2(2.2f, 3.5f)));
829 vec2_v = Vector2(-5.4f, -7.9f);
830 bool_v = vec2_v;
831 CHECK(bool_v.get_type() == Variant::VECTOR2);
832
833 Variant int_v = 0;
834 vec2_v = Vector2(2.2f, 3.5f);
835 int_v = vec2_v;
836 CHECK(int_v == Variant(Vector2(2.2f, 3.5f)));
837 vec2_v = Vector2(-5.4f, -7.9f);
838 int_v = vec2_v;
839 CHECK(int_v.get_type() == Variant::VECTOR2);
840
841 Variant float_v = 0.0f;
842 vec2_v = Vector2(2.2f, 3.5f);
843 float_v = vec2_v;
844 CHECK(float_v == Variant(Vector2(2.2f, 3.5f)));
845 vec2_v = Vector2(-5.4f, -7.9f);
846 float_v = vec2_v;
847 CHECK(float_v.get_type() == Variant::VECTOR2);
848
849 Variant string_v = "";
850 vec2_v = Vector2(2.2f, 3.5f);
851 string_v = vec2_v;
852 CHECK(string_v == Variant(Vector2(2.2f, 3.5f)));
853 vec2_v = Vector2(-5.4f, -7.9f);
854 string_v = vec2_v;
855 CHECK(string_v.get_type() == Variant::VECTOR2);
856
857 Variant vec2i_v = Vector2i(0, 0);
858 vec2_v = Vector2(2.2f, 3.5f);
859 vec2i_v = vec2_v;
860 CHECK(vec2i_v == Variant(Vector2(2.2f, 3.5f)));
861 vec2_v = Vector2(-5.4f, -7.9f);
862 vec2i_v = vec2_v;
863 CHECK(vec2i_v.get_type() == Variant::VECTOR2);
864
865 Variant vec3_v = Vector3(0, 0, 0);
866 vec2_v = Vector2(2.2f, 3.5f);
867 vec3_v = vec2_v;
868 CHECK(vec3_v == Variant(Vector2(2.2f, 3.5f)));
869 vec2_v = Vector2(-5.4f, -7.9f);
870 vec3_v = vec2_v;
871 CHECK(vec3_v.get_type() == Variant::VECTOR2);
872
873 Variant vec3i_v = Vector3i(0, 0, 0);
874 vec2_v = Vector2(2.2f, 3.5f);
875 vec3i_v = vec2_v;
876 CHECK(vec3i_v == Variant(Vector2(2.2f, 3.5f)));
877 vec2_v = Vector2(-5.4f, -7.9f);
878 vec3i_v = vec2_v;
879 CHECK(vec3i_v.get_type() == Variant::VECTOR2);
880
881 Variant vec4_v = Vector4(0, 0, 0, 0);
882 vec2_v = Vector2(2.2f, 3.5f);
883 vec4_v = vec2_v;
884 CHECK(vec4_v == Variant(Vector2(2.2f, 3.5f)));
885 vec2_v = Vector2(-5.4f, -7.9f);
886 vec4_v = vec2_v;
887 CHECK(vec4_v.get_type() == Variant::VECTOR2);
888
889 Variant vec4i_v = Vector4i(0, 0, 0, 0);
890 vec2_v = Vector2(2.2f, 3.5f);
891 vec4i_v = vec2_v;
892 CHECK(vec4i_v == Variant(Vector2(2.2f, 3.5f)));
893 vec2_v = Vector2(-5.4f, -7.9f);
894 vec4i_v = vec2_v;
895 CHECK(vec4i_v.get_type() == Variant::VECTOR2);
896
897 Variant rect2_v = Rect2();
898 vec2_v = Vector2(2.2f, 3.5f);
899 rect2_v = vec2_v;
900 CHECK(rect2_v == Variant(Vector2(2.2f, 3.5f)));
901 vec2_v = Vector2(-5.4f, -7.9f);
902 rect2_v = vec2_v;
903 CHECK(rect2_v.get_type() == Variant::VECTOR2);
904
905 Variant rect2i_v = Rect2i();
906 vec2_v = Vector2(2.2f, 3.5f);
907 rect2i_v = vec2_v;
908 CHECK(rect2i_v == Variant(Vector2(2.2f, 3.5f)));
909 vec2_v = Vector2(-5.4f, -7.9f);
910 rect2i_v = vec2_v;
911 CHECK(rect2i_v.get_type() == Variant::VECTOR2);
912
913 Variant transform2d_v = Transform2D();
914 vec2_v = Vector2(2.2f, 3.5f);
915 transform2d_v = vec2_v;
916 CHECK(transform2d_v == Variant(Vector2(2.2f, 3.5f)));
917 vec2_v = Vector2(-5.4f, -7.9f);
918 transform2d_v = vec2_v;
919 CHECK(transform2d_v.get_type() == Variant::VECTOR2);
920
921 Variant transform3d_v = Transform3D();
922 vec2_v = Vector2(2.2f, 3.5f);
923 transform3d_v = vec2_v;
924 CHECK(transform3d_v == Variant(Vector2(2.2f, 3.5f)));
925 vec2_v = Vector2(-5.4f, -7.9f);
926 transform3d_v = vec2_v;
927 CHECK(transform3d_v.get_type() == Variant::VECTOR2);
928
929 Variant col_v = Color(0.5f, 0.2f, 0.75f);
930 vec2_v = Vector2(2.2f, 3.5f);
931 col_v = vec2_v;
932 CHECK(col_v == Variant(Vector2(2.2f, 3.5f)));
933 vec2_v = Vector2(-5.4f, -7.9f);
934 col_v = vec2_v;
935 CHECK(col_v.get_type() == Variant::VECTOR2);
936
937 Variant call_v = Callable();
938 vec2_v = Vector2(2.2f, 3.5f);
939 call_v = vec2_v;
940 CHECK(call_v == Variant(Vector2(2.2f, 3.5f)));
941 vec2_v = Vector2(-5.4f, -7.9f);
942 call_v = vec2_v;
943 CHECK(call_v.get_type() == Variant::VECTOR2);
944
945 Variant plane_v = Plane();
946 vec2_v = Vector2(2.2f, 3.5f);
947 plane_v = vec2_v;
948 CHECK(plane_v == Variant(Vector2(2.2f, 3.5f)));
949 vec2_v = Vector2(-5.4f, -7.9f);
950 plane_v = vec2_v;
951 CHECK(plane_v.get_type() == Variant::VECTOR2);
952
953 Variant basis_v = Basis();
954 vec2_v = Vector2(2.2f, 3.5f);
955 basis_v = vec2_v;
956 CHECK(basis_v == Variant(Vector2(2.2f, 3.5f)));
957 vec2_v = Vector2(-5.4f, -7.9f);
958 basis_v = vec2_v;
959 CHECK(basis_v.get_type() == Variant::VECTOR2);
960
961 Variant aabb_v = AABB();
962 vec2_v = Vector2(2.2f, 3.5f);
963 aabb_v = vec2_v;
964 CHECK(aabb_v == Variant(Vector2(2.2f, 3.5f)));
965 vec2_v = Vector2(-5.4f, -7.9f);
966 aabb_v = vec2_v;
967 CHECK(aabb_v.get_type() == Variant::VECTOR2);
968
969 Variant quaternion_v = Quaternion();
970 vec2_v = Vector2(2.2f, 3.5f);
971 quaternion_v = vec2_v;
972 CHECK(quaternion_v == Variant(Vector2(2.2f, 3.5f)));
973 vec2_v = Vector2(-5.4f, -7.9f);
974 quaternion_v = vec2_v;
975 CHECK(quaternion_v.get_type() == Variant::VECTOR2);
976
977 Variant projection_v = Projection();
978 vec2_v = Vector2(2.2f, 3.5f);
979 projection_v = vec2_v;
980 CHECK(projection_v == Variant(Vector2(2.2f, 3.5f)));
981 vec2_v = Vector2(-5.4f, -7.9f);
982 projection_v = vec2_v;
983 CHECK(projection_v.get_type() == Variant::VECTOR2);
984
985 Variant rid_v = RID();
986 vec2_v = Vector2(2.2f, 3.5f);
987 rid_v = vec2_v;
988 CHECK(rid_v == Variant(Vector2(2.2f, 3.5f)));
989 vec2_v = Vector2(-5.4f, -7.9f);
990 rid_v = vec2_v;
991 CHECK(rid_v.get_type() == Variant::VECTOR2);
992
993 Object obj_one = Object();
994 Variant object_v = &obj_one;
995 vec2_v = Vector2(2.2f, 3.5f);
996 object_v = vec2_v;
997 CHECK(object_v == Variant(Vector2(2.2f, 3.5f)));
998 vec2_v = Vector2(-5.4f, -7.9f);
999 object_v = vec2_v;
1000 CHECK(object_v.get_type() == Variant::VECTOR2);
1001 }
1002
1003 TEST_CASE("[Variant] Assignment To Vec2i from Bool,Int,Float,String,Vec2,Vec3,Vec3i,Vec4,Vec4i,Rect2,Rect2i,Trans2d,Trans3d,Color,Call,Plane,Basis,AABB,Quant,Proj,RID,and Object") {
1004 Variant bool_v = false;
1005 Variant vec2i_v = Vector2i(2, 3);
1006 bool_v = vec2i_v; // Now bool_v is Vector2i
1007 CHECK(bool_v == Variant(Vector2i(2, 3)));
1008 vec2i_v = Vector2i(-5, -7);
1009 bool_v = vec2i_v;
1010 CHECK(bool_v.get_type() == Variant::VECTOR2I);
1011
1012 Variant int_v = 0;
1013 vec2i_v = Vector2i(2, 3);
1014 int_v = vec2i_v;
1015 CHECK(int_v == Variant(Vector2i(2, 3)));
1016 vec2i_v = Vector2i(-5, -7);
1017 int_v = vec2i_v;
1018 CHECK(int_v.get_type() == Variant::VECTOR2I);
1019
1020 Variant float_v = 0.0f;
1021 vec2i_v = Vector2i(2, 3);
1022 float_v = vec2i_v;
1023 CHECK(float_v == Variant(Vector2i(2, 3)));
1024 vec2i_v = Vector2i(-5, -7);
1025 float_v = vec2i_v;
1026 CHECK(float_v.get_type() == Variant::VECTOR2I);
1027
1028 Variant string_v = "";
1029 vec2i_v = Vector2i(2, 3);
1030 string_v = vec2i_v;
1031 CHECK(string_v == Variant(Vector2i(2, 3)));
1032 vec2i_v = Vector2i(-5, -7);
1033 string_v = vec2i_v;
1034 CHECK(string_v.get_type() == Variant::VECTOR2I);
1035
1036 Variant vec2_v = Vector2(0, 0);
1037 vec2i_v = Vector2i(2, 3);
1038 vec2_v = vec2i_v;
1039 CHECK(vec2_v == Variant(Vector2i(2, 3)));
1040 vec2i_v = Vector2i(-5, -7);
1041 vec2_v = vec2i_v;
1042 CHECK(vec2i_v.get_type() == Variant::VECTOR2I);
1043
1044 Variant vec3_v = Vector3(0, 0, 0);
1045 vec2i_v = Vector2i(2, 3);
1046 vec3_v = vec2i_v;
1047 CHECK(vec3_v == Variant(Vector2i(2, 3)));
1048 vec2i_v = Vector2i(-5, -7);
1049 vec3_v = vec2i_v;
1050 CHECK(vec3_v.get_type() == Variant::VECTOR2I);
1051
1052 Variant vec3i_v = Vector3i(0, 0, 0);
1053 vec2i_v = Vector2i(2, 3);
1054 vec3i_v = vec2i_v;
1055 CHECK(vec3i_v == Variant(Vector2i(2, 3)));
1056 vec2i_v = Vector2i(-5, -7);
1057 vec3i_v = vec2i_v;
1058 CHECK(vec3i_v.get_type() == Variant::VECTOR2I);
1059
1060 Variant vec4_v = Vector4(0, 0, 0, 0);
1061 vec2i_v = Vector2i(2, 3);
1062 vec4_v = vec2i_v;
1063 CHECK(vec4_v == Variant(Vector2i(2, 3)));
1064 vec2i_v = Vector2i(-5, -7);
1065 vec4_v = vec2i_v;
1066 CHECK(vec4_v.get_type() == Variant::VECTOR2I);
1067
1068 Variant vec4i_v = Vector4i(0, 0, 0, 0);
1069 vec2i_v = Vector2i(2, 3);
1070 vec4i_v = vec2i_v;
1071 CHECK(vec4i_v == Variant(Vector2i(2, 3)));
1072 vec2i_v = Vector2i(-5, -7);
1073 vec4i_v = vec2i_v;
1074 CHECK(vec4i_v.get_type() == Variant::VECTOR2I);
1075
1076 Variant rect2_v = Rect2();
1077 vec2i_v = Vector2i(2, 3);
1078 rect2_v = vec2i_v;
1079 CHECK(rect2_v == Variant(Vector2i(2, 3)));
1080 vec2i_v = Vector2i(-5, -7);
1081 rect2_v = vec2i_v;
1082 CHECK(rect2_v.get_type() == Variant::VECTOR2I);
1083
1084 Variant rect2i_v = Rect2i();
1085 vec2i_v = Vector2i(2, 3);
1086 rect2i_v = vec2i_v;
1087 CHECK(rect2i_v == Variant(Vector2i(2, 3)));
1088 vec2i_v = Vector2i(-5, -7);
1089 rect2i_v = vec2i_v;
1090 CHECK(rect2i_v.get_type() == Variant::VECTOR2I);
1091
1092 Variant transform2d_v = Transform2D();
1093 vec2i_v = Vector2i(2, 3);
1094 transform2d_v = vec2i_v;
1095 CHECK(transform2d_v == Variant(Vector2i(2, 3)));
1096 vec2i_v = Vector2i(-5, -7);
1097 transform2d_v = vec2i_v;
1098 CHECK(transform2d_v.get_type() == Variant::VECTOR2I);
1099
1100 Variant transform3d_v = Transform3D();
1101 vec2i_v = Vector2i(2, 3);
1102 transform3d_v = vec2i_v;
1103 CHECK(transform3d_v == Variant(Vector2i(2, 3)));
1104 vec2i_v = Vector2i(-5, -7);
1105 transform3d_v = vec2i_v;
1106 CHECK(transform3d_v.get_type() == Variant::VECTOR2I);
1107
1108 Variant col_v = Color(0.5f, 0.2f, 0.75f);
1109 vec2i_v = Vector2i(2, 3);
1110 col_v = vec2i_v;
1111 CHECK(col_v == Variant(Vector2i(2, 3)));
1112 vec2i_v = Vector2i(-5, -7);
1113 col_v = vec2i_v;
1114 CHECK(col_v.get_type() == Variant::VECTOR2I);
1115
1116 Variant call_v = Callable();
1117 vec2i_v = Vector2i(2, 3);
1118 call_v = vec2i_v;
1119 CHECK(call_v == Variant(Vector2i(2, 3)));
1120 vec2i_v = Vector2i(-5, -7);
1121 call_v = vec2i_v;
1122 CHECK(call_v.get_type() == Variant::VECTOR2I);
1123
1124 Variant plane_v = Plane();
1125 vec2i_v = Vector2i(2, 3);
1126 plane_v = vec2i_v;
1127 CHECK(plane_v == Variant(Vector2i(2, 3)));
1128 vec2i_v = Vector2i(-5, -7);
1129 plane_v = vec2i_v;
1130 CHECK(plane_v.get_type() == Variant::VECTOR2I);
1131
1132 Variant basis_v = Basis();
1133 vec2i_v = Vector2i(2, 3);
1134 basis_v = vec2i_v;
1135 CHECK(basis_v == Variant(Vector2i(2, 3)));
1136 vec2i_v = Vector2i(-5, -7);
1137 basis_v = vec2i_v;
1138 CHECK(basis_v.get_type() == Variant::VECTOR2I);
1139
1140 Variant aabb_v = AABB();
1141 vec2i_v = Vector2i(2, 3);
1142 aabb_v = vec2i_v;
1143 CHECK(aabb_v == Variant(Vector2i(2, 3)));
1144 vec2i_v = Vector2i(-5, -7);
1145 aabb_v = vec2i_v;
1146 CHECK(aabb_v.get_type() == Variant::VECTOR2I);
1147
1148 Variant quaternion_v = Quaternion();
1149 vec2i_v = Vector2i(2, 3);
1150 quaternion_v = vec2i_v;
1151 CHECK(quaternion_v == Variant(Vector2i(2, 3)));
1152 vec2i_v = Vector2i(-5, -7);
1153 quaternion_v = vec2i_v;
1154 CHECK(quaternion_v.get_type() == Variant::VECTOR2I);
1155
1156 Variant projection_v = Projection();
1157 vec2i_v = Vector2i(2, 3);
1158 projection_v = vec2i_v;
1159 CHECK(projection_v == Variant(Vector2i(2, 3)));
1160 vec2i_v = Vector2i(-5, -7);
1161 projection_v = vec2i_v;
1162 CHECK(projection_v.get_type() == Variant::VECTOR2I);
1163
1164 Variant rid_v = RID();
1165 vec2i_v = Vector2i(2, 3);
1166 rid_v = vec2i_v;
1167 CHECK(rid_v == Variant(Vector2i(2, 3)));
1168 vec2i_v = Vector2i(-5, -7);
1169 rid_v = vec2i_v;
1170 CHECK(rid_v.get_type() == Variant::VECTOR2I);
1171
1172 Object obj_one = Object();
1173 Variant object_v = &obj_one;
1174 vec2i_v = Vector2i(2, 3);
1175 object_v = vec2i_v;
1176 CHECK(object_v == Variant(Vector2i(2, 3)));
1177 vec2i_v = Vector2i(-5, -7);
1178 object_v = vec2i_v;
1179 CHECK(object_v.get_type() == Variant::VECTOR2I);
1180 }
1181
1182 TEST_CASE("[Variant] Assignment To Vec3 from Bool,Int,Float,String,Vec2,Vec2i,Vec3i,Vec4,Vec4i,Rect2,Rect2i,Trans2d,Trans3d,Color,Call,Plane,Basis,AABB,Quant,Proj,RID,and Object") {
1183 Variant bool_v = false;
1184 Variant vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1185 bool_v = vec3_v; // Now bool_v is Vector3
1186 CHECK(bool_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1187 vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1188 bool_v = vec3_v;
1189 CHECK(bool_v.get_type() == Variant::VECTOR3);
1190
1191 Variant int_v = 0;
1192 vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1193 int_v = vec3_v;
1194 CHECK(int_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1195 vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1196 int_v = vec3_v;
1197 CHECK(int_v.get_type() == Variant::VECTOR3);
1198
1199 Variant float_v = 0.0f;
1200 vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1201 float_v = vec3_v;
1202 CHECK(float_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1203 vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1204 float_v = vec3_v;
1205 CHECK(float_v.get_type() == Variant::VECTOR3);
1206
1207 Variant string_v = "";
1208 vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1209 string_v = vec3_v;
1210 CHECK(string_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1211 vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1212 string_v = vec3_v;
1213 CHECK(string_v.get_type() == Variant::VECTOR3);
1214
1215 Variant vec2_v = Vector2(0, 0);
1216 vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1217 vec2_v = vec3_v;
1218 CHECK(vec2_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1219 vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1220 vec2_v = vec3_v;
1221 CHECK(vec2_v.get_type() == Variant::VECTOR3);
1222
1223 Variant vec2i_v = Vector2i(0, 0);
1224 vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1225 vec2i_v = vec3_v;
1226 CHECK(vec2i_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1227 vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1228 vec2i_v = vec3_v;
1229 CHECK(vec2i_v.get_type() == Variant::VECTOR3);
1230
1231 Variant vec3i_v = Vector3i(0, 0, 0);
1232 vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1233 vec3i_v = vec3_v;
1234 CHECK(vec3i_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1235 vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1236 vec3i_v = vec3_v;
1237 CHECK(vec3i_v.get_type() == Variant::VECTOR3);
1238
1239 Variant vec4_v = Vector4(0, 0, 0, 0);
1240 vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1241 vec4_v = vec3_v;
1242 CHECK(vec4_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1243 vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1244 vec4_v = vec3_v;
1245 CHECK(vec4_v.get_type() == Variant::VECTOR3);
1246
1247 Variant vec4i_v = Vector4i(0, 0, 0, 0);
1248 vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1249 vec4i_v = vec3_v;
1250 CHECK(vec4i_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1251 vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1252 vec4i_v = vec3_v;
1253 CHECK(vec4i_v.get_type() == Variant::VECTOR3);
1254
1255 Variant rect2_v = Rect2();
1256 vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1257 rect2_v = vec3_v;
1258 CHECK(rect2_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1259 vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1260 rect2_v = vec3_v;
1261 CHECK(rect2_v.get_type() == Variant::VECTOR3);
1262
1263 Variant rect2i_v = Rect2i();
1264 vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1265 rect2i_v = vec3_v;
1266 CHECK(rect2i_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1267 vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1268 rect2i_v = vec3_v;
1269 CHECK(rect2i_v.get_type() == Variant::VECTOR3);
1270
1271 Variant transform2d_v = Transform2D();
1272 vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1273 transform2d_v = vec3_v;
1274 CHECK(transform2d_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1275 vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1276 transform2d_v = vec3_v;
1277 CHECK(transform2d_v.get_type() == Variant::VECTOR3);
1278
1279 Variant transform3d_v = Transform3D();
1280 vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1281 transform3d_v = vec3_v;
1282 CHECK(transform3d_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1283 vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1284 transform3d_v = vec3_v;
1285 CHECK(transform3d_v.get_type() == Variant::VECTOR3);
1286
1287 Variant col_v = Color(0.5f, 0.2f, 0.75f);
1288 vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1289 col_v = vec3_v;
1290 CHECK(col_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1291 vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1292 col_v = vec3_v;
1293 CHECK(col_v.get_type() == Variant::VECTOR3);
1294
1295 Variant call_v = Callable();
1296 vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1297 call_v = vec3_v;
1298 CHECK(call_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1299 vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1300 call_v = vec3_v;
1301 CHECK(call_v.get_type() == Variant::VECTOR3);
1302
1303 Variant plane_v = Plane();
1304 vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1305 plane_v = vec3_v;
1306 CHECK(plane_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1307 vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1308 plane_v = vec3_v;
1309 CHECK(plane_v.get_type() == Variant::VECTOR3);
1310
1311 Variant basis_v = Basis();
1312 vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1313 basis_v = vec3_v;
1314 CHECK(basis_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1315 vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1316 basis_v = vec3_v;
1317 CHECK(basis_v.get_type() == Variant::VECTOR3);
1318
1319 Variant aabb_v = AABB();
1320 vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1321 aabb_v = vec3_v;
1322 CHECK(aabb_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1323 vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1324 aabb_v = vec3_v;
1325 CHECK(aabb_v.get_type() == Variant::VECTOR3);
1326
1327 Variant quaternion_v = Quaternion();
1328 vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1329 quaternion_v = vec3_v;
1330 CHECK(quaternion_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1331 vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1332 quaternion_v = vec3_v;
1333 CHECK(quaternion_v.get_type() == Variant::VECTOR3);
1334
1335 Variant projection_v = Projection();
1336 vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1337 quaternion_v = vec3_v;
1338 CHECK(quaternion_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1339 vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1340 quaternion_v = vec3_v;
1341 CHECK(quaternion_v.get_type() == Variant::VECTOR3);
1342
1343 Variant rid_v = RID();
1344 vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1345 rid_v = vec3_v;
1346 CHECK(rid_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1347 vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1348 rid_v = vec3_v;
1349 CHECK(rid_v.get_type() == Variant::VECTOR3);
1350
1351 Object obj_one = Object();
1352 Variant object_v = &obj_one;
1353 vec3_v = Vector3(2.2f, 3.5f, 5.3f);
1354 object_v = vec3_v;
1355 CHECK(object_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));
1356 vec3_v = Vector3(-5.4f, -7.9f, -2.1f);
1357 object_v = vec3_v;
1358 CHECK(object_v.get_type() == Variant::VECTOR3);
1359 }
1360
1361 TEST_CASE("[Variant] Assignment To Vec3i from Bool,Int,Float,String,Vec2,Vec2i,Vec3 and Color") {
1362 Variant bool_v = false;
1363 Variant vec3i_v = Vector3i(2, 3, 5);
1364 bool_v = vec3i_v; // Now bool_v is Vector3i
1365 CHECK(bool_v == Variant(Vector3i(2, 3, 5)));
1366 vec3i_v = Vector3i(-5, -7, -2);
1367 bool_v = vec3i_v;
1368 CHECK(bool_v.get_type() == Variant::VECTOR3I);
1369
1370 Variant int_v = 0;
1371 vec3i_v = Vector3i(2, 3, 5);
1372 int_v = vec3i_v;
1373 CHECK(int_v == Variant(Vector3i(2, 3, 5)));
1374 vec3i_v = Vector3i(-5, -7, -2);
1375 int_v = vec3i_v;
1376 CHECK(int_v.get_type() == Variant::VECTOR3I);
1377
1378 Variant float_v = 0.0f;
1379 vec3i_v = Vector3i(2, 3, 5);
1380 float_v = vec3i_v;
1381 CHECK(float_v == Variant(Vector3i(2, 3, 5)));
1382 vec3i_v = Vector3i(-5, -7, -2);
1383 float_v = vec3i_v;
1384 CHECK(float_v.get_type() == Variant::VECTOR3I);
1385
1386 Variant string_v = "";
1387 vec3i_v = Vector3i(2, 3, 5);
1388 string_v = vec3i_v;
1389 CHECK(string_v == Variant(Vector3i(2, 3, 5)));
1390 vec3i_v = Vector3i(-5, -7, -2);
1391 string_v = vec3i_v;
1392 CHECK(string_v.get_type() == Variant::VECTOR3I);
1393
1394 Variant vec2_v = Vector2(0, 0);
1395 vec3i_v = Vector3i(2, 3, 5);
1396 vec2_v = vec3i_v;
1397 CHECK(vec2_v == Variant(Vector3i(2, 3, 5)));
1398 vec3i_v = Vector3i(-5, -7, -2);
1399 vec2_v = vec3i_v;
1400 CHECK(vec2_v.get_type() == Variant::VECTOR3I);
1401
1402 Variant vec2i_v = Vector2i(0, 0);
1403 vec3i_v = Vector3i(2, 3, 5);
1404 vec2i_v = vec3i_v;
1405 CHECK(vec2i_v == Variant(Vector3i(2, 3, 5)));
1406 vec3i_v = Vector3i(-5, -7, -2);
1407 vec2i_v = vec3i_v;
1408 CHECK(vec2i_v.get_type() == Variant::VECTOR3I);
1409
1410 Variant vec3_v = Vector3(0, 0, 0);
1411 vec3i_v = Vector3i(2, 3, 5);
1412 vec3_v = vec3i_v;
1413 CHECK(vec3_v == Variant(Vector3i(2, 3, 5)));
1414 vec3i_v = Vector3i(-5, -7, -2);
1415 vec3_v = vec3i_v;
1416 CHECK(vec3_v.get_type() == Variant::VECTOR3I);
1417
1418 Variant vec4_v = Vector4(0, 0, 0, 0);
1419 vec3i_v = Vector3i(2, 3, 5);
1420 vec4_v = vec3i_v;
1421 CHECK(vec4_v == Variant(Vector3i(2, 3, 5)));
1422 vec3i_v = Vector3i(-5, -7, -2);
1423 vec4_v = vec3i_v;
1424 CHECK(vec4_v.get_type() == Variant::VECTOR3I);
1425
1426 Variant vec4i_v = Vector4i(0, 0, 0, 0);
1427 vec3i_v = Vector3i(2, 3, 5);
1428 vec4i_v = vec3i_v;
1429 CHECK(vec4i_v == Variant(Vector3i(2, 3, 5)));
1430 vec3i_v = Vector3i(-5, -7, -2);
1431 vec4i_v = vec3i_v;
1432 CHECK(vec4i_v.get_type() == Variant::VECTOR3I);
1433
1434 Variant rect2_v = Rect2();
1435 vec3i_v = Vector3i(2, 3, 5);
1436 rect2_v = vec3i_v;
1437 CHECK(rect2_v == Variant(Vector3i(2, 3, 5)));
1438 vec3i_v = Vector3i(-5, -7, -2);
1439 rect2_v = vec3i_v;
1440 CHECK(rect2_v.get_type() == Variant::VECTOR3I);
1441
1442 Variant rect2i_v = Rect2i();
1443 vec3i_v = Vector3i(2, 3, 5);
1444 rect2i_v = vec3i_v;
1445 CHECK(rect2i_v == Variant(Vector3i(2, 3, 5)));
1446 vec3i_v = Vector3i(-5, -7, -2);
1447 rect2i_v = vec3i_v;
1448 CHECK(rect2i_v.get_type() == Variant::VECTOR3I);
1449
1450 Variant transform2d_v = Transform2D();
1451 vec3i_v = Vector3i(2, 3, 5);
1452 transform2d_v = vec3i_v;
1453 CHECK(transform2d_v == Variant(Vector3i(2, 3, 5)));
1454 vec3i_v = Vector3i(-5, -7, -2);
1455 transform2d_v = vec3i_v;
1456 CHECK(transform2d_v.get_type() == Variant::VECTOR3I);
1457
1458 Variant transform3d_v = Transform3D();
1459 vec3i_v = Vector3i(2, 3, 5);
1460 transform3d_v = vec3i_v;
1461 CHECK(transform3d_v == Variant(Vector3i(2, 3, 5)));
1462 vec3i_v = Vector3i(-5, -7, -2);
1463 transform3d_v = vec3i_v;
1464 CHECK(transform3d_v.get_type() == Variant::VECTOR3I);
1465
1466 Variant col_v = Color(0.5f, 0.2f, 0.75f);
1467 vec3i_v = Vector3i(2, 3, 5);
1468 col_v = vec3i_v;
1469 CHECK(col_v == Variant(Vector3i(2, 3, 5)));
1470 vec3i_v = Vector3i(-5, -7, -2);
1471 col_v = vec3i_v;
1472 CHECK(col_v.get_type() == Variant::VECTOR3I);
1473
1474 Variant call_v = Callable();
1475 vec3i_v = Vector3i(2, 3, 5);
1476 call_v = vec3i_v;
1477 CHECK(call_v == Variant(Vector3i(2, 3, 5)));
1478 vec3i_v = Vector3i(-5, -7, -2);
1479 call_v = vec3i_v;
1480 CHECK(call_v.get_type() == Variant::VECTOR3I);
1481
1482 Variant plane_v = Plane();
1483 vec3i_v = Vector3i(2, 3, 5);
1484 plane_v = vec3i_v;
1485 CHECK(plane_v == Variant(Vector3i(2, 3, 5)));
1486 vec3i_v = Vector3i(-5, -7, -2);
1487 plane_v = vec3i_v;
1488 CHECK(plane_v.get_type() == Variant::VECTOR3I);
1489
1490 Variant basis_v = Basis();
1491 vec3i_v = Vector3i(2, 3, 5);
1492 basis_v = vec3i_v;
1493 CHECK(basis_v == Variant(Vector3i(2, 3, 5)));
1494 vec3i_v = Vector3i(-5, -7, -2);
1495 basis_v = vec3i_v;
1496 CHECK(basis_v.get_type() == Variant::VECTOR3I);
1497
1498 Variant aabb_v = AABB();
1499 vec3i_v = Vector3i(2, 3, 5);
1500 aabb_v = vec3i_v;
1501 CHECK(aabb_v == Variant(Vector3i(2, 3, 5)));
1502 vec3i_v = Vector3i(-5, -7, -2);
1503 aabb_v = vec3i_v;
1504 CHECK(aabb_v.get_type() == Variant::VECTOR3I);
1505
1506 Variant quaternion_v = Quaternion();
1507 vec3i_v = Vector3i(2, 3, 5);
1508 quaternion_v = vec3i_v;
1509 CHECK(quaternion_v == Variant(Vector3i(2, 3, 5)));
1510 vec3i_v = Vector3i(-5, -7, -2);
1511 quaternion_v = vec3i_v;
1512 CHECK(quaternion_v.get_type() == Variant::VECTOR3I);
1513
1514 Variant projection_v = Projection();
1515 vec3i_v = Vector3i(2, 3, 5);
1516 projection_v = vec3i_v;
1517 CHECK(projection_v == Variant(Vector3i(2, 3, 5)));
1518 vec3i_v = Vector3i(-5, -7, -2);
1519 projection_v = vec3i_v;
1520 CHECK(projection_v.get_type() == Variant::VECTOR3I);
1521
1522 Variant rid_v = RID();
1523 vec3i_v = Vector3i(2, 3, 5);
1524 rid_v = vec3i_v;
1525 CHECK(rid_v == Variant(Vector3i(2, 3, 5)));
1526 vec3i_v = Vector3i(-5, -7, -2);
1527 rid_v = vec3i_v;
1528 CHECK(rid_v.get_type() == Variant::VECTOR3I);
1529
1530 Object obj_one = Object();
1531 Variant object_v = &obj_one;
1532 vec3i_v = Vector3i(2, 3, 5);
1533 object_v = vec3i_v;
1534 CHECK(object_v == Variant(Vector3i(2, 3, 5)));
1535 vec3i_v = Vector3i(-5, -7, -2);
1536 object_v = vec3i_v;
1537 CHECK(object_v.get_type() == Variant::VECTOR3I);
1538 }
1539
1540 TEST_CASE("[Variant] Assignment To Color from Bool,Int,Float,String,Vec2,Vec2i,Vec3,Vec3i,Vec4,Vec4i,Rect2,Rect2i,Trans2d,Trans3d,Color,Call,Plane,Basis,AABB,Quant,Proj,RID,and Object") {
1541 Variant bool_v = false;
1542 Variant col_v = Color(0.25f, 0.4f, 0.78f);
1543 bool_v = col_v; // Now bool_v is Color
1544 CHECK(bool_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1545 col_v = Color(0.33f, 0.75f, 0.21f);
1546 bool_v = col_v;
1547 CHECK(bool_v.get_type() == Variant::COLOR);
1548
1549 Variant int_v = 0;
1550 col_v = Color(0.25f, 0.4f, 0.78f);
1551 int_v = col_v;
1552 CHECK(int_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1553 col_v = Color(0.33f, 0.75f, 0.21f);
1554 int_v = col_v;
1555 CHECK(int_v.get_type() == Variant::COLOR);
1556
1557 Variant float_v = 0.0f;
1558 col_v = Color(0.25f, 0.4f, 0.78f);
1559 float_v = col_v;
1560 CHECK(float_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1561 col_v = Color(0.33f, 0.75f, 0.21f);
1562 float_v = col_v;
1563 CHECK(float_v.get_type() == Variant::COLOR);
1564
1565 Variant string_v = "";
1566 col_v = Color(0.25f, 0.4f, 0.78f);
1567 string_v = col_v;
1568 CHECK(string_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1569 col_v = Color(0.33f, 0.75f, 0.21f);
1570 string_v = col_v;
1571 CHECK(string_v.get_type() == Variant::COLOR);
1572
1573 Variant vec2_v = Vector2(0, 0);
1574 col_v = Color(0.25f, 0.4f, 0.78f);
1575 vec2_v = col_v;
1576 CHECK(vec2_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1577 col_v = Color(0.33f, 0.75f, 0.21f);
1578 vec2_v = col_v;
1579 CHECK(vec2_v.get_type() == Variant::COLOR);
1580
1581 Variant vec2i_v = Vector2i(0, 0);
1582 col_v = Color(0.25f, 0.4f, 0.78f);
1583 vec2i_v = col_v;
1584 CHECK(vec2i_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1585 col_v = Color(0.33f, 0.75f, 0.21f);
1586 vec2i_v = col_v;
1587 CHECK(vec2i_v.get_type() == Variant::COLOR);
1588
1589 Variant vec3_v = Vector3(0, 0, 0);
1590 col_v = Color(0.25f, 0.4f, 0.78f);
1591 vec3_v = col_v;
1592 CHECK(vec3_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1593 col_v = Color(0.33f, 0.75f, 0.21f);
1594 vec3_v = col_v;
1595 CHECK(vec3_v.get_type() == Variant::COLOR);
1596
1597 Variant vec3i_v = Vector3i(0, 0, 0);
1598 col_v = Color(0.25f, 0.4f, 0.78f);
1599 vec3i_v = col_v;
1600 CHECK(vec3i_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1601 col_v = Color(0.33f, 0.75f, 0.21f);
1602 vec3i_v = col_v;
1603 CHECK(vec3i_v.get_type() == Variant::COLOR);
1604
1605 Variant vec4_v = Vector4(0, 0, 0, 0);
1606 col_v = Color(0.25f, 0.4f, 0.78f);
1607 vec4_v = col_v;
1608 CHECK(vec4_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1609 col_v = Color(0.33f, 0.75f, 0.21f);
1610 vec4_v = col_v;
1611 CHECK(vec4_v.get_type() == Variant::COLOR);
1612
1613 Variant vec4i_v = Vector4i(0, 0, 0, 0);
1614 col_v = Color(0.25f, 0.4f, 0.78f);
1615 vec4i_v = col_v;
1616 CHECK(vec4i_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1617 col_v = Color(0.33f, 0.75f, 0.21f);
1618 vec4i_v = col_v;
1619 CHECK(vec4i_v.get_type() == Variant::COLOR);
1620
1621 Variant rect2_v = Rect2();
1622 col_v = Color(0.25f, 0.4f, 0.78f);
1623 rect2_v = col_v;
1624 CHECK(rect2_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1625 col_v = Color(0.33f, 0.75f, 0.21f);
1626 rect2_v = col_v;
1627 CHECK(rect2_v.get_type() == Variant::COLOR);
1628
1629 Variant rect2i_v = Rect2i();
1630 col_v = Color(0.25f, 0.4f, 0.78f);
1631 rect2i_v = col_v;
1632 CHECK(rect2i_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1633 col_v = Color(0.33f, 0.75f, 0.21f);
1634 rect2i_v = col_v;
1635 CHECK(rect2i_v.get_type() == Variant::COLOR);
1636
1637 Variant transform2d_v = Transform2D();
1638 col_v = Color(0.25f, 0.4f, 0.78f);
1639 transform2d_v = col_v;
1640 CHECK(transform2d_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1641 col_v = Color(0.33f, 0.75f, 0.21f);
1642 transform2d_v = col_v;
1643 CHECK(transform2d_v.get_type() == Variant::COLOR);
1644
1645 Variant transform3d_v = Transform3D();
1646 col_v = Color(0.25f, 0.4f, 0.78f);
1647 transform3d_v = col_v;
1648 CHECK(transform3d_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1649 col_v = Color(0.33f, 0.75f, 0.21f);
1650 transform3d_v = col_v;
1651 CHECK(transform3d_v.get_type() == Variant::COLOR);
1652
1653 Variant call_v = Callable();
1654 col_v = Color(0.25f, 0.4f, 0.78f);
1655 call_v = col_v;
1656 CHECK(call_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1657 col_v = Color(0.33f, 0.75f, 0.21f);
1658 call_v = col_v;
1659 CHECK(call_v.get_type() == Variant::COLOR);
1660
1661 Variant plane_v = Plane();
1662 col_v = Color(0.25f, 0.4f, 0.78f);
1663 plane_v = col_v;
1664 CHECK(plane_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1665 col_v = Color(0.33f, 0.75f, 0.21f);
1666 plane_v = col_v;
1667 CHECK(plane_v.get_type() == Variant::COLOR);
1668
1669 Variant basis_v = Basis();
1670 col_v = Color(0.25f, 0.4f, 0.78f);
1671 basis_v = col_v;
1672 CHECK(basis_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1673 col_v = Color(0.33f, 0.75f, 0.21f);
1674 basis_v = col_v;
1675 CHECK(basis_v.get_type() == Variant::COLOR);
1676
1677 Variant aabb_v = AABB();
1678 col_v = Color(0.25f, 0.4f, 0.78f);
1679 aabb_v = col_v;
1680 CHECK(aabb_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1681 col_v = Color(0.33f, 0.75f, 0.21f);
1682 aabb_v = col_v;
1683 CHECK(aabb_v.get_type() == Variant::COLOR);
1684
1685 Variant quaternion_v = Quaternion();
1686 col_v = Color(0.25f, 0.4f, 0.78f);
1687 quaternion_v = col_v;
1688 CHECK(quaternion_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1689 col_v = Color(0.33f, 0.75f, 0.21f);
1690 quaternion_v = col_v;
1691 CHECK(quaternion_v.get_type() == Variant::COLOR);
1692
1693 Variant projection_v = Projection();
1694 col_v = Color(0.25f, 0.4f, 0.78f);
1695 projection_v = col_v;
1696 CHECK(projection_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1697 col_v = Color(0.33f, 0.75f, 0.21f);
1698 projection_v = col_v;
1699 CHECK(projection_v.get_type() == Variant::COLOR);
1700
1701 Variant rid_v = RID();
1702 col_v = Color(0.25f, 0.4f, 0.78f);
1703 rid_v = col_v;
1704 CHECK(rid_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1705 col_v = Color(0.33f, 0.75f, 0.21f);
1706 rid_v = col_v;
1707 CHECK(rid_v.get_type() == Variant::COLOR);
1708
1709 Object obj_one = Object();
1710 Variant object_v = &obj_one;
1711 col_v = Color(0.25f, 0.4f, 0.78f);
1712 object_v = col_v;
1713 CHECK(object_v == Variant(Color(0.25f, 0.4f, 0.78f)));
1714 col_v = Color(0.33f, 0.75f, 0.21f);
1715 object_v = col_v;
1716 CHECK(object_v.get_type() == Variant::COLOR);
1717 }
1718
1719 TEST_CASE("[Variant] array initializer list") {
1720 Variant arr_v = { 0, 1, "test", true, { 0.0, 1.0 } };
1721 CHECK(arr_v.get_type() == Variant::ARRAY);
1722 Array arr = (Array)arr_v;
1723 CHECK(arr.size() == 5);
1724 CHECK(arr[0] == Variant(0));
1725 CHECK(arr[1] == Variant(1));
1726 CHECK(arr[2] == Variant("test"));
1727 CHECK(arr[3] == Variant(true));
1728 CHECK(arr[4] == Variant({ 0.0, 1.0 }));
1729
1730 PackedInt32Array packed_arr = { 2, 1, 0 };
1731 CHECK(packed_arr.size() == 3);
1732 CHECK(packed_arr[0] == 2);
1733 CHECK(packed_arr[1] == 1);
1734 CHECK(packed_arr[2] == 0);
1735 }
1736
1737 TEST_CASE("[Variant] Writer and parser Vector2") {
1738 Variant vec2_parsed;
1739 String vec2_str;
1740 String errs;
1741 int line;
1742 // Variant::VECTOR2 and Vector2 can be either 32-bit or 64-bit depending on the precision level of real_t.
1743 {
1744 Vector2 vec2 = Vector2(1.2, 3.4);
1745 VariantWriter::write_to_string(vec2, vec2_str);
1746 // Reminder: "1.2" and "3.4" are not exactly those decimal numbers. They are the closest float to them.
1747 CHECK_MESSAGE(vec2_str == "Vector2(1.2, 3.4)", "Should write with enough digits to ensure parsing back is exact.");
1748 VariantParser::StreamString stream;
1749 stream.s = vec2_str;
1750 VariantParser::parse(&stream, vec2_parsed, errs, line);
1751 CHECK_MESSAGE(Vector2(vec2_parsed) == vec2, "Should parse back to the same Vector2.");
1752 }
1753 // Check with big numbers and small numbers.
1754 {
1755 Vector2 vec2 = Vector2(1.234567898765432123456789e30, 1.234567898765432123456789e-10);
1756 VariantWriter::write_to_string(vec2, vec2_str);
1757 #ifdef REAL_T_IS_DOUBLE
1758 CHECK_MESSAGE(vec2_str == "Vector2(1.2345678987654322e+30, 1.2345678987654322e-10)", "Should write with enough digits to ensure parsing back is exact.");
1759 #else
1760 CHECK_MESSAGE(vec2_str == "Vector2(1.2345679e+30, 1.2345679e-10)", "Should write with enough digits to ensure parsing back is exact.");
1761 #endif
1762 VariantParser::StreamString stream;
1763 stream.s = vec2_str;
1764 VariantParser::parse(&stream, vec2_parsed, errs, line);
1765 CHECK_MESSAGE(Vector2(vec2_parsed) == vec2, "Should parse back to the same Vector2.");
1766 }
1767 }
1768
1769 TEST_CASE("[Variant] Writer and parser array") {
1770 Array a = { 1, String("hello"), Array({ Variant() }) };
1771 String a_str;
1772 VariantWriter::write_to_string(a, a_str);
1773
1774 CHECK_EQ(a_str, "[1, \"hello\", [null]]");
1775
1776 VariantParser::StreamString ss;
1777 String errs;
1778 int line;
1779 Variant a_parsed;
1780
1781 ss.s = a_str;
1782 VariantParser::parse(&ss, a_parsed, errs, line);
1783
1784 CHECK_MESSAGE(a_parsed == Variant(a), "Should parse back.");
1785 }
1786
1787 TEST_CASE("[Variant] Writer recursive array") {
1788 // There is no way to accurately represent a recursive array,
1789 // the only thing we can do is make sure the writer doesn't blow up
1790
1791 // Self recursive
1792 Array a;
1793 a.push_back(a);
1794
1795 // Writer should it recursion limit while visiting the array
1796 ERR_PRINT_OFF;
1797 String a_str;
1798 VariantWriter::write_to_string(a, a_str);
1799 ERR_PRINT_ON;
1800
1801 // Nested recursive
1802 Array a1;
1803 Array a2;
1804 a1.push_back(a2);
1805 a2.push_back(a1);
1806
1807 // Writer should it recursion limit while visiting the array
1808 ERR_PRINT_OFF;
1809 String a1_str;
1810 VariantWriter::write_to_string(a1, a1_str);
1811 ERR_PRINT_ON;
1812
1813 // Break the recursivity otherwise Dictionary tearndown will leak memory
1814 a.clear();
1815 a1.clear();
1816 a2.clear();
1817 }
1818
1819 TEST_CASE("[Variant] Writer and parser dictionary") {
1820 // d = {{1: 2}: 3, 4: "hello", 5: {null: []}}
1821 Dictionary d = { { Dictionary({ { 1, 2 } }), 3 }, { 4, String("hello") }, { 5, Dictionary({ { Variant(), Array() } }) } };
1822 String d_str;
1823 VariantWriter::write_to_string(d, d_str);
1824
1825 CHECK_EQ(d_str, "{\n4: \"hello\",\n5: {\nnull: []\n},\n{\n1: 2\n}: 3\n}");
1826
1827 VariantParser::StreamString ss;
1828 String errs;
1829 int line;
1830 Variant d_parsed;
1831
1832 ss.s = d_str;
1833 VariantParser::parse(&ss, d_parsed, errs, line);
1834
1835 CHECK_MESSAGE(d_parsed == Variant(d), "Should parse back.");
1836 }
1837
1838 TEST_CASE("[Variant] Writer key sorting") {
1839 Dictionary d = { { StringName("C"), 3 }, { "A", 1 }, { StringName("B"), 2 }, { "D", 4 } };
1840 String d_str;
1841 VariantWriter::write_to_string(d, d_str);
1842
1843 CHECK_EQ(d_str, "{\n\"A\": 1,\n&\"B\": 2,\n&\"C\": 3,\n\"D\": 4\n}");
1844 }
1845
1846 TEST_CASE("[Variant] Writer recursive dictionary") {
1847 // There is no way to accurately represent a recursive dictionary,
1848 // the only thing we can do is make sure the writer doesn't blow up
1849
1850 // Self recursive
1851 Dictionary d;
1852 d[1] = d;
1853
1854 // Writer should it recursion limit while visiting the dictionary
1855 ERR_PRINT_OFF;
1856 String d_str;
1857 VariantWriter::write_to_string(d, d_str);
1858 ERR_PRINT_ON;
1859
1860 // Nested recursive
1861 Dictionary d1;
1862 Dictionary d2;
1863 d1[2] = d2;
1864 d2[1] = d1;
1865
1866 // Writer should it recursion limit while visiting the dictionary
1867 ERR_PRINT_OFF;
1868 String d1_str;
1869 VariantWriter::write_to_string(d1, d1_str);
1870 ERR_PRINT_ON;
1871
1872 // Break the recursivity otherwise Dictionary tearndown will leak memory
1873 d.clear();
1874 d1.clear();
1875 d2.clear();
1876 }
1877
1878 #if 0 // TODO: recursion in dict key is currently buggy
1879 TEST_CASE("[Variant] Writer recursive dictionary on keys") {
1880 // There is no way to accurately represent a recursive dictionary,
1881 // the only thing we can do is make sure the writer doesn't blow up
1882
1883 // Self recursive
1884 Dictionary d;
1885 d[d] = 1;
1886
1887 // Writer should it recursion limit while visiting the dictionary
1888 ERR_PRINT_OFF;
1889 String d_str;
1890 VariantWriter::write_to_string(d, d_str);
1891 ERR_PRINT_ON;
1892
1893 // Nested recursive
1894 Dictionary d1;
1895 Dictionary d2;
1896 d1[d2] = 2;
1897 d2[d1] = 1;
1898
1899 // Writer should it recursion limit while visiting the dictionary
1900 ERR_PRINT_OFF;
1901 String d1_str;
1902 VariantWriter::write_to_string(d1, d1_str);
1903 ERR_PRINT_ON;
1904
1905 // Break the recursivity otherwise Dictionary tearndown will leak memory
1906 d.clear();
1907 d1.clear();
1908 d2.clear();
1909 }
1910 #endif
1911
1912 TEST_CASE("[Variant] Basic comparison") {
1913 CHECK_EQ(Variant(1), Variant(1));
1914 CHECK_FALSE(Variant(1) != Variant(1));
1915 CHECK_NE(Variant(1), Variant(2));
1916 CHECK_EQ(Variant(String("foo")), Variant(String("foo")));
1917 CHECK_NE(Variant(String("foo")), Variant(String("bar")));
1918 // Check "empty" version of different types are not equivalents
1919 CHECK_NE(Variant(0), Variant());
1920 CHECK_NE(Variant(String()), Variant());
1921 CHECK_NE(Variant(Array()), Variant());
1922 CHECK_NE(Variant(Dictionary()), Variant());
1923 }
1924
1925 TEST_CASE("[Variant] Identity comparison") {
1926 // Value types are compared by value
1927 Variant aabb = AABB();
1928 CHECK(aabb.identity_compare(aabb));
1929 CHECK(aabb.identity_compare(AABB()));
1930 CHECK_FALSE(aabb.identity_compare(AABB(Vector3(1, 2, 3), Vector3(1, 2, 3))));
1931
1932 Variant basis = Basis();
1933 CHECK(basis.identity_compare(basis));
1934 CHECK(basis.identity_compare(Basis()));
1935 CHECK_FALSE(basis.identity_compare(Basis(Quaternion(Vector3(1, 2, 3).normalized(), 45))));
1936
1937 Variant bool_var = true;
1938 CHECK(bool_var.identity_compare(bool_var));
1939 CHECK(bool_var.identity_compare(true));
1940 CHECK_FALSE(bool_var.identity_compare(false));
1941
1942 Variant callable = Callable();
1943 CHECK(callable.identity_compare(callable));
1944 CHECK(callable.identity_compare(Callable()));
1945 CHECK_FALSE(callable.identity_compare(Callable(ObjectID(), StringName("lambda"))));
1946
1947 Variant color = Color();
1948 CHECK(color.identity_compare(color));
1949 CHECK(color.identity_compare(Color()));
1950 CHECK_FALSE(color.identity_compare(Color(255, 0, 255)));
1951
1952 Variant float_var = 1.0;
1953 CHECK(float_var.identity_compare(float_var));
1954 CHECK(float_var.identity_compare(1.0));
1955 CHECK_FALSE(float_var.identity_compare(2.0));
1956
1957 Variant int_var = 1;
1958 CHECK(int_var.identity_compare(int_var));
1959 CHECK(int_var.identity_compare(1));
1960 CHECK_FALSE(int_var.identity_compare(2));
1961
1962 Variant nil = Variant();
1963 CHECK(nil.identity_compare(nil));
1964 CHECK(nil.identity_compare(Variant()));
1965 CHECK_FALSE(nil.identity_compare(true));
1966
1967 Variant node_path = NodePath("godot");
1968 CHECK(node_path.identity_compare(node_path));
1969 CHECK(node_path.identity_compare(NodePath("godot")));
1970 CHECK_FALSE(node_path.identity_compare(NodePath("waiting")));
1971
1972 Variant plane = Plane();
1973 CHECK(plane.identity_compare(plane));
1974 CHECK(plane.identity_compare(Plane()));
1975 CHECK_FALSE(plane.identity_compare(Plane(Vector3(1, 2, 3), 42)));
1976
1977 Variant projection = Projection();
1978 CHECK(projection.identity_compare(projection));
1979 CHECK(projection.identity_compare(Projection()));
1980 CHECK_FALSE(projection.identity_compare(Projection(Transform3D(Basis(Vector3(1, 2, 3).normalized(), 45), Vector3(1, 2, 3)))));
1981
1982 Variant quaternion = Quaternion();
1983 CHECK(quaternion.identity_compare(quaternion));
1984 CHECK(quaternion.identity_compare(Quaternion()));
1985 CHECK_FALSE(quaternion.identity_compare(Quaternion(Vector3(1, 2, 3).normalized(), 45)));
1986
1987 Variant rect2 = Rect2();
1988 CHECK(rect2.identity_compare(rect2));
1989 CHECK(rect2.identity_compare(Rect2()));
1990 CHECK_FALSE(rect2.identity_compare(Rect2(Point2(Vector2(1, 2)), Size2(Vector2(1, 2)))));
1991
1992 Variant rect2i = Rect2i();
1993 CHECK(rect2i.identity_compare(rect2i));
1994 CHECK(rect2i.identity_compare(Rect2i()));
1995 CHECK_FALSE(rect2i.identity_compare(Rect2i(Point2i(Vector2i(1, 2)), Size2i(Vector2i(1, 2)))));
1996
1997 Variant rid = RID();
1998 CHECK(rid.identity_compare(rid));
1999 CHECK(rid.identity_compare(RID()));
2000 CHECK_FALSE(rid.identity_compare(RID::from_uint64(123)));
2001
2002 Variant signal = Signal();
2003 CHECK(signal.identity_compare(signal));
2004 CHECK(signal.identity_compare(Signal()));
2005 CHECK_FALSE(signal.identity_compare(Signal(ObjectID(), StringName("lambda"))));
2006
2007 Variant str = "godot";
2008 CHECK(str.identity_compare(str));
2009 CHECK(str.identity_compare("godot"));
2010 CHECK_FALSE(str.identity_compare("waiting"));
2011
2012 Variant str_name = StringName("godot");
2013 CHECK(str_name.identity_compare(str_name));
2014 CHECK(str_name.identity_compare(StringName("godot")));
2015 CHECK_FALSE(str_name.identity_compare(StringName("waiting")));
2016
2017 Variant transform2d = Transform2D();
2018 CHECK(transform2d.identity_compare(transform2d));
2019 CHECK(transform2d.identity_compare(Transform2D()));
2020 CHECK_FALSE(transform2d.identity_compare(Transform2D(45, Vector2(1, 2))));
2021
2022 Variant transform3d = Transform3D();
2023 CHECK(transform3d.identity_compare(transform3d));
2024 CHECK(transform3d.identity_compare(Transform3D()));
2025 CHECK_FALSE(transform3d.identity_compare(Transform3D(Basis(Quaternion(Vector3(1, 2, 3).normalized(), 45)), Vector3(1, 2, 3))));
2026
2027 Variant vect2 = Vector2();
2028 CHECK(vect2.identity_compare(vect2));
2029 CHECK(vect2.identity_compare(Vector2()));
2030 CHECK_FALSE(vect2.identity_compare(Vector2(1, 2)));
2031
2032 Variant vect2i = Vector2i();
2033 CHECK(vect2i.identity_compare(vect2i));
2034 CHECK(vect2i.identity_compare(Vector2i()));
2035 CHECK_FALSE(vect2i.identity_compare(Vector2i(1, 2)));
2036
2037 Variant vect3 = Vector3();
2038 CHECK(vect3.identity_compare(vect3));
2039 CHECK(vect3.identity_compare(Vector3()));
2040 CHECK_FALSE(vect3.identity_compare(Vector3(1, 2, 3)));
2041
2042 Variant vect3i = Vector3i();
2043 CHECK(vect3i.identity_compare(vect3i));
2044 CHECK(vect3i.identity_compare(Vector3i()));
2045 CHECK_FALSE(vect3i.identity_compare(Vector3i(1, 2, 3)));
2046
2047 Variant vect4 = Vector4();
2048 CHECK(vect4.identity_compare(vect4));
2049 CHECK(vect4.identity_compare(Vector4()));
2050 CHECK_FALSE(vect4.identity_compare(Vector4(1, 2, 3, 4)));
2051
2052 Variant vect4i = Vector4i();
2053 CHECK(vect4i.identity_compare(vect4i));
2054 CHECK(vect4i.identity_compare(Vector4i()));
2055 CHECK_FALSE(vect4i.identity_compare(Vector4i(1, 2, 3, 4)));
2056
2057 // Reference types are compared by reference
2058 Variant array = Array();
2059 CHECK(array.identity_compare(array));
2060 CHECK_FALSE(array.identity_compare(Array()));
2061
2062 Variant dictionary = Dictionary();
2063 CHECK(dictionary.identity_compare(dictionary));
2064 CHECK_FALSE(dictionary.identity_compare(Dictionary()));
2065
2066 Variant packed_byte_array = PackedByteArray();
2067 CHECK(packed_byte_array.identity_compare(packed_byte_array));
2068 CHECK_FALSE(packed_byte_array.identity_compare(PackedByteArray()));
2069
2070 Variant packed_color_array = PackedColorArray();
2071 CHECK(packed_color_array.identity_compare(packed_color_array));
2072 CHECK_FALSE(packed_color_array.identity_compare(PackedColorArray()));
2073
2074 Variant packed_vector4_array = PackedVector4Array();
2075 CHECK(packed_vector4_array.identity_compare(packed_vector4_array));
2076 CHECK_FALSE(packed_vector4_array.identity_compare(PackedVector4Array()));
2077
2078 Variant packed_float32_array = PackedFloat32Array();
2079 CHECK(packed_float32_array.identity_compare(packed_float32_array));
2080 CHECK_FALSE(packed_float32_array.identity_compare(PackedFloat32Array()));
2081
2082 Variant packed_float64_array = PackedFloat64Array();
2083 CHECK(packed_float64_array.identity_compare(packed_float64_array));
2084 CHECK_FALSE(packed_float64_array.identity_compare(PackedFloat64Array()));
2085
2086 Variant packed_int32_array = PackedInt32Array();
2087 CHECK(packed_int32_array.identity_compare(packed_int32_array));
2088 CHECK_FALSE(packed_int32_array.identity_compare(PackedInt32Array()));
2089
2090 Variant packed_int64_array = PackedInt64Array();
2091 CHECK(packed_int64_array.identity_compare(packed_int64_array));
2092 CHECK_FALSE(packed_int64_array.identity_compare(PackedInt64Array()));
2093
2094 Variant packed_string_array = PackedStringArray();
2095 CHECK(packed_string_array.identity_compare(packed_string_array));
2096 CHECK_FALSE(packed_string_array.identity_compare(PackedStringArray()));
2097
2098 Variant packed_vector2_array = PackedVector2Array();
2099 CHECK(packed_vector2_array.identity_compare(packed_vector2_array));
2100 CHECK_FALSE(packed_vector2_array.identity_compare(PackedVector2Array()));
2101
2102 Variant packed_vector3_array = PackedVector3Array();
2103 CHECK(packed_vector3_array.identity_compare(packed_vector3_array));
2104 CHECK_FALSE(packed_vector3_array.identity_compare(PackedVector3Array()));
2105
2106 Object obj_one = Object();
2107 Variant obj_one_var = &obj_one;
2108 Object obj_two = Object();
2109 Variant obj_two_var = &obj_two;
2110 CHECK(obj_one_var.identity_compare(obj_one_var));
2111 CHECK_FALSE(obj_one_var.identity_compare(obj_two_var));
2112
2113 Variant obj_null_one_var = Variant((Object *)nullptr);
2114 Variant obj_null_two_var = Variant((Object *)nullptr);
2115 CHECK(obj_null_one_var.identity_compare(obj_null_one_var));
2116 CHECK(obj_null_one_var.identity_compare(obj_null_two_var));
2117
2118 Object *freed_one = new Object();
2119 Variant freed_one_var = freed_one;
2120 delete freed_one;
2121 Object *freed_two = new Object();
2122 Variant freed_two_var = freed_two;
2123 delete freed_two;
2124 CHECK_FALSE(freed_one_var.identity_compare(freed_two_var));
2125 }
2126
2127 TEST_CASE("[Variant] Nested array comparison") {
2128 Array a1 = { 1, { 2, 3 } };
2129 Array a2 = { 1, { 2, 3 } };
2130 Array a_other = { 1, { 2, 4 } };
2131 Variant v_a1 = a1;
2132 Variant v_a1_ref2 = a1;
2133 Variant v_a2 = a2;
2134 Variant v_a_other = a_other;
2135
2136 // test both operator== and operator!=
2137 CHECK_EQ(v_a1, v_a1);
2138 CHECK_FALSE(v_a1 != v_a1);
2139 CHECK_EQ(v_a1, v_a1_ref2);
2140 CHECK_FALSE(v_a1 != v_a1_ref2);
2141 CHECK_EQ(v_a1, v_a2);
2142 CHECK_FALSE(v_a1 != v_a2);
2143 CHECK_NE(v_a1, v_a_other);
2144 CHECK_FALSE(v_a1 == v_a_other);
2145 }
2146
2147 TEST_CASE("[Variant] Nested dictionary comparison") {
2148 Dictionary d1 = { { Dictionary({ { 1, 2 } }), Dictionary({ { 3, 4 } }) } };
2149 Dictionary d2 = { { Dictionary({ { 1, 2 } }), Dictionary({ { 3, 4 } }) } };
2150 Dictionary d_other_key = { { Dictionary({ { 1, 0 } }), Dictionary({ { 3, 4 } }) } };
2151 Dictionary d_other_val = { { Dictionary({ { 1, 2 } }), Dictionary({ { 3, 0 } }) } };
2152 Variant v_d1 = d1;
2153 Variant v_d1_ref2 = d1;
2154 Variant v_d2 = d2;
2155 Variant v_d_other_key = d_other_key;
2156 Variant v_d_other_val = d_other_val;
2157
2158 // test both operator== and operator!=
2159 CHECK_EQ(v_d1, v_d1);
2160 CHECK_FALSE(v_d1 != v_d1);
2161 CHECK_EQ(v_d1, v_d1_ref2);
2162 CHECK_FALSE(v_d1 != v_d1_ref2);
2163 CHECK_EQ(v_d1, v_d2);
2164 CHECK_FALSE(v_d1 != v_d2);
2165 CHECK_NE(v_d1, v_d_other_key);
2166 CHECK_FALSE(v_d1 == v_d_other_key);
2167 CHECK_NE(v_d1, v_d_other_val);
2168 CHECK_FALSE(v_d1 == v_d_other_val);
2169 }
2170
2171 struct ArgumentData {
2172 Variant::Type type;
2173 String name;
2174 bool has_defval = false;
2175 Variant defval;
2176 int position;
2177 };
2178
2179 struct MethodData {
2180 StringName name;
2181 Variant::Type return_type;
2182 List<ArgumentData> arguments;
2183 bool is_virtual = false;
2184 bool is_vararg = false;
2185 };
2186
2187 TEST_CASE("[Variant] Utility functions") {
2188 List<MethodData> functions;
2189
2190 List<StringName> function_names;
2191 Variant::get_utility_function_list(&function_names);
2192 function_names.sort_custom<StringName::AlphCompare>();
2193
2194 for (const StringName &E : function_names) {
2195 MethodData md;
2196 md.name = E;
2197
2198 // Utility function's return type.
2199 if (Variant::has_utility_function_return_value(E)) {
2200 md.return_type = Variant::get_utility_function_return_type(E);
2201 }
2202
2203 // Utility function's arguments.
2204 if (Variant::is_utility_function_vararg(E)) {
2205 md.is_vararg = true;
2206 } else {
2207 for (int i = 0; i < Variant::get_utility_function_argument_count(E); i++) {
2208 ArgumentData arg;
2209 arg.type = Variant::get_utility_function_argument_type(E, i);
2210 arg.name = Variant::get_utility_function_argument_name(E, i);
2211 arg.position = i;
2212
2213 md.arguments.push_back(arg);
2214 }
2215 }
2216
2217 functions.push_back(md);
2218 }
2219
2220 SUBCASE("[Variant] Validate utility functions") {
2221 for (const MethodData &E : functions) {
2222 for (const ArgumentData &F : E.arguments) {
2223 const ArgumentData &arg = F;
2224
2225 TEST_COND((arg.name.is_empty() || arg.name.begins_with("_unnamed_arg")),
2226 vformat("Unnamed argument in position %d of function '%s'.", arg.position, E.name));
2227 }
2228 }
2229 }
2230 }
2231
2232 TEST_CASE("[Variant] Operator NOT") {
2233 // Verify that operator NOT works for all types and is consistent with booleanize().
2234 for (int i = 0; i < Variant::VARIANT_MAX; i++) {
2235 Variant value;
2236 Callable::CallError err;
2237 Variant::construct((Variant::Type)i, value, nullptr, 0, err);
2238
2239 REQUIRE_EQ(err.error, Callable::CallError::CALL_OK);
2240
2241 Variant result = Variant::evaluate(Variant::OP_NOT, value, Variant());
2242
2243 REQUIRE_EQ(result.get_type(), Variant::BOOL);
2244 CHECK_EQ(!value.booleanize(), result.operator bool());
2245 }
2246 }
2247
2248 } // namespace TestVariant