Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit 5c5255c

Browse files
committed
test: refactoring to use subtests
Signed-off-by: Alexander Bezzubov <[email protected]>
1 parent 8659709 commit 5c5255c

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

driver/normalizer/strconv_test.go

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
"github.com/stretchr/testify/require"
1010
)
1111

12-
const msg = "test case %d failed"
13-
1412
var testCasesUnquote = []struct {
1513
quoted string
1614
unquoted string
@@ -29,29 +27,33 @@ var testCasesUnquote = []struct {
2927
}
3028

3129
func TestUnquoteSingle(t *testing.T) {
32-
for i, test := range testCasesUnquote {
33-
s, err := unquoteSingle(test.quoted)
34-
require.NoError(t, err, msg, i)
35-
require.Equal(t, test.unquoted, s, msg, i)
30+
for _, test := range testCasesUnquote {
31+
t.Run("", func(t *testing.T) {
32+
s, err := unquoteSingle(test.quoted)
33+
require.NoError(t, err)
34+
require.Equal(t, test.unquoted, s)
35+
})
3636
}
3737
}
3838

3939
func TestUnquoteSingleAndQuoteBack(t *testing.T) {
40-
for i, test := range testCasesUnquote {
41-
u, err := unquoteSingle(test.quoted)
42-
require.NoError(t, err, msg, i)
43-
44-
q := quoteSingle(u)
45-
if test.canonicalQuoted != "" {
46-
assertEquals(t, test.canonicalQuoted, q, i)
47-
} else {
48-
assertEquals(t, test.quoted, q, i)
49-
}
40+
for _, test := range testCasesUnquote {
41+
t.Run("", func(t *testing.T) {
42+
u, err := unquoteSingle(test.quoted)
43+
require.NoError(t, err)
44+
45+
q := quoteSingle(u)
46+
if test.canonicalQuoted != "" {
47+
assertEquals(t, test.canonicalQuoted, q)
48+
} else {
49+
assertEquals(t, test.quoted, q)
50+
}
51+
})
5052
}
5153
}
5254

53-
func assertEquals(t *testing.T, quoted, actual string, i int) {
54-
if !assert.Equal(t, quoted, actual, msg, i) {
55+
func assertEquals(t *testing.T, quoted, actual string) {
56+
if !assert.Equal(t, quoted, actual) {
5557
printDebug(t, quoted, actual)
5658
t.FailNow()
5759
}

0 commit comments

Comments
 (0)