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

Function TestDispenser_NextArg

caddyconfig/caddyfile/dispenser_test.go:63–108  ·  caddyconfig/caddyfile/dispenser_test.go::TestDispenser_NextArg
(t *testing.T)

Source from the content-addressed store, hash-verified

61}
62
63func TestDispenser_NextArg(t *testing.T) {
64 input := `dir1 arg1
65 dir2 arg2 arg3
66 dir3`
67 d := NewTestDispenser(input)
68
69 assertNext := func(shouldLoad bool, expectedVal string, expectedCursor int) {
70 if d.Next() != shouldLoad {
71 t.Errorf("Next(): Should load token but got false instead (val: '%s')", d.Val())
72 }
73 if d.cursor != expectedCursor {
74 t.Errorf("Next(): Expected cursor to be at %d, but it was %d", expectedCursor, d.cursor)
75 }
76 if val := d.Val(); val != expectedVal {
77 t.Errorf("Val(): Expected '%s' but got '%s'", expectedVal, val)
78 }
79 }
80
81 assertNextArg := func(expectedVal string, loadAnother bool, expectedCursor int) {
82 if !d.NextArg() {
83 t.Error("NextArg(): Should load next argument but got false instead")
84 }
85 if d.cursor != expectedCursor {
86 t.Errorf("NextArg(): Expected cursor to be at %d, but it was %d", expectedCursor, d.cursor)
87 }
88 if val := d.Val(); val != expectedVal {
89 t.Errorf("Val(): Expected '%s' but got '%s'", expectedVal, val)
90 }
91 if !loadAnother {
92 if d.NextArg() {
93 t.Fatalf("NextArg(): Should NOT load another argument, but got true instead (val: '%s')", d.Val())
94 }
95 if d.cursor != expectedCursor {
96 t.Errorf("NextArg(): Expected cursor to remain at %d, but it was %d", expectedCursor, d.cursor)
97 }
98 }
99 }
100
101 assertNext(true, "dir1", 0)
102 assertNextArg("arg1", false, 1)
103 assertNext(true, "dir2", 2)
104 assertNextArg("arg2", true, 3)
105 assertNextArg("arg3", false, 4)
106 assertNext(true, "dir3", 5)
107 assertNext(false, "dir3", 5)
108}
109
110func TestDispenser_NextLine(t *testing.T) {
111 input := `host:port

Callers

nothing calls this directly

Calls 5

NewTestDispenserFunction · 0.85
ValMethod · 0.80
NextArgMethod · 0.80
NextMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected