mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-13 01:21:38 -07:00
Test #4515
This commit is contained in:
@@ -83,6 +83,40 @@ out_of_memory_in_parse_json :: proc(t: ^testing.T) {
|
||||
testing.expectf(t, err == json.Error.Out_Of_Memory, "Expected `json.parse` to fail with %v, got %v", expected_error, err)
|
||||
}
|
||||
|
||||
@test
|
||||
out_of_memory_in_unmarshal :: proc(t: ^testing.T) {
|
||||
arena: virtual.Arena
|
||||
arena_buffer: [128]byte
|
||||
arena_init_error := virtual.arena_init_buffer(&arena, arena_buffer[:])
|
||||
testing.expectf(t, arena_init_error == nil, "Expected arena initialization to not return error, got: %v\n", arena_init_error)
|
||||
|
||||
context.allocator = virtual.arena_allocator(&arena)
|
||||
|
||||
json_data := `{
|
||||
"number": 42,
|
||||
"strs": [
|
||||
"Cat",
|
||||
"Dog",
|
||||
"Toucan"
|
||||
],
|
||||
"flag": true
|
||||
}`
|
||||
|
||||
Test_Structure :: struct {
|
||||
number: int,
|
||||
strs: []string,
|
||||
flag: bool,
|
||||
}
|
||||
test_result: Test_Structure
|
||||
|
||||
err := json.unmarshal(transmute([]u8)json_data, &test_result)
|
||||
testing.expectf(t, err == nil, "Expected `json.unmarshal` to succeed, got error %v", err)
|
||||
|
||||
err = json.unmarshal(transmute([]u8)json_data, &test_result)
|
||||
expected_error := json.Error.Out_Of_Memory
|
||||
testing.expectf(t, err == json.Error.Out_Of_Memory, "Expected `json.unmarshal` to fail with %v, got %v", expected_error, err)
|
||||
}
|
||||
|
||||
@test
|
||||
marshal_json :: proc(t: ^testing.T) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user