diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-04-10 17:49:14 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-04-10 17:49:14 +0200 |
commit | 7670b812333f64b8ef349797cf3e2fb26765502c (patch) | |
tree | bbfae7eca9992c0dcdf2ee237dd56f9d742d6c77 /tests/core/variant/test_array.h | |
parent | 1f0f81049fc470fe10ddb64086c94b9c595ec81f (diff) | |
parent | 64146cb7f35b57b0974b82845674d58f9f3480b6 (diff) | |
download | redot-engine-7670b812333f64b8ef349797cf3e2fb26765502c.tar.gz |
Merge pull request #86518 from AThousandShips/array_iter
[Core] Add iteration support to `Array`
Diffstat (limited to 'tests/core/variant/test_array.h')
-rw-r--r-- | tests/core/variant/test_array.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/core/variant/test_array.h b/tests/core/variant/test_array.h index ea61ae2a02..287345e831 100644 --- a/tests/core/variant/test_array.h +++ b/tests/core/variant/test_array.h @@ -545,6 +545,54 @@ TEST_CASE("[Array] Recursive self comparison") { a2.clear(); } +TEST_CASE("[Array] Iteration") { + Array a1 = build_array(1, 2, 3); + Array a2 = build_array(1, 2, 3); + + int idx = 0; + for (Variant &E : a1) { + CHECK_EQ(int(a2[idx]), int(E)); + idx++; + } + + idx = 0; + + for (const Variant &E : (const Array &)a1) { + CHECK_EQ(int(a2[idx]), int(E)); + idx++; + } + + a1.clear(); +} + +TEST_CASE("[Array] Iteration and modification") { + Array a1 = build_array(1, 2, 3); + Array a2 = build_array(2, 3, 4); + Array a3 = build_array(1, 2, 3); + Array a4 = build_array(1, 2, 3); + a3.make_read_only(); + + int idx = 0; + for (Variant &E : a1) { + E = a2[idx]; + idx++; + } + + CHECK_EQ(a1, a2); + + // Ensure read-only is respected. + idx = 0; + for (Variant &E : a3) { + E = a2[idx]; + } + + CHECK_EQ(a3, a4); + + a1.clear(); + a2.clear(); + a4.clear(); +} + } // namespace TestArray #endif // TEST_ARRAY_H |