MCPcopy Create free account
hub / github.com/cli/cli / score

Method score

script/ghmock/restcheck.go:123–158  ·  view source on GitHub ↗
(parts []string)

Source from the content-addressed store, hash-verified

121}
122
123func (r *restRoute) score(parts []string) (int, bool) {
124 segs := r.segments
125 switch {
126 case len(parts) < len(segs):
127 return 0, false
128 case len(parts) > len(segs):
129 if len(segs) == 0 || !slashParams[segs[len(segs)-1].param] {
130 return 0, false
131 }
132 }
133 score := 0
134 for i, s := range segs {
135 part := parts[i]
136 switch {
137 case part == "":
138 return 0, false
139 case s.param != "":
140 case s.pattern != nil:
141 if !s.pattern.MatchString(part) {
142 return 0, false
143 }
144 score++
145 default:
146 if s.literal != part {
147 return 0, false
148 }
149 score += 2
150 }
151 }
152 // An exact segment count beats a final parameter that takes the rest.
153 score *= 2
154 if len(parts) == len(segs) {
155 score++
156 }
157 return score, true
158}
159
160// check compares a response with GitHub's description of it. It returns the
161// problems it found, or a note saying why it couldn't check.

Callers 1

matchMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected