Move tests out of the package
This commit is contained in:
+10
-9
@@ -1,22 +1,23 @@
|
|||||||
package toml
|
package toml_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/pelletier/go-toml/v2"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUnmarshalSimple(t *testing.T) {
|
func TestUnmarshalSimple(t *testing.T) {
|
||||||
x := struct{ Foo string }{}
|
x := struct{ Foo string }{}
|
||||||
err := Unmarshal([]byte(`Foo = "hello"`), &x)
|
err := toml.Unmarshal([]byte(`Foo = "hello"`), &x)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "hello", x.Foo)
|
assert.Equal(t, "hello", x.Foo)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUnmarshalNestedStructs(t *testing.T) {
|
func TestUnmarshalNestedStructs(t *testing.T) {
|
||||||
x := struct{ Foo struct{ Bar string } }{}
|
x := struct{ Foo struct{ Bar string } }{}
|
||||||
err := Unmarshal([]byte(`Foo.Bar = "hello"`), &x)
|
err := toml.Unmarshal([]byte(`Foo.Bar = "hello"`), &x)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "hello", x.Foo.Bar)
|
assert.Equal(t, "hello", x.Foo.Bar)
|
||||||
}
|
}
|
||||||
@@ -26,7 +27,7 @@ func TestUnmarshalNestedStructsMultipleExpressions(t *testing.T) {
|
|||||||
A struct{ B string }
|
A struct{ B string }
|
||||||
C string
|
C string
|
||||||
}{}
|
}{}
|
||||||
err := Unmarshal([]byte(`A.B = "hello"
|
err := toml.Unmarshal([]byte(`A.B = "hello"
|
||||||
C = "test"`), &x)
|
C = "test"`), &x)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "hello", x.A.B)
|
assert.Equal(t, "hello", x.A.B)
|
||||||
@@ -45,7 +46,7 @@ func TestUnmarshalTable(t *testing.T) {
|
|||||||
}
|
}
|
||||||
E string
|
E string
|
||||||
}{}
|
}{}
|
||||||
err := Unmarshal([]byte(`
|
err := toml.Unmarshal([]byte(`
|
||||||
|
|
||||||
E = "E"
|
E = "E"
|
||||||
Foo.C = "C"
|
Foo.C = "C"
|
||||||
@@ -73,7 +74,7 @@ func TestUnmarshalDoesNotEraseBaseStruct(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
A: "preset",
|
A: "preset",
|
||||||
}
|
}
|
||||||
err := Unmarshal([]byte(`B = "data"`), &x)
|
err := toml.Unmarshal([]byte(`B = "data"`), &x)
|
||||||
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "preset", x.A)
|
assert.Equal(t, "preset", x.A)
|
||||||
@@ -98,7 +99,7 @@ Name = "Nail"
|
|||||||
}
|
}
|
||||||
|
|
||||||
x := Data{}
|
x := Data{}
|
||||||
err := Unmarshal([]byte(doc), &x)
|
err := toml.Unmarshal([]byte(doc), &x)
|
||||||
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
@@ -142,7 +143,7 @@ Color = "gray"
|
|||||||
}
|
}
|
||||||
|
|
||||||
x := Data{}
|
x := Data{}
|
||||||
err := Unmarshal([]byte(doc), &x)
|
err := toml.Unmarshal([]byte(doc), &x)
|
||||||
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
@@ -206,7 +207,7 @@ Name = "plantain"
|
|||||||
}
|
}
|
||||||
|
|
||||||
x := Doc{}
|
x := Doc{}
|
||||||
err := Unmarshal([]byte(doc), &x)
|
err := toml.Unmarshal([]byte(doc), &x)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := Doc{
|
expected := Doc{
|
||||||
|
|||||||
Reference in New Issue
Block a user