aboutsummaryrefslogtreecommitdiff
path: root/tests/issues/test_issue_2694.odin
blob: 01860d6033ea3a6ead4cac01302698f909383600 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package test_issues

import "core:fmt"
import "core:encoding/json"
import "core:log"
import "core:mem"
import "core:testing"

// This is a minimal reproduction of the code in #2694.
// It exemplifies the original problem as briefly as possible.

SAMPLE_JSON :: `
{
	"foo": 0,
	"things": [
		{ "a": "ZZZZ"},
	]
}
`

@test
test_issue_2694 :: proc(t: ^testing.T) {
	into: struct {
		foo: int,
		things: []json.Object,
	}

	scratch := new(mem.Scratch_Allocator)
	defer free(scratch)
	if mem.scratch_allocator_init(scratch, 4 * mem.Megabyte) != .None {
		log.error("unable to initialize scratch allocator")
		return
	}
	defer mem.scratch_allocator_destroy(scratch)

	err := json.unmarshal_string(SAMPLE_JSON, &into, allocator = mem.scratch_allocator(scratch))
	testing.expect(t, err == nil)

	output := fmt.tprintf("%v", into)
	expected := `{foo = 0, things = [map[a="ZZZZ"]]}`
	testing.expectf(t, output == expected, "\n\texpected: %q\n\tgot:      %q", expected, output)
}