From eaaf7bc29d43b4470623c75e6e409a049b3083af Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 14 Feb 2023 11:02:33 -0700 Subject: compat/json: Valid: Check for EOF --- compat/json/compat_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 compat/json/compat_test.go (limited to 'compat/json/compat_test.go') diff --git a/compat/json/compat_test.go b/compat/json/compat_test.go new file mode 100644 index 0000000..5c8f3ee --- /dev/null +++ b/compat/json/compat_test.go @@ -0,0 +1,34 @@ +// Copyright (C) 2023 Luke Shumaker +// +// SPDX-License-Identifier: GPL-2.0-or-later + +package json + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestCompatValid(t *testing.T) { + t.Parallel() + type testcase struct { + In string + Exp bool + } + testcases := map[string]testcase{ + "empty": {In: ``, Exp: false}, + "num": {In: `1`, Exp: true}, + "trunc": {In: `{`, Exp: false}, + "object": {In: `{}`, Exp: true}, + } + for tcName, tc := range testcases { + tc := tc + t.Run(tcName, func(t *testing.T) { + t.Parallel() + t.Logf("in=%q", tc.In) + act := Valid([]byte(tc.In)) + assert.Equal(t, tc.Exp, act) + }) + } +} -- cgit v1.2.3-2-g168b