Path: blob/master/tests/core/variant/test_variant.cpp
23450 views
/**************************************************************************/1/* test_variant.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "tests/test_macros.h"3132TEST_FORCE_LINK(test_variant)3334#include "core/variant/variant.h"35#include "core/variant/variant_parser.h"3637namespace TestVariant {3839TEST_CASE("[Variant] Writer and parser integer") {40int64_t a32 = 2147483648; // 2^31, so out of bounds for 32-bit signed int [-2^31, +2^31-1].41String a32_str;42VariantWriter::write_to_string(a32, a32_str);4344CHECK_MESSAGE(a32_str != "-2147483648", "Should not wrap around");4546int64_t b64 = 9223372036854775807; // 2^63-1, upper bound for signed 64-bit int.47String b64_str;48VariantWriter::write_to_string(b64, b64_str);4950CHECK_MESSAGE(b64_str == "9223372036854775807", "Should not wrap around.");5152VariantParser::StreamString ss;53String errs;54int line;55Variant b64_parsed;56int64_t b64_int_parsed;5758ss.s = b64_str;59VariantParser::parse(&ss, b64_parsed, errs, line);60b64_int_parsed = b64_parsed;6162CHECK_MESSAGE(b64_int_parsed == 9223372036854775807, "Should parse back.");6364ss.s = "9223372036854775808"; // Overflowed by one.65VariantParser::parse(&ss, b64_parsed, errs, line);66b64_int_parsed = b64_parsed;6768CHECK_MESSAGE(b64_int_parsed == 9223372036854775807, "The result should be clamped to max value.");6970ss.s = "1e100"; // Googol! Scientific notation.71VariantParser::parse(&ss, b64_parsed, errs, line);72b64_int_parsed = b64_parsed;7374CHECK_MESSAGE(b64_int_parsed == 9223372036854775807, "The result should be clamped to max value.");75}7677TEST_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.80double a64 = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0;81String a64_str;82VariantWriter::write_to_string(a64, a64_str);8384CHECK_MESSAGE(a64_str == "1.7976931348623157e+308", "Writes in scientific notation.");85CHECK_MESSAGE(a64_str != "inf", "Should not overflow.");86CHECK_MESSAGE(a64_str != "nan", "The result should be defined.");8788String errs;89int line;90Variant variant_parsed;91double float_parsed;9293VariantParser::StreamString bss;94bss.s = a64_str;95VariantParser::parse(&bss, variant_parsed, errs, line);96float_parsed = variant_parsed;97// Loses precision, but that's alright.98CHECK_MESSAGE(float_parsed == 1.797693134862315708145274237317e+308, "Should parse back.");99100// Approximation of Googol with a double-precision float.101VariantParser::StreamString css;102css.s = "1.0e+100";103VariantParser::parse(&css, variant_parsed, errs, line);104float_parsed = variant_parsed;105CHECK_MESSAGE(float_parsed == 1.0e+100, "Should match the double literal.");106}107108TEST_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") {109Variant int_v = 0;110Variant bool_v = true;111int_v = bool_v; // int_v is now a bool112CHECK(int_v == Variant(true));113bool_v = false;114int_v = bool_v;115CHECK(int_v.get_type() == Variant::BOOL);116117Variant float_v = 0.0f;118bool_v = true;119float_v = bool_v;120CHECK(float_v == Variant(true));121bool_v = false;122float_v = bool_v;123CHECK(float_v.get_type() == Variant::BOOL);124125Variant string_v = "";126bool_v = true;127string_v = bool_v;128CHECK(string_v == Variant(true));129bool_v = false;130string_v = bool_v;131CHECK(string_v.get_type() == Variant::BOOL);132133Variant vec2_v = Vector2(0, 0);134bool_v = true;135vec2_v = bool_v;136CHECK(vec2_v == Variant(true));137bool_v = false;138vec2_v = bool_v;139CHECK(vec2_v.get_type() == Variant::BOOL);140141Variant vec2i_v = Vector2i(0, 0);142bool_v = true;143vec2i_v = bool_v;144CHECK(vec2i_v == Variant(true));145bool_v = false;146vec2i_v = bool_v;147CHECK(vec2i_v.get_type() == Variant::BOOL);148149Variant vec3_v = Vector3(0, 0, 0);150bool_v = true;151vec3_v = bool_v;152CHECK(vec3_v == Variant(true));153bool_v = false;154vec3_v = bool_v;155CHECK(vec3_v.get_type() == Variant::BOOL);156157Variant vec3i_v = Vector3i(0, 0, 0);158bool_v = true;159vec3i_v = bool_v;160CHECK(vec3i_v == Variant(true));161bool_v = false;162vec3i_v = bool_v;163CHECK(vec3i_v.get_type() == Variant::BOOL);164165Variant vec4_v = Vector4(0, 0, 0, 0);166bool_v = true;167vec4_v = bool_v;168CHECK(vec4_v == Variant(true));169bool_v = false;170vec4_v = bool_v;171CHECK(vec4_v.get_type() == Variant::BOOL);172173Variant vec4i_v = Vector4i(0, 0, 0, 0);174bool_v = true;175vec4i_v = bool_v;176CHECK(vec4i_v == Variant(true));177bool_v = false;178vec4i_v = bool_v;179CHECK(vec4i_v.get_type() == Variant::BOOL);180181Variant rect2_v = Rect2();182bool_v = true;183rect2_v = bool_v;184CHECK(rect2_v == Variant(true));185bool_v = false;186rect2_v = bool_v;187CHECK(rect2_v.get_type() == Variant::BOOL);188189Variant rect2i_v = Rect2i();190bool_v = true;191rect2i_v = bool_v;192CHECK(rect2i_v == Variant(true));193bool_v = false;194rect2i_v = bool_v;195CHECK(rect2i_v.get_type() == Variant::BOOL);196197Variant transform2d_v = Transform2D();198bool_v = true;199transform2d_v = bool_v;200CHECK(transform2d_v == Variant(true));201bool_v = false;202transform2d_v = bool_v;203CHECK(transform2d_v.get_type() == Variant::BOOL);204205Variant transform3d_v = Transform3D();206bool_v = true;207transform3d_v = bool_v;208CHECK(transform3d_v == Variant(true));209bool_v = false;210transform3d_v = bool_v;211CHECK(transform3d_v.get_type() == Variant::BOOL);212213Variant col_v = Color(0.5f, 0.2f, 0.75f);214bool_v = true;215col_v = bool_v;216CHECK(col_v == Variant(true));217bool_v = false;218col_v = bool_v;219CHECK(col_v.get_type() == Variant::BOOL);220221Variant call_v = Callable();222bool_v = true;223call_v = bool_v;224CHECK(call_v == Variant(true));225bool_v = false;226call_v = bool_v;227CHECK(call_v.get_type() == Variant::BOOL);228229Variant plane_v = Plane();230bool_v = true;231plane_v = bool_v;232CHECK(plane_v == Variant(true));233bool_v = false;234plane_v = bool_v;235CHECK(plane_v.get_type() == Variant::BOOL);236237Variant basis_v = Basis();238bool_v = true;239basis_v = bool_v;240CHECK(basis_v == Variant(true));241bool_v = false;242basis_v = bool_v;243CHECK(basis_v.get_type() == Variant::BOOL);244245Variant aabb_v = AABB();246bool_v = true;247aabb_v = bool_v;248CHECK(aabb_v == Variant(true));249bool_v = false;250aabb_v = bool_v;251CHECK(aabb_v.get_type() == Variant::BOOL);252253Variant quaternion_v = Quaternion();254bool_v = true;255quaternion_v = bool_v;256CHECK(quaternion_v == Variant(true));257bool_v = false;258quaternion_v = bool_v;259CHECK(quaternion_v.get_type() == Variant::BOOL);260261Variant projection_v = Projection();262bool_v = true;263projection_v = bool_v;264CHECK(projection_v == Variant(true));265bool_v = false;266projection_v = bool_v;267CHECK(projection_v.get_type() == Variant::BOOL);268269Variant rid_v = RID();270bool_v = true;271rid_v = bool_v;272CHECK(rid_v == Variant(true));273bool_v = false;274rid_v = bool_v;275CHECK(rid_v.get_type() == Variant::BOOL);276277Object obj_one = Object();278Variant object_v = &obj_one;279bool_v = true;280object_v = bool_v;281CHECK(object_v == Variant(true));282bool_v = false;283object_v = bool_v;284CHECK(object_v.get_type() == Variant::BOOL);285}286287TEST_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") {288Variant bool_v = false;289Variant int_v = 2;290bool_v = int_v; // Now bool_v is int291CHECK(bool_v == Variant(2));292int_v = -3;293bool_v = int_v;294CHECK(bool_v.get_type() == Variant::INT);295296Variant float_v = 0.0f;297int_v = 2;298float_v = int_v;299CHECK(float_v == Variant(2));300int_v = -3;301float_v = int_v;302CHECK(float_v.get_type() == Variant::INT);303304Variant string_v = "";305int_v = 2;306string_v = int_v;307CHECK(string_v == Variant(2));308int_v = -3;309string_v = int_v;310CHECK(string_v.get_type() == Variant::INT);311312Variant vec2_v = Vector2(0, 0);313int_v = 2;314vec2_v = int_v;315CHECK(vec2_v == Variant(2));316int_v = -3;317vec2_v = int_v;318CHECK(vec2_v.get_type() == Variant::INT);319320Variant vec2i_v = Vector2i(0, 0);321int_v = 2;322vec2i_v = int_v;323CHECK(vec2i_v == Variant(2));324int_v = -3;325vec2i_v = int_v;326CHECK(vec2i_v.get_type() == Variant::INT);327328Variant vec3_v = Vector3(0, 0, 0);329int_v = 2;330vec3_v = int_v;331CHECK(vec3_v == Variant(2));332int_v = -3;333vec3_v = int_v;334CHECK(vec3_v.get_type() == Variant::INT);335336Variant vec3i_v = Vector3i(0, 0, 0);337int_v = 2;338vec3i_v = int_v;339CHECK(vec3i_v == Variant(2));340int_v = -3;341vec3i_v = int_v;342CHECK(vec3i_v.get_type() == Variant::INT);343344Variant vec4_v = Vector4(0, 0, 0, 0);345int_v = 2;346vec4_v = int_v;347CHECK(vec4_v == Variant(2));348int_v = -3;349vec4_v = int_v;350CHECK(vec4_v.get_type() == Variant::INT);351352Variant vec4i_v = Vector4i(0, 0, 0, 0);353int_v = 2;354vec4i_v = int_v;355CHECK(vec4i_v == Variant(2));356int_v = -3;357vec4i_v = int_v;358CHECK(vec4i_v.get_type() == Variant::INT);359360Variant rect2_v = Rect2();361int_v = 2;362rect2_v = int_v;363CHECK(rect2_v == Variant(2));364int_v = -3;365rect2_v = int_v;366CHECK(rect2_v.get_type() == Variant::INT);367368Variant rect2i_v = Rect2i();369int_v = 2;370rect2i_v = int_v;371CHECK(rect2i_v == Variant(2));372int_v = -3;373rect2i_v = int_v;374CHECK(rect2i_v.get_type() == Variant::INT);375376Variant transform2d_v = Transform2D();377int_v = 2;378transform2d_v = int_v;379CHECK(transform2d_v == Variant(2));380int_v = -3;381transform2d_v = int_v;382CHECK(transform2d_v.get_type() == Variant::INT);383384Variant transform3d_v = Transform3D();385int_v = 2;386transform3d_v = int_v;387CHECK(transform3d_v == Variant(2));388int_v = -3;389transform3d_v = int_v;390CHECK(transform3d_v.get_type() == Variant::INT);391392Variant col_v = Color(0.5f, 0.2f, 0.75f);393int_v = 2;394col_v = int_v;395CHECK(col_v == Variant(2));396int_v = -3;397col_v = int_v;398CHECK(col_v.get_type() == Variant::INT);399400Variant call_v = Callable();401int_v = 2;402call_v = int_v;403CHECK(call_v == Variant(2));404int_v = -3;405call_v = int_v;406CHECK(call_v.get_type() == Variant::INT);407408Variant plane_v = Plane();409int_v = 2;410plane_v = int_v;411CHECK(plane_v == Variant(2));412int_v = -3;413plane_v = int_v;414CHECK(plane_v.get_type() == Variant::INT);415416Variant basis_v = Basis();417int_v = 2;418basis_v = int_v;419CHECK(basis_v == Variant(2));420int_v = -3;421basis_v = int_v;422CHECK(basis_v.get_type() == Variant::INT);423424Variant aabb_v = AABB();425int_v = 2;426aabb_v = int_v;427CHECK(aabb_v == Variant(2));428int_v = -3;429aabb_v = int_v;430CHECK(aabb_v.get_type() == Variant::INT);431432Variant quaternion_v = Quaternion();433int_v = 2;434quaternion_v = int_v;435CHECK(quaternion_v == Variant(2));436int_v = -3;437quaternion_v = int_v;438CHECK(quaternion_v.get_type() == Variant::INT);439440Variant projection_v = Projection();441int_v = 2;442projection_v = int_v;443CHECK(projection_v == Variant(2));444int_v = -3;445projection_v = int_v;446CHECK(projection_v.get_type() == Variant::INT);447448Variant rid_v = RID();449int_v = 2;450rid_v = int_v;451CHECK(rid_v == Variant(2));452bool_v = -3;453rid_v = int_v;454CHECK(rid_v.get_type() == Variant::INT);455456Object obj_one = Object();457Variant object_v = &obj_one;458int_v = 2;459object_v = int_v;460CHECK(object_v == Variant(2));461int_v = -3;462object_v = int_v;463CHECK(object_v.get_type() == Variant::INT);464}465466TEST_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") {467Variant bool_v = false;468Variant float_v = 1.5f;469bool_v = float_v; // Now bool_v is float470CHECK(bool_v == Variant(1.5f));471float_v = -4.6f;472bool_v = float_v;473CHECK(bool_v.get_type() == Variant::FLOAT);474475Variant int_v = 1;476float_v = 1.5f;477int_v = float_v;478CHECK(int_v == Variant(1.5f));479float_v = -4.6f;480int_v = float_v;481CHECK(int_v.get_type() == Variant::FLOAT);482483Variant string_v = "";484float_v = 1.5f;485string_v = float_v;486CHECK(string_v == Variant(1.5f));487float_v = -4.6f;488string_v = float_v;489CHECK(string_v.get_type() == Variant::FLOAT);490491Variant vec2_v = Vector2(0, 0);492float_v = 1.5f;493vec2_v = float_v;494CHECK(vec2_v == Variant(1.5f));495float_v = -4.6f;496vec2_v = float_v;497CHECK(vec2_v.get_type() == Variant::FLOAT);498499Variant vec2i_v = Vector2i(0, 0);500float_v = 1.5f;501vec2i_v = float_v;502CHECK(vec2i_v == Variant(1.5f));503float_v = -4.6f;504vec2i_v = float_v;505CHECK(vec2i_v.get_type() == Variant::FLOAT);506507Variant vec3_v = Vector3(0, 0, 0);508float_v = 1.5f;509vec3_v = float_v;510CHECK(vec3_v == Variant(1.5f));511float_v = -4.6f;512vec3_v = float_v;513CHECK(vec3_v.get_type() == Variant::FLOAT);514515Variant vec3i_v = Vector3i(0, 0, 0);516float_v = 1.5f;517vec3i_v = float_v;518CHECK(vec3i_v == Variant(1.5f));519float_v = -4.6f;520vec3i_v = float_v;521CHECK(vec3i_v.get_type() == Variant::FLOAT);522523Variant vec4_v = Vector4(0, 0, 0, 0);524float_v = 1.5f;525vec4_v = float_v;526CHECK(vec4_v == Variant(1.5f));527float_v = -4.6f;528vec4_v = float_v;529CHECK(vec4_v.get_type() == Variant::FLOAT);530531Variant vec4i_v = Vector4i(0, 0, 0, 0);532float_v = 1.5f;533vec4i_v = float_v;534CHECK(vec4i_v == Variant(1.5f));535float_v = -4.6f;536vec4i_v = float_v;537CHECK(vec4i_v.get_type() == Variant::FLOAT);538539Variant rect2_v = Rect2();540float_v = 1.5f;541rect2_v = float_v;542CHECK(rect2_v == Variant(1.5f));543float_v = -4.6f;544rect2_v = float_v;545CHECK(rect2_v.get_type() == Variant::FLOAT);546547Variant rect2i_v = Rect2i();548float_v = 1.5f;549rect2i_v = float_v;550CHECK(rect2i_v == Variant(1.5f));551float_v = -4.6f;552rect2i_v = float_v;553CHECK(rect2i_v.get_type() == Variant::FLOAT);554555Variant transform2d_v = Transform2D();556float_v = 1.5f;557transform2d_v = float_v;558CHECK(transform2d_v == Variant(1.5f));559float_v = -4.6f;560transform2d_v = float_v;561CHECK(transform2d_v.get_type() == Variant::FLOAT);562563Variant transform3d_v = Transform3D();564float_v = 1.5f;565transform3d_v = float_v;566CHECK(transform3d_v == Variant(1.5f));567float_v = -4.6f;568transform3d_v = float_v;569CHECK(transform2d_v.get_type() == Variant::FLOAT);570571Variant col_v = Color(0.5f, 0.2f, 0.75f);572float_v = 1.5f;573col_v = float_v;574CHECK(col_v == Variant(1.5f));575float_v = -4.6f;576col_v = float_v;577CHECK(col_v.get_type() == Variant::FLOAT);578579Variant call_v = Callable();580float_v = 1.5f;581call_v = float_v;582CHECK(call_v == Variant(1.5f));583float_v = -4.6f;584call_v = float_v;585CHECK(call_v.get_type() == Variant::FLOAT);586587Variant plane_v = Plane();588float_v = 1.5f;589plane_v = float_v;590CHECK(plane_v == Variant(1.5f));591float_v = -4.6f;592plane_v = float_v;593CHECK(plane_v.get_type() == Variant::FLOAT);594595Variant basis_v = Basis();596float_v = 1.5f;597basis_v = float_v;598CHECK(basis_v == Variant(1.5f));599float_v = -4.6f;600basis_v = float_v;601CHECK(basis_v.get_type() == Variant::FLOAT);602603Variant aabb_v = AABB();604float_v = 1.5f;605aabb_v = float_v;606CHECK(aabb_v == Variant(1.5f));607float_v = -4.6f;608aabb_v = float_v;609CHECK(aabb_v.get_type() == Variant::FLOAT);610611Variant quaternion_v = Quaternion();612float_v = 1.5f;613quaternion_v = float_v;614CHECK(quaternion_v == Variant(1.5f));615float_v = -4.6f;616quaternion_v = float_v;617CHECK(quaternion_v.get_type() == Variant::FLOAT);618619Variant projection_v = Projection();620float_v = 1.5f;621projection_v = float_v;622CHECK(projection_v == Variant(1.5f));623float_v = -4.6f;624projection_v = float_v;625CHECK(projection_v.get_type() == Variant::FLOAT);626627Variant rid_v = RID();628float_v = 1.5f;629rid_v = float_v;630CHECK(rid_v == Variant(1.5f));631float_v = -4.6f;632rid_v = float_v;633CHECK(rid_v.get_type() == Variant::FLOAT);634635Object obj_one = Object();636Variant object_v = &obj_one;637float_v = 1.5f;638object_v = float_v;639CHECK(object_v == Variant(1.5f));640float_v = -4.6f;641object_v = float_v;642CHECK(object_v.get_type() == Variant::FLOAT);643}644645TEST_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") {646Variant bool_v = false;647Variant string_v = "Hello";648bool_v = string_v; // Now bool_v is string649CHECK(bool_v == Variant("Hello"));650string_v = "Hello there";651bool_v = string_v;652CHECK(bool_v.get_type() == Variant::STRING);653654Variant int_v = 0;655string_v = "Hello";656int_v = string_v;657CHECK(int_v == Variant("Hello"));658string_v = "Hello there";659int_v = string_v;660CHECK(int_v.get_type() == Variant::STRING);661662Variant float_v = 0.0f;663string_v = "Hello";664float_v = string_v;665CHECK(float_v == Variant("Hello"));666string_v = "Hello there";667float_v = string_v;668CHECK(float_v.get_type() == Variant::STRING);669670Variant vec2_v = Vector2(0, 0);671string_v = "Hello";672vec2_v = string_v;673CHECK(vec2_v == Variant("Hello"));674string_v = "Hello there";675vec2_v = string_v;676CHECK(vec2_v.get_type() == Variant::STRING);677678Variant vec2i_v = Vector2i(0, 0);679string_v = "Hello";680vec2i_v = string_v;681CHECK(vec2i_v == Variant("Hello"));682string_v = "Hello there";683vec2i_v = string_v;684CHECK(vec2i_v.get_type() == Variant::STRING);685686Variant vec3_v = Vector3(0, 0, 0);687string_v = "Hello";688vec3_v = string_v;689CHECK(vec3_v == Variant("Hello"));690string_v = "Hello there";691vec3_v = string_v;692CHECK(vec3_v.get_type() == Variant::STRING);693694Variant vec3i_v = Vector3i(0, 0, 0);695string_v = "Hello";696vec3i_v = string_v;697CHECK(vec3i_v == Variant("Hello"));698string_v = "Hello there";699vec3i_v = string_v;700CHECK(vec3i_v.get_type() == Variant::STRING);701702Variant vec4_v = Vector4(0, 0, 0, 0);703string_v = "Hello";704vec4_v = string_v;705CHECK(vec4_v == Variant("Hello"));706string_v = "Hello there";707vec4_v = string_v;708CHECK(vec4_v.get_type() == Variant::STRING);709710Variant vec4i_v = Vector4i(0, 0, 0, 0);711string_v = "Hello";712vec4i_v = string_v;713CHECK(vec4i_v == Variant("Hello"));714string_v = "Hello there";715vec4i_v = string_v;716CHECK(vec4i_v.get_type() == Variant::STRING);717718Variant rect2_v = Rect2();719string_v = "Hello";720rect2_v = string_v;721CHECK(rect2_v == Variant("Hello"));722string_v = "Hello there";723rect2_v = string_v;724CHECK(rect2_v.get_type() == Variant::STRING);725726Variant rect2i_v = Rect2i();727string_v = "Hello";728rect2i_v = string_v;729CHECK(rect2i_v == Variant("Hello"));730string_v = "Hello there";731rect2i_v = string_v;732CHECK(rect2i_v.get_type() == Variant::STRING);733734Variant transform2d_v = Transform2D();735string_v = "Hello";736transform2d_v = string_v;737CHECK(transform2d_v == Variant("Hello"));738string_v = "Hello there";739transform2d_v = string_v;740CHECK(transform2d_v.get_type() == Variant::STRING);741742Variant transform3d_v = Transform3D();743string_v = "Hello";744transform3d_v = string_v;745CHECK(transform3d_v == Variant("Hello"));746string_v = "Hello there";747transform3d_v = string_v;748CHECK(transform3d_v.get_type() == Variant::STRING);749750Variant col_v = Color(0.5f, 0.2f, 0.75f);751string_v = "Hello";752col_v = string_v;753CHECK(col_v == Variant("Hello"));754string_v = "Hello there";755col_v = string_v;756CHECK(col_v.get_type() == Variant::STRING);757758Variant call_v = Callable();759string_v = "Hello";760call_v = string_v;761CHECK(call_v == Variant("Hello"));762string_v = "Hello there";763call_v = string_v;764CHECK(call_v.get_type() == Variant::STRING);765766Variant plane_v = Plane();767string_v = "Hello";768plane_v = string_v;769CHECK(plane_v == Variant("Hello"));770string_v = "Hello there";771plane_v = string_v;772CHECK(plane_v.get_type() == Variant::STRING);773774Variant basis_v = Basis();775string_v = "Hello";776basis_v = string_v;777CHECK(basis_v == Variant("Hello"));778string_v = "Hello there";779basis_v = string_v;780CHECK(basis_v.get_type() == Variant::STRING);781782Variant aabb_v = AABB();783string_v = "Hello";784aabb_v = string_v;785CHECK(aabb_v == Variant("Hello"));786string_v = "Hello there";787aabb_v = string_v;788CHECK(aabb_v.get_type() == Variant::STRING);789790Variant quaternion_v = Quaternion();791string_v = "Hello";792quaternion_v = string_v;793CHECK(quaternion_v == Variant("Hello"));794string_v = "Hello there";795quaternion_v = string_v;796CHECK(quaternion_v.get_type() == Variant::STRING);797798Variant projection_v = Projection();799string_v = "Hello";800projection_v = string_v;801CHECK(projection_v == Variant("Hello"));802string_v = "Hello there";803projection_v = string_v;804CHECK(projection_v.get_type() == Variant::STRING);805806Variant rid_v = RID();807string_v = "Hello";808rid_v = string_v;809CHECK(rid_v == Variant("Hello"));810string_v = "Hello there";811rid_v = string_v;812CHECK(rid_v.get_type() == Variant::STRING);813814Object obj_one = Object();815Variant object_v = &obj_one;816string_v = "Hello";817object_v = string_v;818CHECK(object_v == Variant("Hello"));819string_v = "Hello there";820object_v = string_v;821CHECK(object_v.get_type() == Variant::STRING);822}823824TEST_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") {825Variant bool_v = false;826Variant vec2_v = Vector2(2.2f, 3.5f);827bool_v = vec2_v; // Now bool_v is Vector2828CHECK(bool_v == Variant(Vector2(2.2f, 3.5f)));829vec2_v = Vector2(-5.4f, -7.9f);830bool_v = vec2_v;831CHECK(bool_v.get_type() == Variant::VECTOR2);832833Variant int_v = 0;834vec2_v = Vector2(2.2f, 3.5f);835int_v = vec2_v;836CHECK(int_v == Variant(Vector2(2.2f, 3.5f)));837vec2_v = Vector2(-5.4f, -7.9f);838int_v = vec2_v;839CHECK(int_v.get_type() == Variant::VECTOR2);840841Variant float_v = 0.0f;842vec2_v = Vector2(2.2f, 3.5f);843float_v = vec2_v;844CHECK(float_v == Variant(Vector2(2.2f, 3.5f)));845vec2_v = Vector2(-5.4f, -7.9f);846float_v = vec2_v;847CHECK(float_v.get_type() == Variant::VECTOR2);848849Variant string_v = "";850vec2_v = Vector2(2.2f, 3.5f);851string_v = vec2_v;852CHECK(string_v == Variant(Vector2(2.2f, 3.5f)));853vec2_v = Vector2(-5.4f, -7.9f);854string_v = vec2_v;855CHECK(string_v.get_type() == Variant::VECTOR2);856857Variant vec2i_v = Vector2i(0, 0);858vec2_v = Vector2(2.2f, 3.5f);859vec2i_v = vec2_v;860CHECK(vec2i_v == Variant(Vector2(2.2f, 3.5f)));861vec2_v = Vector2(-5.4f, -7.9f);862vec2i_v = vec2_v;863CHECK(vec2i_v.get_type() == Variant::VECTOR2);864865Variant vec3_v = Vector3(0, 0, 0);866vec2_v = Vector2(2.2f, 3.5f);867vec3_v = vec2_v;868CHECK(vec3_v == Variant(Vector2(2.2f, 3.5f)));869vec2_v = Vector2(-5.4f, -7.9f);870vec3_v = vec2_v;871CHECK(vec3_v.get_type() == Variant::VECTOR2);872873Variant vec3i_v = Vector3i(0, 0, 0);874vec2_v = Vector2(2.2f, 3.5f);875vec3i_v = vec2_v;876CHECK(vec3i_v == Variant(Vector2(2.2f, 3.5f)));877vec2_v = Vector2(-5.4f, -7.9f);878vec3i_v = vec2_v;879CHECK(vec3i_v.get_type() == Variant::VECTOR2);880881Variant vec4_v = Vector4(0, 0, 0, 0);882vec2_v = Vector2(2.2f, 3.5f);883vec4_v = vec2_v;884CHECK(vec4_v == Variant(Vector2(2.2f, 3.5f)));885vec2_v = Vector2(-5.4f, -7.9f);886vec4_v = vec2_v;887CHECK(vec4_v.get_type() == Variant::VECTOR2);888889Variant vec4i_v = Vector4i(0, 0, 0, 0);890vec2_v = Vector2(2.2f, 3.5f);891vec4i_v = vec2_v;892CHECK(vec4i_v == Variant(Vector2(2.2f, 3.5f)));893vec2_v = Vector2(-5.4f, -7.9f);894vec4i_v = vec2_v;895CHECK(vec4i_v.get_type() == Variant::VECTOR2);896897Variant rect2_v = Rect2();898vec2_v = Vector2(2.2f, 3.5f);899rect2_v = vec2_v;900CHECK(rect2_v == Variant(Vector2(2.2f, 3.5f)));901vec2_v = Vector2(-5.4f, -7.9f);902rect2_v = vec2_v;903CHECK(rect2_v.get_type() == Variant::VECTOR2);904905Variant rect2i_v = Rect2i();906vec2_v = Vector2(2.2f, 3.5f);907rect2i_v = vec2_v;908CHECK(rect2i_v == Variant(Vector2(2.2f, 3.5f)));909vec2_v = Vector2(-5.4f, -7.9f);910rect2i_v = vec2_v;911CHECK(rect2i_v.get_type() == Variant::VECTOR2);912913Variant transform2d_v = Transform2D();914vec2_v = Vector2(2.2f, 3.5f);915transform2d_v = vec2_v;916CHECK(transform2d_v == Variant(Vector2(2.2f, 3.5f)));917vec2_v = Vector2(-5.4f, -7.9f);918transform2d_v = vec2_v;919CHECK(transform2d_v.get_type() == Variant::VECTOR2);920921Variant transform3d_v = Transform3D();922vec2_v = Vector2(2.2f, 3.5f);923transform3d_v = vec2_v;924CHECK(transform3d_v == Variant(Vector2(2.2f, 3.5f)));925vec2_v = Vector2(-5.4f, -7.9f);926transform3d_v = vec2_v;927CHECK(transform3d_v.get_type() == Variant::VECTOR2);928929Variant col_v = Color(0.5f, 0.2f, 0.75f);930vec2_v = Vector2(2.2f, 3.5f);931col_v = vec2_v;932CHECK(col_v == Variant(Vector2(2.2f, 3.5f)));933vec2_v = Vector2(-5.4f, -7.9f);934col_v = vec2_v;935CHECK(col_v.get_type() == Variant::VECTOR2);936937Variant call_v = Callable();938vec2_v = Vector2(2.2f, 3.5f);939call_v = vec2_v;940CHECK(call_v == Variant(Vector2(2.2f, 3.5f)));941vec2_v = Vector2(-5.4f, -7.9f);942call_v = vec2_v;943CHECK(call_v.get_type() == Variant::VECTOR2);944945Variant plane_v = Plane();946vec2_v = Vector2(2.2f, 3.5f);947plane_v = vec2_v;948CHECK(plane_v == Variant(Vector2(2.2f, 3.5f)));949vec2_v = Vector2(-5.4f, -7.9f);950plane_v = vec2_v;951CHECK(plane_v.get_type() == Variant::VECTOR2);952953Variant basis_v = Basis();954vec2_v = Vector2(2.2f, 3.5f);955basis_v = vec2_v;956CHECK(basis_v == Variant(Vector2(2.2f, 3.5f)));957vec2_v = Vector2(-5.4f, -7.9f);958basis_v = vec2_v;959CHECK(basis_v.get_type() == Variant::VECTOR2);960961Variant aabb_v = AABB();962vec2_v = Vector2(2.2f, 3.5f);963aabb_v = vec2_v;964CHECK(aabb_v == Variant(Vector2(2.2f, 3.5f)));965vec2_v = Vector2(-5.4f, -7.9f);966aabb_v = vec2_v;967CHECK(aabb_v.get_type() == Variant::VECTOR2);968969Variant quaternion_v = Quaternion();970vec2_v = Vector2(2.2f, 3.5f);971quaternion_v = vec2_v;972CHECK(quaternion_v == Variant(Vector2(2.2f, 3.5f)));973vec2_v = Vector2(-5.4f, -7.9f);974quaternion_v = vec2_v;975CHECK(quaternion_v.get_type() == Variant::VECTOR2);976977Variant projection_v = Projection();978vec2_v = Vector2(2.2f, 3.5f);979projection_v = vec2_v;980CHECK(projection_v == Variant(Vector2(2.2f, 3.5f)));981vec2_v = Vector2(-5.4f, -7.9f);982projection_v = vec2_v;983CHECK(projection_v.get_type() == Variant::VECTOR2);984985Variant rid_v = RID();986vec2_v = Vector2(2.2f, 3.5f);987rid_v = vec2_v;988CHECK(rid_v == Variant(Vector2(2.2f, 3.5f)));989vec2_v = Vector2(-5.4f, -7.9f);990rid_v = vec2_v;991CHECK(rid_v.get_type() == Variant::VECTOR2);992993Object obj_one = Object();994Variant object_v = &obj_one;995vec2_v = Vector2(2.2f, 3.5f);996object_v = vec2_v;997CHECK(object_v == Variant(Vector2(2.2f, 3.5f)));998vec2_v = Vector2(-5.4f, -7.9f);999object_v = vec2_v;1000CHECK(object_v.get_type() == Variant::VECTOR2);1001}10021003TEST_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") {1004Variant bool_v = false;1005Variant vec2i_v = Vector2i(2, 3);1006bool_v = vec2i_v; // Now bool_v is Vector2i1007CHECK(bool_v == Variant(Vector2i(2, 3)));1008vec2i_v = Vector2i(-5, -7);1009bool_v = vec2i_v;1010CHECK(bool_v.get_type() == Variant::VECTOR2I);10111012Variant int_v = 0;1013vec2i_v = Vector2i(2, 3);1014int_v = vec2i_v;1015CHECK(int_v == Variant(Vector2i(2, 3)));1016vec2i_v = Vector2i(-5, -7);1017int_v = vec2i_v;1018CHECK(int_v.get_type() == Variant::VECTOR2I);10191020Variant float_v = 0.0f;1021vec2i_v = Vector2i(2, 3);1022float_v = vec2i_v;1023CHECK(float_v == Variant(Vector2i(2, 3)));1024vec2i_v = Vector2i(-5, -7);1025float_v = vec2i_v;1026CHECK(float_v.get_type() == Variant::VECTOR2I);10271028Variant string_v = "";1029vec2i_v = Vector2i(2, 3);1030string_v = vec2i_v;1031CHECK(string_v == Variant(Vector2i(2, 3)));1032vec2i_v = Vector2i(-5, -7);1033string_v = vec2i_v;1034CHECK(string_v.get_type() == Variant::VECTOR2I);10351036Variant vec2_v = Vector2(0, 0);1037vec2i_v = Vector2i(2, 3);1038vec2_v = vec2i_v;1039CHECK(vec2_v == Variant(Vector2i(2, 3)));1040vec2i_v = Vector2i(-5, -7);1041vec2_v = vec2i_v;1042CHECK(vec2i_v.get_type() == Variant::VECTOR2I);10431044Variant vec3_v = Vector3(0, 0, 0);1045vec2i_v = Vector2i(2, 3);1046vec3_v = vec2i_v;1047CHECK(vec3_v == Variant(Vector2i(2, 3)));1048vec2i_v = Vector2i(-5, -7);1049vec3_v = vec2i_v;1050CHECK(vec3_v.get_type() == Variant::VECTOR2I);10511052Variant vec3i_v = Vector3i(0, 0, 0);1053vec2i_v = Vector2i(2, 3);1054vec3i_v = vec2i_v;1055CHECK(vec3i_v == Variant(Vector2i(2, 3)));1056vec2i_v = Vector2i(-5, -7);1057vec3i_v = vec2i_v;1058CHECK(vec3i_v.get_type() == Variant::VECTOR2I);10591060Variant vec4_v = Vector4(0, 0, 0, 0);1061vec2i_v = Vector2i(2, 3);1062vec4_v = vec2i_v;1063CHECK(vec4_v == Variant(Vector2i(2, 3)));1064vec2i_v = Vector2i(-5, -7);1065vec4_v = vec2i_v;1066CHECK(vec4_v.get_type() == Variant::VECTOR2I);10671068Variant vec4i_v = Vector4i(0, 0, 0, 0);1069vec2i_v = Vector2i(2, 3);1070vec4i_v = vec2i_v;1071CHECK(vec4i_v == Variant(Vector2i(2, 3)));1072vec2i_v = Vector2i(-5, -7);1073vec4i_v = vec2i_v;1074CHECK(vec4i_v.get_type() == Variant::VECTOR2I);10751076Variant rect2_v = Rect2();1077vec2i_v = Vector2i(2, 3);1078rect2_v = vec2i_v;1079CHECK(rect2_v == Variant(Vector2i(2, 3)));1080vec2i_v = Vector2i(-5, -7);1081rect2_v = vec2i_v;1082CHECK(rect2_v.get_type() == Variant::VECTOR2I);10831084Variant rect2i_v = Rect2i();1085vec2i_v = Vector2i(2, 3);1086rect2i_v = vec2i_v;1087CHECK(rect2i_v == Variant(Vector2i(2, 3)));1088vec2i_v = Vector2i(-5, -7);1089rect2i_v = vec2i_v;1090CHECK(rect2i_v.get_type() == Variant::VECTOR2I);10911092Variant transform2d_v = Transform2D();1093vec2i_v = Vector2i(2, 3);1094transform2d_v = vec2i_v;1095CHECK(transform2d_v == Variant(Vector2i(2, 3)));1096vec2i_v = Vector2i(-5, -7);1097transform2d_v = vec2i_v;1098CHECK(transform2d_v.get_type() == Variant::VECTOR2I);10991100Variant transform3d_v = Transform3D();1101vec2i_v = Vector2i(2, 3);1102transform3d_v = vec2i_v;1103CHECK(transform3d_v == Variant(Vector2i(2, 3)));1104vec2i_v = Vector2i(-5, -7);1105transform3d_v = vec2i_v;1106CHECK(transform3d_v.get_type() == Variant::VECTOR2I);11071108Variant col_v = Color(0.5f, 0.2f, 0.75f);1109vec2i_v = Vector2i(2, 3);1110col_v = vec2i_v;1111CHECK(col_v == Variant(Vector2i(2, 3)));1112vec2i_v = Vector2i(-5, -7);1113col_v = vec2i_v;1114CHECK(col_v.get_type() == Variant::VECTOR2I);11151116Variant call_v = Callable();1117vec2i_v = Vector2i(2, 3);1118call_v = vec2i_v;1119CHECK(call_v == Variant(Vector2i(2, 3)));1120vec2i_v = Vector2i(-5, -7);1121call_v = vec2i_v;1122CHECK(call_v.get_type() == Variant::VECTOR2I);11231124Variant plane_v = Plane();1125vec2i_v = Vector2i(2, 3);1126plane_v = vec2i_v;1127CHECK(plane_v == Variant(Vector2i(2, 3)));1128vec2i_v = Vector2i(-5, -7);1129plane_v = vec2i_v;1130CHECK(plane_v.get_type() == Variant::VECTOR2I);11311132Variant basis_v = Basis();1133vec2i_v = Vector2i(2, 3);1134basis_v = vec2i_v;1135CHECK(basis_v == Variant(Vector2i(2, 3)));1136vec2i_v = Vector2i(-5, -7);1137basis_v = vec2i_v;1138CHECK(basis_v.get_type() == Variant::VECTOR2I);11391140Variant aabb_v = AABB();1141vec2i_v = Vector2i(2, 3);1142aabb_v = vec2i_v;1143CHECK(aabb_v == Variant(Vector2i(2, 3)));1144vec2i_v = Vector2i(-5, -7);1145aabb_v = vec2i_v;1146CHECK(aabb_v.get_type() == Variant::VECTOR2I);11471148Variant quaternion_v = Quaternion();1149vec2i_v = Vector2i(2, 3);1150quaternion_v = vec2i_v;1151CHECK(quaternion_v == Variant(Vector2i(2, 3)));1152vec2i_v = Vector2i(-5, -7);1153quaternion_v = vec2i_v;1154CHECK(quaternion_v.get_type() == Variant::VECTOR2I);11551156Variant projection_v = Projection();1157vec2i_v = Vector2i(2, 3);1158projection_v = vec2i_v;1159CHECK(projection_v == Variant(Vector2i(2, 3)));1160vec2i_v = Vector2i(-5, -7);1161projection_v = vec2i_v;1162CHECK(projection_v.get_type() == Variant::VECTOR2I);11631164Variant rid_v = RID();1165vec2i_v = Vector2i(2, 3);1166rid_v = vec2i_v;1167CHECK(rid_v == Variant(Vector2i(2, 3)));1168vec2i_v = Vector2i(-5, -7);1169rid_v = vec2i_v;1170CHECK(rid_v.get_type() == Variant::VECTOR2I);11711172Object obj_one = Object();1173Variant object_v = &obj_one;1174vec2i_v = Vector2i(2, 3);1175object_v = vec2i_v;1176CHECK(object_v == Variant(Vector2i(2, 3)));1177vec2i_v = Vector2i(-5, -7);1178object_v = vec2i_v;1179CHECK(object_v.get_type() == Variant::VECTOR2I);1180}11811182TEST_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") {1183Variant bool_v = false;1184Variant vec3_v = Vector3(2.2f, 3.5f, 5.3f);1185bool_v = vec3_v; // Now bool_v is Vector31186CHECK(bool_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));1187vec3_v = Vector3(-5.4f, -7.9f, -2.1f);1188bool_v = vec3_v;1189CHECK(bool_v.get_type() == Variant::VECTOR3);11901191Variant int_v = 0;1192vec3_v = Vector3(2.2f, 3.5f, 5.3f);1193int_v = vec3_v;1194CHECK(int_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));1195vec3_v = Vector3(-5.4f, -7.9f, -2.1f);1196int_v = vec3_v;1197CHECK(int_v.get_type() == Variant::VECTOR3);11981199Variant float_v = 0.0f;1200vec3_v = Vector3(2.2f, 3.5f, 5.3f);1201float_v = vec3_v;1202CHECK(float_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));1203vec3_v = Vector3(-5.4f, -7.9f, -2.1f);1204float_v = vec3_v;1205CHECK(float_v.get_type() == Variant::VECTOR3);12061207Variant string_v = "";1208vec3_v = Vector3(2.2f, 3.5f, 5.3f);1209string_v = vec3_v;1210CHECK(string_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));1211vec3_v = Vector3(-5.4f, -7.9f, -2.1f);1212string_v = vec3_v;1213CHECK(string_v.get_type() == Variant::VECTOR3);12141215Variant vec2_v = Vector2(0, 0);1216vec3_v = Vector3(2.2f, 3.5f, 5.3f);1217vec2_v = vec3_v;1218CHECK(vec2_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));1219vec3_v = Vector3(-5.4f, -7.9f, -2.1f);1220vec2_v = vec3_v;1221CHECK(vec2_v.get_type() == Variant::VECTOR3);12221223Variant vec2i_v = Vector2i(0, 0);1224vec3_v = Vector3(2.2f, 3.5f, 5.3f);1225vec2i_v = vec3_v;1226CHECK(vec2i_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));1227vec3_v = Vector3(-5.4f, -7.9f, -2.1f);1228vec2i_v = vec3_v;1229CHECK(vec2i_v.get_type() == Variant::VECTOR3);12301231Variant vec3i_v = Vector3i(0, 0, 0);1232vec3_v = Vector3(2.2f, 3.5f, 5.3f);1233vec3i_v = vec3_v;1234CHECK(vec3i_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));1235vec3_v = Vector3(-5.4f, -7.9f, -2.1f);1236vec3i_v = vec3_v;1237CHECK(vec3i_v.get_type() == Variant::VECTOR3);12381239Variant vec4_v = Vector4(0, 0, 0, 0);1240vec3_v = Vector3(2.2f, 3.5f, 5.3f);1241vec4_v = vec3_v;1242CHECK(vec4_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));1243vec3_v = Vector3(-5.4f, -7.9f, -2.1f);1244vec4_v = vec3_v;1245CHECK(vec4_v.get_type() == Variant::VECTOR3);12461247Variant vec4i_v = Vector4i(0, 0, 0, 0);1248vec3_v = Vector3(2.2f, 3.5f, 5.3f);1249vec4i_v = vec3_v;1250CHECK(vec4i_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));1251vec3_v = Vector3(-5.4f, -7.9f, -2.1f);1252vec4i_v = vec3_v;1253CHECK(vec4i_v.get_type() == Variant::VECTOR3);12541255Variant rect2_v = Rect2();1256vec3_v = Vector3(2.2f, 3.5f, 5.3f);1257rect2_v = vec3_v;1258CHECK(rect2_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));1259vec3_v = Vector3(-5.4f, -7.9f, -2.1f);1260rect2_v = vec3_v;1261CHECK(rect2_v.get_type() == Variant::VECTOR3);12621263Variant rect2i_v = Rect2i();1264vec3_v = Vector3(2.2f, 3.5f, 5.3f);1265rect2i_v = vec3_v;1266CHECK(rect2i_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));1267vec3_v = Vector3(-5.4f, -7.9f, -2.1f);1268rect2i_v = vec3_v;1269CHECK(rect2i_v.get_type() == Variant::VECTOR3);12701271Variant transform2d_v = Transform2D();1272vec3_v = Vector3(2.2f, 3.5f, 5.3f);1273transform2d_v = vec3_v;1274CHECK(transform2d_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));1275vec3_v = Vector3(-5.4f, -7.9f, -2.1f);1276transform2d_v = vec3_v;1277CHECK(transform2d_v.get_type() == Variant::VECTOR3);12781279Variant transform3d_v = Transform3D();1280vec3_v = Vector3(2.2f, 3.5f, 5.3f);1281transform3d_v = vec3_v;1282CHECK(transform3d_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));1283vec3_v = Vector3(-5.4f, -7.9f, -2.1f);1284transform3d_v = vec3_v;1285CHECK(transform3d_v.get_type() == Variant::VECTOR3);12861287Variant col_v = Color(0.5f, 0.2f, 0.75f);1288vec3_v = Vector3(2.2f, 3.5f, 5.3f);1289col_v = vec3_v;1290CHECK(col_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));1291vec3_v = Vector3(-5.4f, -7.9f, -2.1f);1292col_v = vec3_v;1293CHECK(col_v.get_type() == Variant::VECTOR3);12941295Variant call_v = Callable();1296vec3_v = Vector3(2.2f, 3.5f, 5.3f);1297call_v = vec3_v;1298CHECK(call_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));1299vec3_v = Vector3(-5.4f, -7.9f, -2.1f);1300call_v = vec3_v;1301CHECK(call_v.get_type() == Variant::VECTOR3);13021303Variant plane_v = Plane();1304vec3_v = Vector3(2.2f, 3.5f, 5.3f);1305plane_v = vec3_v;1306CHECK(plane_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));1307vec3_v = Vector3(-5.4f, -7.9f, -2.1f);1308plane_v = vec3_v;1309CHECK(plane_v.get_type() == Variant::VECTOR3);13101311Variant basis_v = Basis();1312vec3_v = Vector3(2.2f, 3.5f, 5.3f);1313basis_v = vec3_v;1314CHECK(basis_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));1315vec3_v = Vector3(-5.4f, -7.9f, -2.1f);1316basis_v = vec3_v;1317CHECK(basis_v.get_type() == Variant::VECTOR3);13181319Variant aabb_v = AABB();1320vec3_v = Vector3(2.2f, 3.5f, 5.3f);1321aabb_v = vec3_v;1322CHECK(aabb_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));1323vec3_v = Vector3(-5.4f, -7.9f, -2.1f);1324aabb_v = vec3_v;1325CHECK(aabb_v.get_type() == Variant::VECTOR3);13261327Variant quaternion_v = Quaternion();1328vec3_v = Vector3(2.2f, 3.5f, 5.3f);1329quaternion_v = vec3_v;1330CHECK(quaternion_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));1331vec3_v = Vector3(-5.4f, -7.9f, -2.1f);1332quaternion_v = vec3_v;1333CHECK(quaternion_v.get_type() == Variant::VECTOR3);13341335Variant projection_v = Projection();1336vec3_v = Vector3(2.2f, 3.5f, 5.3f);1337quaternion_v = vec3_v;1338CHECK(quaternion_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));1339vec3_v = Vector3(-5.4f, -7.9f, -2.1f);1340quaternion_v = vec3_v;1341CHECK(quaternion_v.get_type() == Variant::VECTOR3);13421343Variant rid_v = RID();1344vec3_v = Vector3(2.2f, 3.5f, 5.3f);1345rid_v = vec3_v;1346CHECK(rid_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));1347vec3_v = Vector3(-5.4f, -7.9f, -2.1f);1348rid_v = vec3_v;1349CHECK(rid_v.get_type() == Variant::VECTOR3);13501351Object obj_one = Object();1352Variant object_v = &obj_one;1353vec3_v = Vector3(2.2f, 3.5f, 5.3f);1354object_v = vec3_v;1355CHECK(object_v == Variant(Vector3(2.2f, 3.5f, 5.3f)));1356vec3_v = Vector3(-5.4f, -7.9f, -2.1f);1357object_v = vec3_v;1358CHECK(object_v.get_type() == Variant::VECTOR3);1359}13601361TEST_CASE("[Variant] Assignment To Vec3i from Bool,Int,Float,String,Vec2,Vec2i,Vec3 and Color") {1362Variant bool_v = false;1363Variant vec3i_v = Vector3i(2, 3, 5);1364bool_v = vec3i_v; // Now bool_v is Vector3i1365CHECK(bool_v == Variant(Vector3i(2, 3, 5)));1366vec3i_v = Vector3i(-5, -7, -2);1367bool_v = vec3i_v;1368CHECK(bool_v.get_type() == Variant::VECTOR3I);13691370Variant int_v = 0;1371vec3i_v = Vector3i(2, 3, 5);1372int_v = vec3i_v;1373CHECK(int_v == Variant(Vector3i(2, 3, 5)));1374vec3i_v = Vector3i(-5, -7, -2);1375int_v = vec3i_v;1376CHECK(int_v.get_type() == Variant::VECTOR3I);13771378Variant float_v = 0.0f;1379vec3i_v = Vector3i(2, 3, 5);1380float_v = vec3i_v;1381CHECK(float_v == Variant(Vector3i(2, 3, 5)));1382vec3i_v = Vector3i(-5, -7, -2);1383float_v = vec3i_v;1384CHECK(float_v.get_type() == Variant::VECTOR3I);13851386Variant string_v = "";1387vec3i_v = Vector3i(2, 3, 5);1388string_v = vec3i_v;1389CHECK(string_v == Variant(Vector3i(2, 3, 5)));1390vec3i_v = Vector3i(-5, -7, -2);1391string_v = vec3i_v;1392CHECK(string_v.get_type() == Variant::VECTOR3I);13931394Variant vec2_v = Vector2(0, 0);1395vec3i_v = Vector3i(2, 3, 5);1396vec2_v = vec3i_v;1397CHECK(vec2_v == Variant(Vector3i(2, 3, 5)));1398vec3i_v = Vector3i(-5, -7, -2);1399vec2_v = vec3i_v;1400CHECK(vec2_v.get_type() == Variant::VECTOR3I);14011402Variant vec2i_v = Vector2i(0, 0);1403vec3i_v = Vector3i(2, 3, 5);1404vec2i_v = vec3i_v;1405CHECK(vec2i_v == Variant(Vector3i(2, 3, 5)));1406vec3i_v = Vector3i(-5, -7, -2);1407vec2i_v = vec3i_v;1408CHECK(vec2i_v.get_type() == Variant::VECTOR3I);14091410Variant vec3_v = Vector3(0, 0, 0);1411vec3i_v = Vector3i(2, 3, 5);1412vec3_v = vec3i_v;1413CHECK(vec3_v == Variant(Vector3i(2, 3, 5)));1414vec3i_v = Vector3i(-5, -7, -2);1415vec3_v = vec3i_v;1416CHECK(vec3_v.get_type() == Variant::VECTOR3I);14171418Variant vec4_v = Vector4(0, 0, 0, 0);1419vec3i_v = Vector3i(2, 3, 5);1420vec4_v = vec3i_v;1421CHECK(vec4_v == Variant(Vector3i(2, 3, 5)));1422vec3i_v = Vector3i(-5, -7, -2);1423vec4_v = vec3i_v;1424CHECK(vec4_v.get_type() == Variant::VECTOR3I);14251426Variant vec4i_v = Vector4i(0, 0, 0, 0);1427vec3i_v = Vector3i(2, 3, 5);1428vec4i_v = vec3i_v;1429CHECK(vec4i_v == Variant(Vector3i(2, 3, 5)));1430vec3i_v = Vector3i(-5, -7, -2);1431vec4i_v = vec3i_v;1432CHECK(vec4i_v.get_type() == Variant::VECTOR3I);14331434Variant rect2_v = Rect2();1435vec3i_v = Vector3i(2, 3, 5);1436rect2_v = vec3i_v;1437CHECK(rect2_v == Variant(Vector3i(2, 3, 5)));1438vec3i_v = Vector3i(-5, -7, -2);1439rect2_v = vec3i_v;1440CHECK(rect2_v.get_type() == Variant::VECTOR3I);14411442Variant rect2i_v = Rect2i();1443vec3i_v = Vector3i(2, 3, 5);1444rect2i_v = vec3i_v;1445CHECK(rect2i_v == Variant(Vector3i(2, 3, 5)));1446vec3i_v = Vector3i(-5, -7, -2);1447rect2i_v = vec3i_v;1448CHECK(rect2i_v.get_type() == Variant::VECTOR3I);14491450Variant transform2d_v = Transform2D();1451vec3i_v = Vector3i(2, 3, 5);1452transform2d_v = vec3i_v;1453CHECK(transform2d_v == Variant(Vector3i(2, 3, 5)));1454vec3i_v = Vector3i(-5, -7, -2);1455transform2d_v = vec3i_v;1456CHECK(transform2d_v.get_type() == Variant::VECTOR3I);14571458Variant transform3d_v = Transform3D();1459vec3i_v = Vector3i(2, 3, 5);1460transform3d_v = vec3i_v;1461CHECK(transform3d_v == Variant(Vector3i(2, 3, 5)));1462vec3i_v = Vector3i(-5, -7, -2);1463transform3d_v = vec3i_v;1464CHECK(transform3d_v.get_type() == Variant::VECTOR3I);14651466Variant col_v = Color(0.5f, 0.2f, 0.75f);1467vec3i_v = Vector3i(2, 3, 5);1468col_v = vec3i_v;1469CHECK(col_v == Variant(Vector3i(2, 3, 5)));1470vec3i_v = Vector3i(-5, -7, -2);1471col_v = vec3i_v;1472CHECK(col_v.get_type() == Variant::VECTOR3I);14731474Variant call_v = Callable();1475vec3i_v = Vector3i(2, 3, 5);1476call_v = vec3i_v;1477CHECK(call_v == Variant(Vector3i(2, 3, 5)));1478vec3i_v = Vector3i(-5, -7, -2);1479call_v = vec3i_v;1480CHECK(call_v.get_type() == Variant::VECTOR3I);14811482Variant plane_v = Plane();1483vec3i_v = Vector3i(2, 3, 5);1484plane_v = vec3i_v;1485CHECK(plane_v == Variant(Vector3i(2, 3, 5)));1486vec3i_v = Vector3i(-5, -7, -2);1487plane_v = vec3i_v;1488CHECK(plane_v.get_type() == Variant::VECTOR3I);14891490Variant basis_v = Basis();1491vec3i_v = Vector3i(2, 3, 5);1492basis_v = vec3i_v;1493CHECK(basis_v == Variant(Vector3i(2, 3, 5)));1494vec3i_v = Vector3i(-5, -7, -2);1495basis_v = vec3i_v;1496CHECK(basis_v.get_type() == Variant::VECTOR3I);14971498Variant aabb_v = AABB();1499vec3i_v = Vector3i(2, 3, 5);1500aabb_v = vec3i_v;1501CHECK(aabb_v == Variant(Vector3i(2, 3, 5)));1502vec3i_v = Vector3i(-5, -7, -2);1503aabb_v = vec3i_v;1504CHECK(aabb_v.get_type() == Variant::VECTOR3I);15051506Variant quaternion_v = Quaternion();1507vec3i_v = Vector3i(2, 3, 5);1508quaternion_v = vec3i_v;1509CHECK(quaternion_v == Variant(Vector3i(2, 3, 5)));1510vec3i_v = Vector3i(-5, -7, -2);1511quaternion_v = vec3i_v;1512CHECK(quaternion_v.get_type() == Variant::VECTOR3I);15131514Variant projection_v = Projection();1515vec3i_v = Vector3i(2, 3, 5);1516projection_v = vec3i_v;1517CHECK(projection_v == Variant(Vector3i(2, 3, 5)));1518vec3i_v = Vector3i(-5, -7, -2);1519projection_v = vec3i_v;1520CHECK(projection_v.get_type() == Variant::VECTOR3I);15211522Variant rid_v = RID();1523vec3i_v = Vector3i(2, 3, 5);1524rid_v = vec3i_v;1525CHECK(rid_v == Variant(Vector3i(2, 3, 5)));1526vec3i_v = Vector3i(-5, -7, -2);1527rid_v = vec3i_v;1528CHECK(rid_v.get_type() == Variant::VECTOR3I);15291530Object obj_one = Object();1531Variant object_v = &obj_one;1532vec3i_v = Vector3i(2, 3, 5);1533object_v = vec3i_v;1534CHECK(object_v == Variant(Vector3i(2, 3, 5)));1535vec3i_v = Vector3i(-5, -7, -2);1536object_v = vec3i_v;1537CHECK(object_v.get_type() == Variant::VECTOR3I);1538}15391540TEST_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") {1541Variant bool_v = false;1542Variant col_v = Color(0.25f, 0.4f, 0.78f);1543bool_v = col_v; // Now bool_v is Color1544CHECK(bool_v == Variant(Color(0.25f, 0.4f, 0.78f)));1545col_v = Color(0.33f, 0.75f, 0.21f);1546bool_v = col_v;1547CHECK(bool_v.get_type() == Variant::COLOR);15481549Variant int_v = 0;1550col_v = Color(0.25f, 0.4f, 0.78f);1551int_v = col_v;1552CHECK(int_v == Variant(Color(0.25f, 0.4f, 0.78f)));1553col_v = Color(0.33f, 0.75f, 0.21f);1554int_v = col_v;1555CHECK(int_v.get_type() == Variant::COLOR);15561557Variant float_v = 0.0f;1558col_v = Color(0.25f, 0.4f, 0.78f);1559float_v = col_v;1560CHECK(float_v == Variant(Color(0.25f, 0.4f, 0.78f)));1561col_v = Color(0.33f, 0.75f, 0.21f);1562float_v = col_v;1563CHECK(float_v.get_type() == Variant::COLOR);15641565Variant string_v = "";1566col_v = Color(0.25f, 0.4f, 0.78f);1567string_v = col_v;1568CHECK(string_v == Variant(Color(0.25f, 0.4f, 0.78f)));1569col_v = Color(0.33f, 0.75f, 0.21f);1570string_v = col_v;1571CHECK(string_v.get_type() == Variant::COLOR);15721573Variant vec2_v = Vector2(0, 0);1574col_v = Color(0.25f, 0.4f, 0.78f);1575vec2_v = col_v;1576CHECK(vec2_v == Variant(Color(0.25f, 0.4f, 0.78f)));1577col_v = Color(0.33f, 0.75f, 0.21f);1578vec2_v = col_v;1579CHECK(vec2_v.get_type() == Variant::COLOR);15801581Variant vec2i_v = Vector2i(0, 0);1582col_v = Color(0.25f, 0.4f, 0.78f);1583vec2i_v = col_v;1584CHECK(vec2i_v == Variant(Color(0.25f, 0.4f, 0.78f)));1585col_v = Color(0.33f, 0.75f, 0.21f);1586vec2i_v = col_v;1587CHECK(vec2i_v.get_type() == Variant::COLOR);15881589Variant vec3_v = Vector3(0, 0, 0);1590col_v = Color(0.25f, 0.4f, 0.78f);1591vec3_v = col_v;1592CHECK(vec3_v == Variant(Color(0.25f, 0.4f, 0.78f)));1593col_v = Color(0.33f, 0.75f, 0.21f);1594vec3_v = col_v;1595CHECK(vec3_v.get_type() == Variant::COLOR);15961597Variant vec3i_v = Vector3i(0, 0, 0);1598col_v = Color(0.25f, 0.4f, 0.78f);1599vec3i_v = col_v;1600CHECK(vec3i_v == Variant(Color(0.25f, 0.4f, 0.78f)));1601col_v = Color(0.33f, 0.75f, 0.21f);1602vec3i_v = col_v;1603CHECK(vec3i_v.get_type() == Variant::COLOR);16041605Variant vec4_v = Vector4(0, 0, 0, 0);1606col_v = Color(0.25f, 0.4f, 0.78f);1607vec4_v = col_v;1608CHECK(vec4_v == Variant(Color(0.25f, 0.4f, 0.78f)));1609col_v = Color(0.33f, 0.75f, 0.21f);1610vec4_v = col_v;1611CHECK(vec4_v.get_type() == Variant::COLOR);16121613Variant vec4i_v = Vector4i(0, 0, 0, 0);1614col_v = Color(0.25f, 0.4f, 0.78f);1615vec4i_v = col_v;1616CHECK(vec4i_v == Variant(Color(0.25f, 0.4f, 0.78f)));1617col_v = Color(0.33f, 0.75f, 0.21f);1618vec4i_v = col_v;1619CHECK(vec4i_v.get_type() == Variant::COLOR);16201621Variant rect2_v = Rect2();1622col_v = Color(0.25f, 0.4f, 0.78f);1623rect2_v = col_v;1624CHECK(rect2_v == Variant(Color(0.25f, 0.4f, 0.78f)));1625col_v = Color(0.33f, 0.75f, 0.21f);1626rect2_v = col_v;1627CHECK(rect2_v.get_type() == Variant::COLOR);16281629Variant rect2i_v = Rect2i();1630col_v = Color(0.25f, 0.4f, 0.78f);1631rect2i_v = col_v;1632CHECK(rect2i_v == Variant(Color(0.25f, 0.4f, 0.78f)));1633col_v = Color(0.33f, 0.75f, 0.21f);1634rect2i_v = col_v;1635CHECK(rect2i_v.get_type() == Variant::COLOR);16361637Variant transform2d_v = Transform2D();1638col_v = Color(0.25f, 0.4f, 0.78f);1639transform2d_v = col_v;1640CHECK(transform2d_v == Variant(Color(0.25f, 0.4f, 0.78f)));1641col_v = Color(0.33f, 0.75f, 0.21f);1642transform2d_v = col_v;1643CHECK(transform2d_v.get_type() == Variant::COLOR);16441645Variant transform3d_v = Transform3D();1646col_v = Color(0.25f, 0.4f, 0.78f);1647transform3d_v = col_v;1648CHECK(transform3d_v == Variant(Color(0.25f, 0.4f, 0.78f)));1649col_v = Color(0.33f, 0.75f, 0.21f);1650transform3d_v = col_v;1651CHECK(transform3d_v.get_type() == Variant::COLOR);16521653Variant call_v = Callable();1654col_v = Color(0.25f, 0.4f, 0.78f);1655call_v = col_v;1656CHECK(call_v == Variant(Color(0.25f, 0.4f, 0.78f)));1657col_v = Color(0.33f, 0.75f, 0.21f);1658call_v = col_v;1659CHECK(call_v.get_type() == Variant::COLOR);16601661Variant plane_v = Plane();1662col_v = Color(0.25f, 0.4f, 0.78f);1663plane_v = col_v;1664CHECK(plane_v == Variant(Color(0.25f, 0.4f, 0.78f)));1665col_v = Color(0.33f, 0.75f, 0.21f);1666plane_v = col_v;1667CHECK(plane_v.get_type() == Variant::COLOR);16681669Variant basis_v = Basis();1670col_v = Color(0.25f, 0.4f, 0.78f);1671basis_v = col_v;1672CHECK(basis_v == Variant(Color(0.25f, 0.4f, 0.78f)));1673col_v = Color(0.33f, 0.75f, 0.21f);1674basis_v = col_v;1675CHECK(basis_v.get_type() == Variant::COLOR);16761677Variant aabb_v = AABB();1678col_v = Color(0.25f, 0.4f, 0.78f);1679aabb_v = col_v;1680CHECK(aabb_v == Variant(Color(0.25f, 0.4f, 0.78f)));1681col_v = Color(0.33f, 0.75f, 0.21f);1682aabb_v = col_v;1683CHECK(aabb_v.get_type() == Variant::COLOR);16841685Variant quaternion_v = Quaternion();1686col_v = Color(0.25f, 0.4f, 0.78f);1687quaternion_v = col_v;1688CHECK(quaternion_v == Variant(Color(0.25f, 0.4f, 0.78f)));1689col_v = Color(0.33f, 0.75f, 0.21f);1690quaternion_v = col_v;1691CHECK(quaternion_v.get_type() == Variant::COLOR);16921693Variant projection_v = Projection();1694col_v = Color(0.25f, 0.4f, 0.78f);1695projection_v = col_v;1696CHECK(projection_v == Variant(Color(0.25f, 0.4f, 0.78f)));1697col_v = Color(0.33f, 0.75f, 0.21f);1698projection_v = col_v;1699CHECK(projection_v.get_type() == Variant::COLOR);17001701Variant rid_v = RID();1702col_v = Color(0.25f, 0.4f, 0.78f);1703rid_v = col_v;1704CHECK(rid_v == Variant(Color(0.25f, 0.4f, 0.78f)));1705col_v = Color(0.33f, 0.75f, 0.21f);1706rid_v = col_v;1707CHECK(rid_v.get_type() == Variant::COLOR);17081709Object obj_one = Object();1710Variant object_v = &obj_one;1711col_v = Color(0.25f, 0.4f, 0.78f);1712object_v = col_v;1713CHECK(object_v == Variant(Color(0.25f, 0.4f, 0.78f)));1714col_v = Color(0.33f, 0.75f, 0.21f);1715object_v = col_v;1716CHECK(object_v.get_type() == Variant::COLOR);1717}17181719TEST_CASE("[Variant] array initializer list") {1720Variant arr_v = { 0, 1, "test", true, { 0.0, 1.0 } };1721CHECK(arr_v.get_type() == Variant::ARRAY);1722Array arr = (Array)arr_v;1723CHECK(arr.size() == 5);1724CHECK(arr[0] == Variant(0));1725CHECK(arr[1] == Variant(1));1726CHECK(arr[2] == Variant("test"));1727CHECK(arr[3] == Variant(true));1728CHECK(arr[4] == Variant({ 0.0, 1.0 }));17291730PackedInt32Array packed_arr = { 2, 1, 0 };1731CHECK(packed_arr.size() == 3);1732CHECK(packed_arr[0] == 2);1733CHECK(packed_arr[1] == 1);1734CHECK(packed_arr[2] == 0);1735}17361737TEST_CASE("[Variant] Writer and parser Vector2") {1738Variant vec2_parsed;1739String vec2_str;1740String errs;1741int line;1742// Variant::VECTOR2 and Vector2 can be either 32-bit or 64-bit depending on the precision level of real_t.1743{1744Vector2 vec2 = Vector2(1.2, 3.4);1745VariantWriter::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.1747CHECK_MESSAGE(vec2_str == "Vector2(1.2, 3.4)", "Should write with enough digits to ensure parsing back is exact.");1748VariantParser::StreamString stream;1749stream.s = vec2_str;1750VariantParser::parse(&stream, vec2_parsed, errs, line);1751CHECK_MESSAGE(Vector2(vec2_parsed) == vec2, "Should parse back to the same Vector2.");1752}1753// Check with big numbers and small numbers.1754{1755Vector2 vec2 = Vector2(1.234567898765432123456789e30, 1.234567898765432123456789e-10);1756VariantWriter::write_to_string(vec2, vec2_str);1757#ifdef REAL_T_IS_DOUBLE1758CHECK_MESSAGE(vec2_str == "Vector2(1.2345678987654322e+30, 1.2345678987654322e-10)", "Should write with enough digits to ensure parsing back is exact.");1759#else1760CHECK_MESSAGE(vec2_str == "Vector2(1.2345679e+30, 1.2345679e-10)", "Should write with enough digits to ensure parsing back is exact.");1761#endif1762VariantParser::StreamString stream;1763stream.s = vec2_str;1764VariantParser::parse(&stream, vec2_parsed, errs, line);1765CHECK_MESSAGE(Vector2(vec2_parsed) == vec2, "Should parse back to the same Vector2.");1766}1767}17681769TEST_CASE("[Variant] Writer and parser array") {1770Array a = { 1, String("hello"), Array({ Variant() }) };1771String a_str;1772VariantWriter::write_to_string(a, a_str);17731774CHECK_EQ(a_str, "[1, \"hello\", [null]]");17751776VariantParser::StreamString ss;1777String errs;1778int line;1779Variant a_parsed;17801781ss.s = a_str;1782VariantParser::parse(&ss, a_parsed, errs, line);17831784CHECK_MESSAGE(a_parsed == Variant(a), "Should parse back.");1785}17861787TEST_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 up17901791// Self recursive1792Array a;1793a.push_back(a);17941795// Writer should it recursion limit while visiting the array1796ERR_PRINT_OFF;1797String a_str;1798VariantWriter::write_to_string(a, a_str);1799ERR_PRINT_ON;18001801// Nested recursive1802Array a1;1803Array a2;1804a1.push_back(a2);1805a2.push_back(a1);18061807// Writer should it recursion limit while visiting the array1808ERR_PRINT_OFF;1809String a1_str;1810VariantWriter::write_to_string(a1, a1_str);1811ERR_PRINT_ON;18121813// Break the recursivity otherwise Dictionary tearndown will leak memory1814a.clear();1815a1.clear();1816a2.clear();1817}18181819TEST_CASE("[Variant] Writer and parser dictionary") {1820// d = {{1: 2}: 3, 4: "hello", 5: {null: []}}1821Dictionary d = { { Dictionary({ { 1, 2 } }), 3 }, { 4, String("hello") }, { 5, Dictionary({ { Variant(), Array() } }) } };1822String d_str;1823VariantWriter::write_to_string(d, d_str);18241825CHECK_EQ(d_str, "{\n4: \"hello\",\n5: {\nnull: []\n},\n{\n1: 2\n}: 3\n}");18261827VariantParser::StreamString ss;1828String errs;1829int line;1830Variant d_parsed;18311832ss.s = d_str;1833VariantParser::parse(&ss, d_parsed, errs, line);18341835CHECK_MESSAGE(d_parsed == Variant(d), "Should parse back.");1836}18371838TEST_CASE("[Variant] Writer key sorting") {1839Dictionary d = { { StringName("C"), 3 }, { "A", 1 }, { StringName("B"), 2 }, { "D", 4 } };1840String d_str;1841VariantWriter::write_to_string(d, d_str);18421843CHECK_EQ(d_str, "{\n\"A\": 1,\n&\"B\": 2,\n&\"C\": 3,\n\"D\": 4\n}");1844}18451846TEST_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 up18491850// Self recursive1851Dictionary d;1852d[1] = d;18531854// Writer should it recursion limit while visiting the dictionary1855ERR_PRINT_OFF;1856String d_str;1857VariantWriter::write_to_string(d, d_str);1858ERR_PRINT_ON;18591860// Nested recursive1861Dictionary d1;1862Dictionary d2;1863d1[2] = d2;1864d2[1] = d1;18651866// Writer should it recursion limit while visiting the dictionary1867ERR_PRINT_OFF;1868String d1_str;1869VariantWriter::write_to_string(d1, d1_str);1870ERR_PRINT_ON;18711872// Break the recursivity otherwise Dictionary tearndown will leak memory1873d.clear();1874d1.clear();1875d2.clear();1876}18771878#if 0 // TODO: recursion in dict key is currently buggy1879TEST_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 up18821883// Self recursive1884Dictionary d;1885d[d] = 1;18861887// Writer should it recursion limit while visiting the dictionary1888ERR_PRINT_OFF;1889String d_str;1890VariantWriter::write_to_string(d, d_str);1891ERR_PRINT_ON;18921893// Nested recursive1894Dictionary d1;1895Dictionary d2;1896d1[d2] = 2;1897d2[d1] = 1;18981899// Writer should it recursion limit while visiting the dictionary1900ERR_PRINT_OFF;1901String d1_str;1902VariantWriter::write_to_string(d1, d1_str);1903ERR_PRINT_ON;19041905// Break the recursivity otherwise Dictionary tearndown will leak memory1906d.clear();1907d1.clear();1908d2.clear();1909}1910#endif19111912TEST_CASE("[Variant] Basic comparison") {1913CHECK_EQ(Variant(1), Variant(1));1914CHECK_FALSE(Variant(1) != Variant(1));1915CHECK_NE(Variant(1), Variant(2));1916CHECK_EQ(Variant(String("foo")), Variant(String("foo")));1917CHECK_NE(Variant(String("foo")), Variant(String("bar")));1918// Check "empty" version of different types are not equivalents1919CHECK_NE(Variant(0), Variant());1920CHECK_NE(Variant(String()), Variant());1921CHECK_NE(Variant(Array()), Variant());1922CHECK_NE(Variant(Dictionary()), Variant());1923}19241925TEST_CASE("[Variant] Identity comparison") {1926// Value types are compared by value1927Variant aabb = AABB();1928CHECK(aabb.identity_compare(aabb));1929CHECK(aabb.identity_compare(AABB()));1930CHECK_FALSE(aabb.identity_compare(AABB(Vector3(1, 2, 3), Vector3(1, 2, 3))));19311932Variant basis = Basis();1933CHECK(basis.identity_compare(basis));1934CHECK(basis.identity_compare(Basis()));1935CHECK_FALSE(basis.identity_compare(Basis(Quaternion(Vector3(1, 2, 3).normalized(), 45))));19361937Variant bool_var = true;1938CHECK(bool_var.identity_compare(bool_var));1939CHECK(bool_var.identity_compare(true));1940CHECK_FALSE(bool_var.identity_compare(false));19411942Variant callable = Callable();1943CHECK(callable.identity_compare(callable));1944CHECK(callable.identity_compare(Callable()));1945CHECK_FALSE(callable.identity_compare(Callable(ObjectID(), StringName("lambda"))));19461947Variant color = Color();1948CHECK(color.identity_compare(color));1949CHECK(color.identity_compare(Color()));1950CHECK_FALSE(color.identity_compare(Color(255, 0, 255)));19511952Variant float_var = 1.0;1953CHECK(float_var.identity_compare(float_var));1954CHECK(float_var.identity_compare(1.0));1955CHECK_FALSE(float_var.identity_compare(2.0));19561957Variant int_var = 1;1958CHECK(int_var.identity_compare(int_var));1959CHECK(int_var.identity_compare(1));1960CHECK_FALSE(int_var.identity_compare(2));19611962Variant nil = Variant();1963CHECK(nil.identity_compare(nil));1964CHECK(nil.identity_compare(Variant()));1965CHECK_FALSE(nil.identity_compare(true));19661967Variant node_path = NodePath("godot");1968CHECK(node_path.identity_compare(node_path));1969CHECK(node_path.identity_compare(NodePath("godot")));1970CHECK_FALSE(node_path.identity_compare(NodePath("waiting")));19711972Variant plane = Plane();1973CHECK(plane.identity_compare(plane));1974CHECK(plane.identity_compare(Plane()));1975CHECK_FALSE(plane.identity_compare(Plane(Vector3(1, 2, 3), 42)));19761977Variant projection = Projection();1978CHECK(projection.identity_compare(projection));1979CHECK(projection.identity_compare(Projection()));1980CHECK_FALSE(projection.identity_compare(Projection(Transform3D(Basis(Vector3(1, 2, 3).normalized(), 45), Vector3(1, 2, 3)))));19811982Variant quaternion = Quaternion();1983CHECK(quaternion.identity_compare(quaternion));1984CHECK(quaternion.identity_compare(Quaternion()));1985CHECK_FALSE(quaternion.identity_compare(Quaternion(Vector3(1, 2, 3).normalized(), 45)));19861987Variant rect2 = Rect2();1988CHECK(rect2.identity_compare(rect2));1989CHECK(rect2.identity_compare(Rect2()));1990CHECK_FALSE(rect2.identity_compare(Rect2(Point2(Vector2(1, 2)), Size2(Vector2(1, 2)))));19911992Variant rect2i = Rect2i();1993CHECK(rect2i.identity_compare(rect2i));1994CHECK(rect2i.identity_compare(Rect2i()));1995CHECK_FALSE(rect2i.identity_compare(Rect2i(Point2i(Vector2i(1, 2)), Size2i(Vector2i(1, 2)))));19961997Variant rid = RID();1998CHECK(rid.identity_compare(rid));1999CHECK(rid.identity_compare(RID()));2000CHECK_FALSE(rid.identity_compare(RID::from_uint64(123)));20012002Variant signal = Signal();2003CHECK(signal.identity_compare(signal));2004CHECK(signal.identity_compare(Signal()));2005CHECK_FALSE(signal.identity_compare(Signal(ObjectID(), StringName("lambda"))));20062007Variant str = "godot";2008CHECK(str.identity_compare(str));2009CHECK(str.identity_compare("godot"));2010CHECK_FALSE(str.identity_compare("waiting"));20112012Variant str_name = StringName("godot");2013CHECK(str_name.identity_compare(str_name));2014CHECK(str_name.identity_compare(StringName("godot")));2015CHECK_FALSE(str_name.identity_compare(StringName("waiting")));20162017Variant transform2d = Transform2D();2018CHECK(transform2d.identity_compare(transform2d));2019CHECK(transform2d.identity_compare(Transform2D()));2020CHECK_FALSE(transform2d.identity_compare(Transform2D(45, Vector2(1, 2))));20212022Variant transform3d = Transform3D();2023CHECK(transform3d.identity_compare(transform3d));2024CHECK(transform3d.identity_compare(Transform3D()));2025CHECK_FALSE(transform3d.identity_compare(Transform3D(Basis(Quaternion(Vector3(1, 2, 3).normalized(), 45)), Vector3(1, 2, 3))));20262027Variant vect2 = Vector2();2028CHECK(vect2.identity_compare(vect2));2029CHECK(vect2.identity_compare(Vector2()));2030CHECK_FALSE(vect2.identity_compare(Vector2(1, 2)));20312032Variant vect2i = Vector2i();2033CHECK(vect2i.identity_compare(vect2i));2034CHECK(vect2i.identity_compare(Vector2i()));2035CHECK_FALSE(vect2i.identity_compare(Vector2i(1, 2)));20362037Variant vect3 = Vector3();2038CHECK(vect3.identity_compare(vect3));2039CHECK(vect3.identity_compare(Vector3()));2040CHECK_FALSE(vect3.identity_compare(Vector3(1, 2, 3)));20412042Variant vect3i = Vector3i();2043CHECK(vect3i.identity_compare(vect3i));2044CHECK(vect3i.identity_compare(Vector3i()));2045CHECK_FALSE(vect3i.identity_compare(Vector3i(1, 2, 3)));20462047Variant vect4 = Vector4();2048CHECK(vect4.identity_compare(vect4));2049CHECK(vect4.identity_compare(Vector4()));2050CHECK_FALSE(vect4.identity_compare(Vector4(1, 2, 3, 4)));20512052Variant vect4i = Vector4i();2053CHECK(vect4i.identity_compare(vect4i));2054CHECK(vect4i.identity_compare(Vector4i()));2055CHECK_FALSE(vect4i.identity_compare(Vector4i(1, 2, 3, 4)));20562057// Reference types are compared by reference2058Variant array = Array();2059CHECK(array.identity_compare(array));2060CHECK_FALSE(array.identity_compare(Array()));20612062Variant dictionary = Dictionary();2063CHECK(dictionary.identity_compare(dictionary));2064CHECK_FALSE(dictionary.identity_compare(Dictionary()));20652066Variant packed_byte_array = PackedByteArray();2067CHECK(packed_byte_array.identity_compare(packed_byte_array));2068CHECK_FALSE(packed_byte_array.identity_compare(PackedByteArray()));20692070Variant packed_color_array = PackedColorArray();2071CHECK(packed_color_array.identity_compare(packed_color_array));2072CHECK_FALSE(packed_color_array.identity_compare(PackedColorArray()));20732074Variant packed_vector4_array = PackedVector4Array();2075CHECK(packed_vector4_array.identity_compare(packed_vector4_array));2076CHECK_FALSE(packed_vector4_array.identity_compare(PackedVector4Array()));20772078Variant packed_float32_array = PackedFloat32Array();2079CHECK(packed_float32_array.identity_compare(packed_float32_array));2080CHECK_FALSE(packed_float32_array.identity_compare(PackedFloat32Array()));20812082Variant packed_float64_array = PackedFloat64Array();2083CHECK(packed_float64_array.identity_compare(packed_float64_array));2084CHECK_FALSE(packed_float64_array.identity_compare(PackedFloat64Array()));20852086Variant packed_int32_array = PackedInt32Array();2087CHECK(packed_int32_array.identity_compare(packed_int32_array));2088CHECK_FALSE(packed_int32_array.identity_compare(PackedInt32Array()));20892090Variant packed_int64_array = PackedInt64Array();2091CHECK(packed_int64_array.identity_compare(packed_int64_array));2092CHECK_FALSE(packed_int64_array.identity_compare(PackedInt64Array()));20932094Variant packed_string_array = PackedStringArray();2095CHECK(packed_string_array.identity_compare(packed_string_array));2096CHECK_FALSE(packed_string_array.identity_compare(PackedStringArray()));20972098Variant packed_vector2_array = PackedVector2Array();2099CHECK(packed_vector2_array.identity_compare(packed_vector2_array));2100CHECK_FALSE(packed_vector2_array.identity_compare(PackedVector2Array()));21012102Variant packed_vector3_array = PackedVector3Array();2103CHECK(packed_vector3_array.identity_compare(packed_vector3_array));2104CHECK_FALSE(packed_vector3_array.identity_compare(PackedVector3Array()));21052106Object obj_one = Object();2107Variant obj_one_var = &obj_one;2108Object obj_two = Object();2109Variant obj_two_var = &obj_two;2110CHECK(obj_one_var.identity_compare(obj_one_var));2111CHECK_FALSE(obj_one_var.identity_compare(obj_two_var));21122113Variant obj_null_one_var = Variant((Object *)nullptr);2114Variant obj_null_two_var = Variant((Object *)nullptr);2115CHECK(obj_null_one_var.identity_compare(obj_null_one_var));2116CHECK(obj_null_one_var.identity_compare(obj_null_two_var));21172118Object *freed_one = new Object();2119Variant freed_one_var = freed_one;2120delete freed_one;2121Object *freed_two = new Object();2122Variant freed_two_var = freed_two;2123delete freed_two;2124CHECK_FALSE(freed_one_var.identity_compare(freed_two_var));2125}21262127TEST_CASE("[Variant] Nested array comparison") {2128Array a1 = { 1, { 2, 3 } };2129Array a2 = { 1, { 2, 3 } };2130Array a_other = { 1, { 2, 4 } };2131Variant v_a1 = a1;2132Variant v_a1_ref2 = a1;2133Variant v_a2 = a2;2134Variant v_a_other = a_other;21352136// test both operator== and operator!=2137CHECK_EQ(v_a1, v_a1);2138CHECK_FALSE(v_a1 != v_a1);2139CHECK_EQ(v_a1, v_a1_ref2);2140CHECK_FALSE(v_a1 != v_a1_ref2);2141CHECK_EQ(v_a1, v_a2);2142CHECK_FALSE(v_a1 != v_a2);2143CHECK_NE(v_a1, v_a_other);2144CHECK_FALSE(v_a1 == v_a_other);2145}21462147TEST_CASE("[Variant] Nested dictionary comparison") {2148Dictionary d1 = { { Dictionary({ { 1, 2 } }), Dictionary({ { 3, 4 } }) } };2149Dictionary d2 = { { Dictionary({ { 1, 2 } }), Dictionary({ { 3, 4 } }) } };2150Dictionary d_other_key = { { Dictionary({ { 1, 0 } }), Dictionary({ { 3, 4 } }) } };2151Dictionary d_other_val = { { Dictionary({ { 1, 2 } }), Dictionary({ { 3, 0 } }) } };2152Variant v_d1 = d1;2153Variant v_d1_ref2 = d1;2154Variant v_d2 = d2;2155Variant v_d_other_key = d_other_key;2156Variant v_d_other_val = d_other_val;21572158// test both operator== and operator!=2159CHECK_EQ(v_d1, v_d1);2160CHECK_FALSE(v_d1 != v_d1);2161CHECK_EQ(v_d1, v_d1_ref2);2162CHECK_FALSE(v_d1 != v_d1_ref2);2163CHECK_EQ(v_d1, v_d2);2164CHECK_FALSE(v_d1 != v_d2);2165CHECK_NE(v_d1, v_d_other_key);2166CHECK_FALSE(v_d1 == v_d_other_key);2167CHECK_NE(v_d1, v_d_other_val);2168CHECK_FALSE(v_d1 == v_d_other_val);2169}21702171struct ArgumentData {2172Variant::Type type;2173String name;2174bool has_defval = false;2175Variant defval;2176int position;2177};21782179struct MethodData {2180StringName name;2181Variant::Type return_type;2182List<ArgumentData> arguments;2183bool is_virtual = false;2184bool is_vararg = false;2185};21862187TEST_CASE("[Variant] Utility functions") {2188List<MethodData> functions;21892190List<StringName> function_names;2191Variant::get_utility_function_list(&function_names);2192function_names.sort_custom<StringName::AlphCompare>();21932194for (const StringName &E : function_names) {2195MethodData md;2196md.name = E;21972198// Utility function's return type.2199if (Variant::has_utility_function_return_value(E)) {2200md.return_type = Variant::get_utility_function_return_type(E);2201}22022203// Utility function's arguments.2204if (Variant::is_utility_function_vararg(E)) {2205md.is_vararg = true;2206} else {2207for (int i = 0; i < Variant::get_utility_function_argument_count(E); i++) {2208ArgumentData arg;2209arg.type = Variant::get_utility_function_argument_type(E, i);2210arg.name = Variant::get_utility_function_argument_name(E, i);2211arg.position = i;22122213md.arguments.push_back(arg);2214}2215}22162217functions.push_back(md);2218}22192220SUBCASE("[Variant] Validate utility functions") {2221for (const MethodData &E : functions) {2222for (const ArgumentData &F : E.arguments) {2223const ArgumentData &arg = F;22242225TEST_COND((arg.name.is_empty() || arg.name.begins_with("_unnamed_arg")),2226vformat("Unnamed argument in position %d of function '%s'.", arg.position, E.name));2227}2228}2229}2230}22312232TEST_CASE("[Variant] Operator NOT") {2233// Verify that operator NOT works for all types and is consistent with booleanize().2234for (int i = 0; i < Variant::VARIANT_MAX; i++) {2235Variant value;2236Callable::CallError err;2237Variant::construct((Variant::Type)i, value, nullptr, 0, err);22382239REQUIRE_EQ(err.error, Callable::CallError::CALL_OK);22402241Variant result = Variant::evaluate(Variant::OP_NOT, value, Variant());22422243REQUIRE_EQ(result.get_type(), Variant::BOOL);2244CHECK_EQ(!value.booleanize(), result.operator bool());2245}2246}22472248} // namespace TestVariant224922502251