@@ -153,3 +153,48 @@ func TestListenSectionParsers(t *testing.T) {
153153 t .Fatalf ("configurations does not match" )
154154 }
155155}
156+
157+ func TestDefaultSectionsSkipOnWriteParsers (t * testing.T ) {
158+ tests := []struct {
159+ Name string
160+ Config string
161+ Result string
162+ DefaultsSectionToSkip []string
163+ }{
164+ {
165+ "with option DefaultSectionsSkipOnWrite and section present" ,
166+ configDefaultSectionsSkipOnWrite_WithSectionName , configDefaultSectionsSkipOnWrite_WithoutSectionName ,
167+ []string {"to_not_serialize" },
168+ },
169+ {
170+ "with option DefaultSectionsSkipOnWrite and section present - multiple options" ,
171+ configDefaultSectionsSkipOnWrite_WithSectionName , configDefaultSectionsSkipOnWrite_WithoutSectionName ,
172+ []string {"to_not_serialize" , "to_not_serialize2" },
173+ },
174+ {
175+ "no option DefaultSectionsSkipOnWrite and section absent" ,
176+ configDefaultSectionsSkipOnWrite_WithoutSectionName , configDefaultSectionsSkipOnWrite_WithoutSectionName ,
177+ []string {"to_not_serialize" },
178+ },
179+ {
180+ "with option DefaultSectionsSkipOnWrite and section present different option name" ,
181+ configDefaultSectionsSkipOnWrite_WithSectionName , configDefaultSectionsSkipOnWrite_WithSectionName ,
182+ []string {"other" },
183+ },
184+ }
185+
186+ for _ , tt := range tests {
187+ var buffer bytes.Buffer
188+ buffer .WriteString (tt .Config )
189+ p , err := parser .New (options .DefaultSectionsSkipOnWrite (tt .DefaultsSectionToSkip ), options .Reader (& buffer ))
190+ if err != nil {
191+ t .Fatal (err .Error ())
192+ }
193+
194+ result := p .String () //nolint:ifshort
195+ if result != tt .Result {
196+ compare (t , tt .Config , tt .Result )
197+ t .Fatalf ("configurations does not match" )
198+ }
199+ }
200+ }
0 commit comments