summaryrefslogtreecommitdiff
path: root/decode_test.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@datawire.io>2022-08-16 22:40:19 -0600
committerLuke Shumaker <lukeshu@datawire.io>2022-08-17 00:12:35 -0600
commite57bee02e02b7e3697d6c3cb8b75923a92100427 (patch)
treef32610f2b73fbea1f2a94e108fabca18d31d5d27 /decode_test.go
parent87b02577e50b76d373e3c6b921d776e39cb83346 (diff)
Add tests for decode reading too far
Diffstat (limited to 'decode_test.go')
-rw-r--r--decode_test.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/decode_test.go b/decode_test.go
new file mode 100644
index 0000000..8220e39
--- /dev/null
+++ b/decode_test.go
@@ -0,0 +1,21 @@
+// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com>
+//
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+package lowmemjson
+
+import (
+ "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
+}