summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorA Thousand Ships <96648715+AThousandShips@users.noreply.github.com>2024-03-05 20:38:22 +0100
committerA Thousand Ships <96648715+AThousandShips@users.noreply.github.com>2024-05-07 09:52:17 +0200
commit09460d33e60b2789d4861c63e18c019955d9e66c (patch)
treeb44570760657e9432bf9d0ee200eb0e2c9c1beb8 /tests
parent107fd30ae7bbf0a1bacc6f461231b3c31e94a7de (diff)
downloadredot-engine-09460d33e60b2789d4861c63e18c019955d9e66c.tar.gz
[Core] Fix sharing of typed arrays from constructor
Diffstat (limited to 'tests')
-rw-r--r--tests/core/variant/test_array.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/core/variant/test_array.h b/tests/core/variant/test_array.h
index c54854e4d7..787b8f39d9 100644
--- a/tests/core/variant/test_array.h
+++ b/tests/core/variant/test_array.h
@@ -597,6 +597,43 @@ TEST_CASE("[Array] Iteration and modification") {
a4.clear();
}
+TEST_CASE("[Array] Typed copying") {
+ TypedArray<int> a1;
+ a1.push_back(1);
+
+ TypedArray<double> a2;
+ a2.push_back(1.0);
+
+ Array a3 = a1;
+ TypedArray<int> a4 = a3;
+
+ Array a5 = a2;
+ TypedArray<int> a6 = a5;
+
+ a3[0] = 2;
+ a4[0] = 3;
+
+ // Same typed TypedArray should be shared.
+ CHECK_EQ(a1[0], Variant(3));
+ CHECK_EQ(a3[0], Variant(3));
+ CHECK_EQ(a4[0], Variant(3));
+
+ a5[0] = 2.0;
+ a6[0] = 3.0;
+
+ // Different typed TypedArray should not be shared.
+ CHECK_EQ(a2[0], Variant(2.0));
+ CHECK_EQ(a5[0], Variant(2.0));
+ CHECK_EQ(a6[0], Variant(3.0));
+
+ a1.clear();
+ a2.clear();
+ a3.clear();
+ a4.clear();
+ a5.clear();
+ a6.clear();
+}
+
} // namespace TestArray
#endif // TEST_ARRAY_H