diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2025-08-26 11:26:15 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-26 11:26:15 +0100 |
| commit | 83a78d5d28a02de0d224e5f0f0ba5ba2a17a7467 (patch) | |
| tree | 2c44d6ee416a2a4fae1b5ea024a3988f226a48f0 /tests | |
| parent | 18a2980d26602028977da151a0af1a43097b7830 (diff) | |
| parent | 0a02f5f076a225e47737cbeab35c26751c87fd95 (diff) | |
Merge branch 'master' into soa-resize-zero-memory
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/core/runtime/test_core_runtime.odin | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/core/runtime/test_core_runtime.odin b/tests/core/runtime/test_core_runtime.odin index e6201d8f2..6c3b489d7 100644 --- a/tests/core/runtime/test_core_runtime.odin +++ b/tests/core/runtime/test_core_runtime.odin @@ -213,6 +213,84 @@ test_soa_array_resize :: proc(t: ^testing.T) { testing.expect_value(t, array[2], V{0, 0}) } +test_soa_make_len :: proc(t: ^testing.T) { + + array, err := make(#soa[dynamic][2]int, 2) + defer delete(array) + array[0] = [2]int{1, 2} + array[1] = [2]int{3, 4} + + testing.expect_value(t, err, nil) + testing.expect_value(t, len(array), 2) + testing.expect_value(t, cap(array), 2) + + testing.expect_value(t, array[0], [2]int{1, 2}) + testing.expect_value(t, array[1], [2]int{3, 4}) +} + +@(test) +test_soa_array_allocator_resize :: proc(t: ^testing.T) { + + arena: runtime.Arena + context.allocator = runtime.arena_allocator(&arena) + defer runtime.arena_destroy(&arena) + + // |1 3 _ 2 4 _| + // |1 3 _ _ 2 4 _ _| + + array, err := make(#soa[dynamic][2]int, 2, 3) + defer delete(array) + array[0] = [2]int{1, 2} + array[1] = [2]int{3, 4} + + testing.expect_value(t, err, nil) + testing.expect_value(t, len(array), 2) + testing.expect_value(t, cap(array), 3) + + 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}) +} + + +@(test) +test_soa_array_allocator_resize_overlapping :: proc(t: ^testing.T) { + + arena: runtime.Arena + context.allocator = runtime.arena_allocator(&arena) + defer runtime.arena_destroy(&arena) + + // |1 4 2 5 3 6| + // |1 4 _ _ 2 5 _ _ 3 6 _ _| + + array, err := make(#soa[dynamic][3]int, 2, 2) + defer delete(array) + 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) test_memory_equal :: proc(t: ^testing.T) { data: [256]u8 |