@@ -198,6 +198,47 @@ func TestDispenser_NextBlock_MakesProgressOrStopsOnEOF(t *testing.T) {
198198 t .Fatalf ("NextBlock(): exceeded %d iterations without terminating" , maxIters )
199199}
200200
201+ func TestDispenser_NextBlock_MultipleLevelsOfNestedBlocks (t * testing.T ) {
202+ input := `foobar1 {
203+ sub1 arg1
204+ sub2
205+ sub_foobar1 sub_foobar1_arg {
206+ sub3 arg3
207+ sub4
208+ }
209+ }
210+ foobar2 {
211+ }`
212+ d := NewDispenser ("Testfile" , strings .NewReader (input ))
213+
214+ assertNextBlock := func (shouldLoad bool , expectedCursor , expectedNesting int ) {
215+ if loaded := d .NextBlock (); loaded != shouldLoad {
216+ t .Errorf ("NextBlock(): Should return %v but got %v" , shouldLoad , loaded )
217+ }
218+ if d .cursor != expectedCursor {
219+ t .Errorf ("NextBlock(): Expected cursor to be %d, was %d" , expectedCursor , d .cursor )
220+ }
221+ if d .nesting != expectedNesting {
222+ t .Errorf ("NextBlock(): Nesting should be %d, not %d" , expectedNesting , d .nesting )
223+ }
224+ }
225+
226+ assertNextBlock (false , - 1 , 0 )
227+ d .Next () // foobar1
228+ assertNextBlock (true , 2 , 1 )
229+ d .NextArg () // arg1
230+ assertNextBlock (true , 4 , 1 )
231+ assertNextBlock (true , 5 , 1 )
232+ d .NextArg () // sub_foobar1_arg
233+ assertNextBlock (true , 8 , 2 )
234+ d .NextArg () // arg3
235+ assertNextBlock (true , 10 , 2 )
236+ assertNextBlock (false , 11 , 1 )
237+ assertNextBlock (false , 12 , 0 )
238+ d .Next () // foobar2
239+ assertNextBlock (false , 15 , 0 ) // empty block is as if it didn't exist
240+ }
241+
201242func TestDispenser_Args (t * testing.T ) {
202243 var s1 , s2 , s3 string
203244 input := `dir1 arg1 arg2 arg3
0 commit comments