MCPcopy
hub / github.com/grpc-ecosystem/grpc-gateway / TestParseSegments

Function TestParseSegments

internal/httprule/parse_test.go:134–291  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

132}
133
134func TestParseSegments(t *testing.T) {
135 for _, spec := range []struct {
136 tokens []string
137 want []segment
138 }{
139 {
140 tokens: []string{eof},
141 want: []segment{
142 literal(eof),
143 },
144 },
145 {
146 // Note: this case will never arise as tokenize() will never return such a sequence of tokens
147 // and even if it does it will be treated as [eof]
148 tokens: []string{eof, "v1", eof},
149 want: []segment{
150 literal(eof),
151 },
152 },
153 {
154 tokens: []string{"v1", eof},
155 want: []segment{
156 literal("v1"),
157 },
158 },
159 {
160 tokens: []string{"/", eof},
161 want: []segment{
162 wildcard{},
163 },
164 },
165 {
166 tokens: []string{"-._~!$&'()*+,;=:@", eof},
167 want: []segment{
168 literal("-._~!$&'()*+,;=:@"),
169 },
170 },
171 {
172 tokens: []string{"%e7%ac%ac%e4%b8%80%e7%89%88", eof},
173 want: []segment{
174 literal("%e7%ac%ac%e4%b8%80%e7%89%88"),
175 },
176 },
177 {
178 tokens: []string{"v1", "/", "*", eof},
179 want: []segment{
180 literal("v1"),
181 wildcard{},
182 },
183 },
184 {
185 tokens: []string{"v1", "/", "**", eof},
186 want: []segment{
187 literal("v1"),
188 deepWildcard{},
189 },
190 },
191 {

Callers

nothing calls this directly

Calls 2

topLevelSegmentsMethod · 0.95
literalTypeAlias · 0.85

Tested by

no test coverage detected