...
1 package commontest
2
3 import (
4 "strings"
5 "testing"
6
7 "github.com/stretchr/testify/require"
8 )
9
10
11
12
13 type ReaderTestSuite struct {
14
15
16
17 ContextFactory func(input []byte) TestContext
18
19
20
21 ValueTestFactory ValueTestFactory
22
23
24
25 ReadErrorTestFactory ReadErrorTestFactory
26 }
27
28
29 func (s ReaderTestSuite) Run(t *testing.T) {
30 tf := testFactory{
31 valueTestFactory: s.ValueTestFactory,
32 readErrorTestFactory: s.ReadErrorTestFactory,
33 encodingBehavior: encodingBehavior{
34 forParsing: true,
35 },
36 }
37 var testDefs testDefs
38 testDefs = append(testDefs, tf.MakeAllValueTests()...)
39 testDefs = append(testDefs, tf.MakeAllReadErrorTests()...)
40 whitespaceOptions := MakeWhitespaceOptions()
41 whitespaceOptions[""] = ""
42 for _, td := range testDefs {
43 for wsName, wsValue := range whitespaceOptions {
44 testName := td.name
45 if wsName != "" {
46 testName += " [with whitespace: " + wsName + "]"
47 }
48 t.Run(testName, func(t *testing.T) {
49 input := wsValue + strings.Join(td.encoding, wsValue) + wsValue
50 t.Cleanup(func() {
51 if t.Failed() {
52 t.Logf("JSON input was: `%s`", input)
53 }
54 })
55 c := s.ContextFactory([]byte(input))
56 require.NoError(t, td.action(c))
57 })
58 }
59 }
60 }
61
View as plain text