Add test for issue #2694

This commit is contained in:
Feoramund
2025-06-14 13:26:11 -04:00
parent 3261896790
commit d7e98ba82a
3 changed files with 44 additions and 0 deletions

View File

@@ -16,6 +16,7 @@ set COMMON=-define:ODIN_TEST_FANCY=false -file -vet -strict-style
..\..\..\odin test ..\test_issue_2615.odin %COMMON% || exit /b
..\..\..\odin test ..\test_issue_2637.odin %COMMON% || exit /b
..\..\..\odin test ..\test_issue_2666.odin %COMMON% || exit /b
..\..\..\odin test ..\test_issue_2694.odin %COMMON% || exit /b
..\..\..\odin test ..\test_issue_4210.odin %COMMON% || exit /b
..\..\..\odin test ..\test_issue_4364.odin %COMMON% || exit /b
..\..\..\odin test ..\test_issue_4584.odin %COMMON% || exit /b

View File

@@ -17,6 +17,7 @@ $ODIN test ../test_issue_2466.odin $COMMON
$ODIN test ../test_issue_2615.odin $COMMON
$ODIN test ../test_issue_2637.odin $COMMON
$ODIN test ../test_issue_2666.odin $COMMON
$ODIN test ../test_issue_2694.odin $COMMON
$ODIN test ../test_issue_4210.odin $COMMON
$ODIN test ../test_issue_4364.odin $COMMON
$ODIN test ../test_issue_4584.odin $COMMON

View File

@@ -0,0 +1,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)
}