014204cfb7
As recommended, an `internal/assert` package was added with a reduced set of assertions. All tests were then refactored to use the internal assertions. When more complex assertions were used, they have been rewritten using logic and the simplified assertions. Fancy formatting for failures was omitted. The `internal/assert/assertions.diff` function could be overwritten for better formatting. That is where diff libraries are used in other test suites. Refs: #872 Co-authored-by: Alex Mikitik <alex.mikitik@oracle.com>
45 lines
647 B
Go
45 lines
647 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/pelletier/go-toml/v2/internal/assert"
|
|
)
|
|
|
|
func TestConvert(t *testing.T) {
|
|
examples := []struct {
|
|
name string
|
|
input string
|
|
expected string
|
|
errors bool
|
|
}{
|
|
{
|
|
name: "valid toml",
|
|
input: `
|
|
mytoml.a = 42.0
|
|
`,
|
|
expected: `[mytoml]
|
|
a = 42.0
|
|
`,
|
|
},
|
|
{
|
|
name: "invalid toml",
|
|
input: `[what`,
|
|
errors: true,
|
|
},
|
|
}
|
|
|
|
for _, e := range examples {
|
|
b := new(bytes.Buffer)
|
|
err := convert(strings.NewReader(e.input), b)
|
|
if e.errors {
|
|
assert.Error(t, err)
|
|
} else {
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, e.expected, b.String())
|
|
}
|
|
}
|
|
}
|