...
1 package main
2
3 import (
4 "bytes"
5 "strings"
6 "testing"
7
8 "github.com/stretchr/testify/assert"
9 "github.com/stretchr/testify/require"
10 )
11
12 func TestConvert(t *testing.T) {
13 examples := []struct {
14 name string
15 input string
16 expected string
17 errors bool
18 }{
19 {
20 name: "valid toml",
21 input: `
22 mytoml.a = 42.0
23 `,
24 expected: `[mytoml]
25 a = 42.0
26 `,
27 },
28 {
29 name: "invalid toml",
30 input: `[what`,
31 errors: true,
32 },
33 }
34
35 for _, e := range examples {
36 b := new(bytes.Buffer)
37 err := convert(strings.NewReader(e.input), b)
38 if e.errors {
39 require.Error(t, err)
40 } else {
41 assert.NoError(t, err)
42 assert.Equal(t, e.expected, b.String())
43 }
44 }
45 }
46
View as plain text