@@ -182,33 +182,43 @@ func TestEncodeOmitEmptyStruct(t *testing.T) {
182
182
}
183
183
184
184
func TestEncodeWithOmitEmpty (t * testing.T ) {
185
+ type compareable struct {
186
+ Bool bool `toml:"bool,omitempty"`
187
+ }
185
188
type uncomparable struct {
186
- Field []string `toml:"Field,omitempty"`
189
+ Field []string `toml:"field,omitempty"`
190
+ }
191
+ type nestedUncomparable struct {
192
+ Field uncomparable `toml:"uncomparable,omitempty"`
193
+ Bool bool `toml:"bool,omitempty"`
187
194
}
188
195
type simple struct {
189
- Bool bool `toml:"bool,omitempty"`
190
- String string `toml:"string,omitempty"`
191
- Array [0 ]byte `toml:"array,omitempty"`
192
- Slice []int `toml:"slice,omitempty"`
193
- Map map [string ]string `toml:"map,omitempty"`
194
- Time time.Time `toml:"time,omitempty"`
195
- Uncomparable1 uncomparable `toml:"uncomparable1,omitempty"`
196
- Uncomparable2 uncomparable `toml:"uncomparable2,omitempty"`
196
+ Bool bool `toml:"bool,omitempty"`
197
+ String string `toml:"string,omitempty"`
198
+ Array [0 ]byte `toml:"array,omitempty"`
199
+ Slice []int `toml:"slice,omitempty"`
200
+ Map map [string ]string `toml:"map,omitempty"`
201
+ Time time.Time `toml:"time,omitempty"`
202
+ Compareable1 compareable `toml:"compareable1,omitempty"`
203
+ Compareable2 compareable `toml:"compareable2,omitempty"`
204
+ Uncomparable1 uncomparable `toml:"uncomparable1,omitempty"`
205
+ Uncomparable2 uncomparable `toml:"uncomparable2,omitempty"`
206
+ NestedUncomparable1 nestedUncomparable `toml:"nesteduncomparable1,omitempty"`
207
+ NestedUncomparable2 nestedUncomparable `toml:"nesteduncomparable2,omitempty"`
197
208
}
198
209
199
210
var v simple
200
- encodeExpected (t , "fields with omitempty are omitted when empty" , v , `
201
- [uncomparable1]
202
-
203
- [uncomparable2]
204
- ` , nil )
211
+ encodeExpected (t , "fields with omitempty are omitted when empty" , v , "" , nil )
205
212
v = simple {
206
- Bool : true ,
207
- String : " " ,
208
- Slice : []int {2 , 3 , 4 },
209
- Map : map [string ]string {"foo" : "bar" },
210
- Time : time .Date (1985 , 6 , 18 , 15 , 16 , 17 , 0 , time .UTC ),
211
- Uncomparable2 : uncomparable {[]string {"XXX" }},
213
+ Bool : true ,
214
+ String : " " ,
215
+ Slice : []int {2 , 3 , 4 },
216
+ Map : map [string ]string {"foo" : "bar" },
217
+ Time : time .Date (1985 , 6 , 18 , 15 , 16 , 17 , 0 , time .UTC ),
218
+ Compareable2 : compareable {true },
219
+ Uncomparable2 : uncomparable {[]string {"XXX" }},
220
+ NestedUncomparable1 : nestedUncomparable {uncomparable {[]string {"XXX" }}, false },
221
+ NestedUncomparable2 : nestedUncomparable {uncomparable {}, true },
212
222
}
213
223
expected := `bool = true
214
224
string = " "
@@ -218,10 +228,18 @@ time = 1985-06-18T15:16:17Z
218
228
[map]
219
229
foo = "bar"
220
230
221
- [uncomparable1]
231
+ [compareable2]
232
+ bool = true
222
233
223
234
[uncomparable2]
224
- Field = ["XXX"]
235
+ field = ["XXX"]
236
+
237
+ [nesteduncomparable1]
238
+ [nesteduncomparable1.uncomparable]
239
+ field = ["XXX"]
240
+
241
+ [nesteduncomparable2]
242
+ bool = true
225
243
`
226
244
encodeExpected (t , "fields with omitempty are not omitted when non-empty" ,
227
245
v , expected , nil )
@@ -643,8 +661,9 @@ func TestEncodeEmpty(t *testing.T) {
643
661
}
644
662
645
663
// Would previously fail on 32bit architectures; can test with:
646
- // GOARCH=386 go test -c && ./toml.test
647
- // GOARCH=arm GOARM=7 go test -c && qemu-arm ./toml.test
664
+ //
665
+ // GOARCH=386 go test -c && ./toml.test
666
+ // GOARCH=arm GOARM=7 go test -c && qemu-arm ./toml.test
648
667
func TestEncode32bit (t * testing.T ) {
649
668
type Inner struct {
650
669
A , B , C string
0 commit comments