aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDamian Tarnawski <gthetarnav@gmail.com>2025-08-23 16:55:12 +0200
committerDamian Tarnawski <gthetarnav@gmail.com>2025-08-23 16:55:12 +0200
commit2a6dfd2545b78b91ddb690f30068742212862f81 (patch)
treeb0ea5f36277cefea21584794797dc99bdc642cdd /tests
parent9d651348b5c6772db26af79dd2ff077c3af670f2 (diff)
Avoid overlap issues when correcting memory after resize in _reserve_soa
Diffstat (limited to 'tests')
-rw-r--r--tests/core/runtime/test_core_runtime.odin58
1 files changed, 44 insertions, 14 deletions
diff --git a/tests/core/runtime/test_core_runtime.odin b/tests/core/runtime/test_core_runtime.odin
index d74edd3f8..1bc100348 100644
--- a/tests/core/runtime/test_core_runtime.odin
+++ b/tests/core/runtime/test_core_runtime.odin
@@ -181,28 +181,58 @@ test_map_get :: proc(t: ^testing.T) {
@(test)
test_soa_array_allocator_resize :: proc(t: ^testing.T) {
+
arena: runtime.Arena
context.allocator = runtime.arena_allocator(&arena)
defer runtime.arena_destroy(&arena)
- array, err := make(#soa[dynamic][2]int, 2, 3)
- array[0] = [2]int{1, 2}
- array[1] = [2]int{3, 4}
+ {
+ // |1 3 _ 2 4 _|
+ // |1 3 _ _ 2 4 _ _|
- testing.expect_value(t, err, nil)
- testing.expect_value(t, len(array), 2)
- testing.expect_value(t, cap(array), 3)
+ array, err := make(#soa[dynamic][2]int, 2, 3)
+ array[0] = [2]int{1, 2}
+ array[1] = [2]int{3, 4}
- err = resize(&array, 4)
+ testing.expect_value(t, err, nil)
+ testing.expect_value(t, len(array), 2)
+ testing.expect_value(t, cap(array), 3)
- testing.expect_value(t, err, nil)
- testing.expect_value(t, len(array), 4)
- testing.expect_value(t, cap(array), 4)
+ err = resize(&array, 4)
+
+ testing.expect_value(t, err, nil)
+ testing.expect_value(t, len(array), 4)
+ testing.expect_value(t, cap(array), 4)
+
+ testing.expect_value(t, array[0], [2]int{1, 2})
+ testing.expect_value(t, array[1], [2]int{3, 4})
+ testing.expect_value(t, array[2], [2]int{0, 0})
+ testing.expect_value(t, array[3], [2]int{0, 0})
+ }
- testing.expect_value(t, array[0], [2]int{1, 2})
- testing.expect_value(t, array[1], [2]int{3, 4})
- testing.expect_value(t, array[2], [2]int{0, 0})
- testing.expect_value(t, array[3], [2]int{0, 0})
+ {
+ // |1 4 2 5 3 6|
+ // |1 4 _ _ 2 5 _ _ 3 6 _ _|
+
+ array, err := make(#soa[dynamic][3]int, 2, 2)
+ array[0] = [3]int{1, 2, 3}
+ array[1] = [3]int{4, 5, 6}
+
+ testing.expect_value(t, err, nil)
+ testing.expect_value(t, len(array), 2)
+ testing.expect_value(t, cap(array), 2)
+
+ err = resize(&array, 4)
+
+ testing.expect_value(t, err, nil)
+ testing.expect_value(t, len(array), 4)
+ testing.expect_value(t, cap(array), 4)
+
+ testing.expect_value(t, array[0], [3]int{1, 2, 3})
+ testing.expect_value(t, array[1], [3]int{4, 5, 6})
+ testing.expect_value(t, array[2], [3]int{0, 0, 0})
+ testing.expect_value(t, array[3], [3]int{0, 0, 0})
+ }
}
@(test)