Jeroen van Rijn před 9 měsíci
rodič
revize
66c57e380a
1 změnil soubory, kde provedl 34 přidání a 0 odebrání
  1. 34 0
      tests/core/encoding/json/test_core_json.odin

+ 34 - 0
tests/core/encoding/json/test_core_json.odin

@@ -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) {