Skip to content

Commit 45e7e49

Browse files
committed
Update toml-test
1 parent c320c2d commit 45e7e49

File tree

244 files changed

+1459
-844
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

244 files changed

+1459
-844
lines changed

decode_test.go

Lines changed: 0 additions & 197 deletions
Original file line numberDiff line numberDiff line change
@@ -253,53 +253,6 @@ Number = 123
253253
}
254254
}
255255

256-
func TestDecodeTableArrays(t *testing.T) {
257-
var tomlTableArrays = `
258-
[[albums]]
259-
name = "Born to Run"
260-
261-
[[albums.songs]]
262-
name = "Jungleland"
263-
264-
[[albums.songs]]
265-
name = "Meeting Across the River"
266-
267-
[[albums]]
268-
name = "Born in the USA"
269-
270-
[[albums.songs]]
271-
name = "Glory Days"
272-
273-
[[albums.songs]]
274-
name = "Dancing in the Dark"
275-
`
276-
277-
type Song struct {
278-
Name string
279-
}
280-
281-
type Album struct {
282-
Name string
283-
Songs []Song
284-
}
285-
286-
type Music struct {
287-
Albums []Album
288-
}
289-
290-
expected := Music{[]Album{
291-
{"Born to Run", []Song{{"Jungleland"}, {"Meeting Across the River"}}},
292-
{"Born in the USA", []Song{{"Glory Days"}, {"Dancing in the Dark"}}},
293-
}}
294-
var got Music
295-
if _, err := Decode(tomlTableArrays, &got); err != nil {
296-
t.Fatal(err)
297-
}
298-
if !reflect.DeepEqual(expected, got) {
299-
t.Fatalf("\n%#v\n!=\n%#v\n", expected, got)
300-
}
301-
}
302-
303256
func TestDecodePointers(t *testing.T) {
304257
type Object struct {
305258
Type string
@@ -659,92 +612,6 @@ name = "Rice"
659612

660613
}
661614

662-
func TestDecodeInlineTable(t *testing.T) {
663-
input := `
664-
[CookieJar]
665-
Types = {Chocolate = "yummy", Oatmeal = "best ever"}
666-
667-
[Seasons]
668-
Locations = {NY = {Temp = "not cold", Rating = 4}, MI = {Temp = "freezing", Rating = 9}}
669-
`
670-
type cookieJar struct {
671-
Types map[string]string
672-
}
673-
type properties struct {
674-
Temp string
675-
Rating int
676-
}
677-
type seasons struct {
678-
Locations map[string]properties
679-
}
680-
type wrapper struct {
681-
CookieJar cookieJar
682-
Seasons seasons
683-
}
684-
var got wrapper
685-
686-
meta, err := Decode(input, &got)
687-
if err != nil {
688-
t.Fatal(err)
689-
}
690-
want := wrapper{
691-
CookieJar: cookieJar{
692-
Types: map[string]string{
693-
"Chocolate": "yummy",
694-
"Oatmeal": "best ever",
695-
},
696-
},
697-
Seasons: seasons{
698-
Locations: map[string]properties{
699-
"NY": {
700-
Temp: "not cold",
701-
Rating: 4,
702-
},
703-
"MI": {
704-
Temp: "freezing",
705-
Rating: 9,
706-
},
707-
},
708-
},
709-
}
710-
if !reflect.DeepEqual(got, want) {
711-
t.Fatalf("after decode, got:\n\n%#v\n\nwant:\n\n%#v", got, want)
712-
}
713-
if len(meta.keys) != 12 {
714-
t.Errorf("after decode, got %d meta keys; want 12", len(meta.keys))
715-
}
716-
if len(meta.keyInfo) != 12 {
717-
t.Errorf("after decode, got %d meta keyInfo; want 12", len(meta.keyInfo))
718-
}
719-
}
720-
721-
func TestDecodeInlineTableArray(t *testing.T) {
722-
type point struct {
723-
X, Y, Z int
724-
}
725-
var got struct {
726-
Points []point
727-
}
728-
// Example inline table array from the spec.
729-
const in = `
730-
points = [ { x = 1, y = 2, z = 3 },
731-
{ x = 7, y = 8, z = 9 },
732-
{ x = 2, y = 4, z = 8 } ]
733-
734-
`
735-
if _, err := Decode(in, &got); err != nil {
736-
t.Fatal(err)
737-
}
738-
want := []point{
739-
{X: 1, Y: 2, Z: 3},
740-
{X: 7, Y: 8, Z: 9},
741-
{X: 2, Y: 4, Z: 8},
742-
}
743-
if !reflect.DeepEqual(got.Points, want) {
744-
t.Errorf("got %#v; want %#v", got.Points, want)
745-
}
746-
}
747-
748615
type menu struct {
749616
Dishes map[string]dish
750617
}
@@ -789,70 +656,6 @@ type ingredient struct {
789656
Name string
790657
}
791658

792-
func TestDecodeSlices(t *testing.T) {
793-
type (
794-
T struct {
795-
Arr []string
796-
Tbl map[string]any
797-
}
798-
M map[string]any
799-
)
800-
tests := []struct {
801-
input string
802-
in, want T
803-
}{
804-
{"",
805-
T{}, T{}},
806-
807-
// Leave existing values alone.
808-
{"",
809-
T{[]string{}, M{"arr": []string{}}},
810-
T{[]string{}, M{"arr": []string{}}}},
811-
{"",
812-
T{[]string{"a"}, M{"arr": []string{"b"}}},
813-
T{[]string{"a"}, M{"arr": []string{"b"}}}},
814-
815-
// Empty array always allocates (see #339)
816-
{`arr = []
817-
tbl = {arr = []}`,
818-
T{},
819-
T{[]string{}, M{"arr": []any{}}}},
820-
{`arr = []
821-
tbl = {}`,
822-
T{[]string{}, M{}},
823-
T{[]string{}, M{}}},
824-
825-
{`arr = []`,
826-
T{[]string{"a"}, M{}},
827-
T{[]string{}, M{}}},
828-
829-
{`arr = ["x"]
830-
tbl = {arr=["y"]}`,
831-
T{},
832-
T{[]string{"x"}, M{"arr": []any{"y"}}}},
833-
{`arr = ["x"]
834-
tbl = {arr=["y"]}`,
835-
T{[]string{}, M{}},
836-
T{[]string{"x"}, M{"arr": []any{"y"}}}},
837-
{`arr = ["x"]
838-
tbl = {arr=["y"]}`,
839-
T{[]string{"a", "b"}, M{"arr": []any{"c", "d"}}},
840-
T{[]string{"x"}, M{"arr": []any{"y"}}}},
841-
}
842-
843-
for _, tt := range tests {
844-
t.Run("", func(t *testing.T) {
845-
_, err := Decode(tt.input, &tt.in)
846-
if err != nil {
847-
t.Error(err)
848-
}
849-
if !reflect.DeepEqual(tt.in, tt.want) {
850-
t.Errorf("\nhave: %#v\nwant: %#v", tt.in, tt.want)
851-
}
852-
})
853-
}
854-
}
855-
856659
func TestDecodePrimitive(t *testing.T) {
857660
type S struct {
858661
P Primitive

encode_test.go

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -55,46 +55,6 @@ func TestEncodeRoundTrip(t *testing.T) {
5555
}
5656
}
5757

58-
func TestEncodeNestedTableArrays(t *testing.T) {
59-
type song struct {
60-
Name string `toml:"name"`
61-
}
62-
type album struct {
63-
Name string `toml:"name"`
64-
Songs []song `toml:"songs"`
65-
}
66-
type springsteen struct {
67-
Albums []album `toml:"albums"`
68-
}
69-
value := springsteen{
70-
[]album{
71-
{"Born to Run",
72-
[]song{{"Jungleland"}, {"Meeting Across the River"}}},
73-
{"Born in the USA",
74-
[]song{{"Glory Days"}, {"Dancing in the Dark"}}},
75-
},
76-
}
77-
expected := `[[albums]]
78-
name = "Born to Run"
79-
80-
[[albums.songs]]
81-
name = "Jungleland"
82-
83-
[[albums.songs]]
84-
name = "Meeting Across the River"
85-
86-
[[albums]]
87-
name = "Born in the USA"
88-
89-
[[albums.songs]]
90-
name = "Glory Days"
91-
92-
[[albums.songs]]
93-
name = "Dancing in the Dark"
94-
`
95-
encodeExpected(t, "nested table arrays", value, expected, nil)
96-
}
97-
9858
func TestEncodeArrayHashWithNormalHashOrder(t *testing.T) {
9959
type Alpha struct {
10060
V int

error_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ func TestErrorPosition(t *testing.T) {
1818
tests := []struct {
1919
test, err string
2020
}{
21-
{"array/missing-separator.toml", `
21+
{"array/missing-separator-2.toml", `
2222
toml: error: expected a comma (',') or array terminator (']'), but got '2'
2323
2424
At line 1, column 13:
2525
2626
1 | wrong = [ 1 2 3 ]
2727
^`},
2828

29-
{"array/no-close-2.toml", `
29+
{"array/no-close-1.toml", `
3030
toml: error: expected a comma (',') or array terminator (']'), but got end of file
3131
32-
At line 1, column 10:
32+
At line 1, column 23:
3333
34-
1 | x = [42 #
35-
^`},
34+
1 | no-close-1 = [ 1, 2, 3
35+
^`},
3636

3737
{"array/tables-2.toml", `
3838
toml: error: Key 'fruit.variety' has already been defined.

0 commit comments

Comments
 (0)