Skip to content

Commit 6805a3d

Browse files
committed
add test for embed field
1 parent 0ae83fe commit 6805a3d

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

encode_test.go

+37-5
Original file line numberDiff line numberDiff line change
@@ -246,17 +246,22 @@ func TestEncodeOmitemptyWithEmptyName(t *testing.T) {
246246

247247
func TestEncodeAnonymousStruct(t *testing.T) {
248248
type Inner struct{ N int }
249-
type Outer0 struct{ Inner }
249+
type inner struct{ B int }
250+
type Outer0 struct {
251+
Inner
252+
inner
253+
}
250254
type Outer1 struct {
251255
Inner `toml:"inner"`
256+
inner `toml:"innerb"`
252257
}
253258

254-
v0 := Outer0{Inner{3}}
255-
expected := "N = 3\n"
259+
v0 := Outer0{Inner{3}, inner{4}}
260+
expected := "N = 3\nB = 4\n"
256261
encodeExpected(t, "embedded anonymous untagged struct", v0, expected, nil)
257262

258-
v1 := Outer1{Inner{3}}
259-
expected = "[inner]\n N = 3\n"
263+
v1 := Outer1{Inner{3}, inner{4}}
264+
expected = "[inner]\n N = 3\n\n[innerb]\n B = 4\n"
260265
encodeExpected(t, "embedded anonymous tagged struct", v1, expected, nil)
261266
}
262267

@@ -315,6 +320,33 @@ func TestEncodeNestedAnonymousStructs(t *testing.T) {
315320
encodeExpected(t, "nested anonymous untagged structs", v, expected, nil)
316321
}
317322

323+
type InnerForNextTest struct{ N int }
324+
325+
func (InnerForNextTest) F() {}
326+
func (InnerForNextTest) G() {}
327+
328+
func TestEncodeAnonymousNoStructField(t *testing.T) {
329+
type Inner interface{ F() }
330+
type inner interface{ G() }
331+
type IntS []int
332+
type intS []int
333+
type Outer0 struct {
334+
Inner
335+
inner
336+
IntS
337+
intS
338+
}
339+
340+
v0 := Outer0{
341+
Inner: InnerForNextTest{3},
342+
inner: InnerForNextTest{4},
343+
IntS: []int{5, 6},
344+
intS: []int{7, 8},
345+
}
346+
expected := "IntS = [5, 6]\n\n[Inner]\n N = 3\n"
347+
encodeExpected(t, "non struct anonymous field", v0, expected, nil)
348+
}
349+
318350
func TestEncodeIgnoredFields(t *testing.T) {
319351
type simple struct {
320352
Number int `toml:"-"`

0 commit comments

Comments
 (0)