MCPcopy
hub / github.com/caddyserver/caddy / TestDispenser_NextBlock

Function TestDispenser_NextBlock

caddyconfig/caddyfile/dispenser_test.go:140–169  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

138}
139
140func TestDispenser_NextBlock(t *testing.T) {
141 input := `foobar1 {
142 sub1 arg1
143 sub2
144 }
145 foobar2 {
146 }`
147 d := NewTestDispenser(input)
148
149 assertNextBlock := func(shouldLoad bool, expectedCursor, expectedNesting int) {
150 if loaded := d.NextBlock(0); loaded != shouldLoad {
151 t.Errorf("NextBlock(): Should return %v but got %v", shouldLoad, loaded)
152 }
153 if d.cursor != expectedCursor {
154 t.Errorf("NextBlock(): Expected cursor to be %d, was %d", expectedCursor, d.cursor)
155 }
156 if d.nesting != expectedNesting {
157 t.Errorf("NextBlock(): Nesting should be %d, not %d", expectedNesting, d.nesting)
158 }
159 }
160
161 assertNextBlock(false, -1, 0)
162 d.Next() // foobar1
163 assertNextBlock(true, 2, 1)
164 assertNextBlock(true, 3, 1)
165 assertNextBlock(true, 4, 1)
166 assertNextBlock(false, 5, 0)
167 d.Next() // foobar2
168 assertNextBlock(false, 8, 0) // empty block is as if it didn't exist
169}
170
171func TestDispenser_Args(t *testing.T) {
172 var s1, s2, s3 string

Callers

nothing calls this directly

Calls 3

NewTestDispenserFunction · 0.85
NextBlockMethod · 0.80
NextMethod · 0.65

Tested by

no test coverage detected