// Copyright (C) 2022 Luke Shumaker // // SPDX-License-Identifier: GPL-2.0-or-later package lowmemjson import ( "io" "strings" "testing" "github.com/stretchr/testify/assert" ) func TestDecodeNumber(t *testing.T) { r := strings.NewReader(`1{}`) var num int assert.NoError(t, Decode(r, &num)) assert.Equal(t, 1, num) assert.Equal(t, 2, r.Len()) // check that it didn't read too far } func TestDecodeObject(t *testing.T) { err := DecodeObject(strings.NewReader(`{"foo":9}`), func(r io.RuneScanner) error { return nil }, func(r io.RuneScanner) error { var n int return Decode(r, &n) }) assert.ErrorContains(t, err, "did not consume entire") }