3 | *
4 | * Permission to use, copy, modify, and distribute this software for any
5 | * purpose with or without fee is hereby granted, provided that the above
6 | * copyright notice and this permission notice appear in all copies.
7 | *
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 | */
16 |
17 | package spew
18 |
19 | import (
20 | "fmt"
21 | "io"
22 | )
23 |
24 | // Errorf is a wrapper for fmt.Errorf that treats each argument as if it were
25 | // passed with a default Formatter interface returned by NewFormatter. It
26 | // returns the formatted string as a value that satisfies error. See
27 | // NewFormatter for formatting details.
28 | //
29 | // This function is shorthand for the following syntax:
30 | //
31 | // fmt.Errorf(format, spew.NewFormatter(a), spew.NewFormatter(b))
32 | func Errorf(format string, a ...interface{}) (err error) {
33 | return fmt.Errorf(format, convertArgs(a)...)
34 | }
35 |
36 | // Fprint is a wrapper for fmt.Fprint that treats each argument as if it were
37 | // passed with a default Formatter interface returned by NewFormatter. It
38 | // returns the number of bytes written and any write error encountered. See
39 | // NewFormatter for formatting details.
40 | //
41 | // This function is shorthand for the following syntax:
42 | //
43 | // fmt.Fprint(w, spew.NewFormatter(a), spew.NewFormatter(b))
44 | func Fprint(w io.Writer, a ...interface{}) (n int, err error) {
45 | return fmt.Fprint(w, convertArgs(a)...)
46 | }
47 |
48 | // Fprintf is a wrapper for fmt.Fprintf that treats each argument as if it were
49 | // passed with a default Formatter interface returned by NewFormatter. It
50 | // returns the number of bytes written and any write error encountered. See
51 | // NewFormatter for formatting details.
52 | //
53 | // This function is shorthand for the following syntax:
54 | //
55 | // fmt.Fprintf(w, format, spew.NewFormatter(a), spew.NewFormatter(b))
56 | func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) {
57 | return fmt.Fprintf(w, format, convertArgs(a)...)
58 | }
59 |
60 | // Fprintln is a wrapper for fmt.Fprintln that treats each argument as if it
61 | // passed with a default Formatter interface returned by NewFormatter. See
62 | // NewFormatter for formatting details.
63 | //
64 | // This function is shorthand for the following syntax:
65 | //
66 | // fmt.Fprintln(w, spew.NewFormatter(a), spew.NewFormatter(b))
67 | func Fprintln(w io.Writer, a ...interface{}) (n int, err error) {
68 | return fmt.Fprintln(w, convertArgs(a)...)
69 | }
70 |
71 | // Print is a wrapper for fmt.Print that treats each argument as if it were
72 | // passed with a default Formatter interface returned by NewFormatter. It
73 | // returns the number of bytes written and any write error encountered. See
74 | // NewFormatter for formatting details.
75 | //
76 | // This function is shorthand for the following syntax:
77 | //
78 | // fmt.Print(spew.NewFormatter(a), spew.NewFormatter(b))
79 | func Print(a ...interface{}) (n int, err error) {
80 | return fmt.Print(convertArgs(a)...)
81 | }
82 |
83 | // Printf is a wrapper for fmt.Printf that treats each argument as if it were
84 | // passed with a default Formatter interface returned by NewFormatter. It
85 | // returns the number of bytes written and any write error encountered. See
86 | // NewFormatter for formatting details.
87 | //
88 | // This function is shorthand for the following syntax:
89 | //
90 | // fmt.Printf(format, spew.NewFormatter(a), spew.NewFormatter(b))
91 | func Printf(format string, a ...interface{}) (n int, err error) {
92 | return fmt.Printf(format, convertArgs(a)...)
93 | }
94 |
95 | // Println is a wrapper for fmt.Println that treats each argument as if it were
96 | // passed with a default Formatter interface returned by NewFormatter. It
97 | // returns the number of bytes written and any write error encountered. See
98 | // NewFormatter for formatting details.
99 | //
100 | // This function is shorthand for the following syntax:
101 | //
102 | // fmt.Println(spew.NewFormatter(a), spew.NewFormatter(b))
103 | func Println(a ...interface{}) (n int, err error) {
104 | return fmt.Println(convertArgs(a)...)
105 | }
106 |
107 | // Sprint is a wrapper for fmt.Sprint that treats each argument as if it were
108 | // passed with a default Formatter interface returned by NewFormatter. It
109 | // returns the resulting string. See NewFormatter for formatting details.
110 | //
111 | // This function is shorthand for the following syntax:
112 | //
113 | // fmt.Sprint(spew.NewFormatter(a), spew.NewFormatter(b))
114 | func Sprint(a ...interface{}) string {
115 | return fmt.Sprint(convertArgs(a)...)
116 | }
117 |
118 | // Sprintf is a wrapper for fmt.Sprintf that treats each argument as if it were
119 | // passed with a default Formatter interface returned by NewFormatter. It
120 | // returns the resulting string. See NewFormatter for formatting details.
121 | //
122 | // This function is shorthand for the following syntax:
123 | //
124 | // fmt.Sprintf(format, spew.NewFormatter(a), spew.NewFormatter(b))
125 | func Sprintf(format string, a ...interface{}) string {
126 | return fmt.Sprintf(format, convertArgs(a)...)
127 | }
128 |
129 | // Sprintln is a wrapper for fmt.Sprintln that treats each argument as if it
130 | // were passed with a default Formatter interface returned by NewFormatter. It
131 | // returns the resulting string. See NewFormatter for formatting details.
132 | //
133 | // This function is shorthand for the following syntax:
134 | //
135 | // fmt.Sprintln(spew.NewFormatter(a), spew.NewFormatter(b))
136 | func Sprintln(a ...interface{}) string {
137 | return fmt.Sprintln(convertArgs(a)...)
138 | }
139 |
140 | // convertArgs accepts a slice of arguments and returns a slice of the same
141 | // length with each argument converted to a default spew Formatter interface.
142 | func convertArgs(args []interface{}) (formatters []interface{}) {
143 | formatters = make([]interface{}, len(args))
144 | for index, arg := range args {
145 | formatters[index] = NewFormatter(arg)
146 | }
147 | return formatters
148 | }
149 |
--------------------------------------------------------------------------------
/vendor/github.com/pmezard/go-difflib/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2013, Patrick Mezard
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are
6 | met:
7 |
8 | Redistributions of source code must retain the above copyright
9 | notice, this list of conditions and the following disclaimer.
10 | Redistributions in binary form must reproduce the above copyright
11 | notice, this list of conditions and the following disclaimer in the
12 | documentation and/or other materials provided with the distribution.
13 | The names of its contributors may not be used to endorse or promote
14 | products derived from this software without specific prior written
15 | permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
23 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/vendor/github.com/pmezard/go-difflib/difflib/difflib.go:
--------------------------------------------------------------------------------
1 | // Package difflib is a partial port of Python difflib module.
2 | //
3 | // It provides tools to compare sequences of strings and generate textual diffs.
4 | //
5 | // The following class and functions have been ported:
6 | //
7 | // - SequenceMatcher
8 | //
9 | // - unified_diff
10 | //
11 | // - context_diff
12 | //
13 | // Getting unified diffs was the main goal of the port. Keep in mind this code
14 | // is mostly suitable to output text differences in a human friendly way, there
15 | // are no guarantees generated diffs are consumable by patch(1).
16 | package difflib
17 |
18 | import (
19 | "bufio"
20 | "bytes"
21 | "fmt"
22 | "io"
23 | "strings"
24 | )
25 |
26 | func min(a, b int) int {
27 | if a < b {
28 | return a
29 | }
30 | return b
31 | }
32 |
33 | func max(a, b int) int {
34 | if a > b {
35 | return a
36 | }
37 | return b
38 | }
39 |
40 | func calculateRatio(matches, length int) float64 {
41 | if length > 0 {
42 | return 2.0 * float64(matches) / float64(length)
43 | }
44 | return 1.0
45 | }
46 |
47 | type Match struct {
48 | A int
49 | B int
50 | Size int
51 | }
52 |
53 | type OpCode struct {
54 | Tag byte
55 | I1 int
56 | I2 int
57 | J1 int
58 | J2 int
59 | }
60 |
61 | // SequenceMatcher compares sequence of strings. The basic
62 | // algorithm predates, and is a little fancier than, an algorithm
63 | // published in the late 1980's by Ratcliff and Obershelp under the
64 | // hyperbolic name "gestalt pattern matching". The basic idea is to find
65 | // the longest contiguous matching subsequence that contains no "junk"
66 | // elements (R-O doesn't address junk). The same idea is then applied
67 | // recursively to the pieces of the sequences to the left and to the right
68 | // of the matching subsequence. This does not yield minimal edit
69 | // sequences, but does tend to yield matches that "look right" to people.
70 | //
71 | // SequenceMatcher tries to compute a "human-friendly diff" between two
72 | // sequences. Unlike e.g. UNIX(tm) diff, the fundamental notion is the
73 | // longest *contiguous* & junk-free matching subsequence. That's what
74 | // catches peoples' eyes. The Windows(tm) windiff has another interesting
75 | // notion, pairing up elements that appear uniquely in each sequence.
76 | // That, and the method here, appear to yield more intuitive difference
77 | // reports than does diff. This method appears to be the least vulnerable
78 | // to synching up on blocks of "junk lines", though (like blank lines in
79 | // ordinary text files, or maybe "" lines in HTML files). That may be
80 | // because this is the only method of the 3 that has a *concept* of
81 | // "junk" .
82 | //
83 | // Timing: Basic R-O is cubic time worst case and quadratic time expected
84 | // case. SequenceMatcher is quadratic time for the worst case and has
85 | // expected-case behavior dependent in a complicated way on how many
86 | // elements the sequences have in common; best case time is linear.
87 | type SequenceMatcher struct {
88 | a []string
89 | b []string
90 | b2j map[string][]int
91 | IsJunk func(string) bool
92 | autoJunk bool
93 | bJunk map[string]struct{}
94 | matchingBlocks []Match
95 | fullBCount map[string]int
96 | bPopular map[string]struct{}
97 | opCodes []OpCode
98 | }
99 |
100 | func NewMatcher(a, b []string) *SequenceMatcher {
101 | m := SequenceMatcher{autoJunk: true}
102 | m.SetSeqs(a, b)
103 | return &m
104 | }
105 |
106 | func NewMatcherWithJunk(a, b []string, autoJunk bool,
107 | isJunk func(string) bool) *SequenceMatcher {
108 |
109 | m := SequenceMatcher{IsJunk: isJunk, autoJunk: autoJunk}
110 | m.SetSeqs(a, b)
111 | return &m
112 | }
113 |
114 | // Set two sequences to be compared.
115 | func (m *SequenceMatcher) SetSeqs(a, b []string) {
116 | m.SetSeq1(a)
117 | m.SetSeq2(b)
118 | }
119 |
120 | // Set the first sequence to be compared. The second sequence to be compared is
121 | // not changed.
122 | //
123 | // SequenceMatcher computes and caches detailed information about the second
124 | // sequence, so if you want to compare one sequence S against many sequences,
125 | // use .SetSeq2(s) once and call .SetSeq1(x) repeatedly for each of the other
126 | // sequences.
127 | //
128 | // See also SetSeqs() and SetSeq2().
129 | func (m *SequenceMatcher) SetSeq1(a []string) {
130 | if &a == &m.a {
131 | return
132 | }
133 | m.a = a
134 | m.matchingBlocks = nil
135 | m.opCodes = nil
136 | }
137 |
138 | // Set the second sequence to be compared. The first sequence to be compared is
139 | // not changed.
140 | func (m *SequenceMatcher) SetSeq2(b []string) {
141 | if &b == &m.b {
142 | return
143 | }
144 | m.b = b
145 | m.matchingBlocks = nil
146 | m.opCodes = nil
147 | m.fullBCount = nil
148 | m.chainB()
149 | }
150 |
151 | func (m *SequenceMatcher) chainB() {
152 | // Populate line -> index mapping
153 | b2j := map[string][]int{}
154 | for i, s := range m.b {
155 | indices := b2j[s]
156 | indices = append(indices, i)
157 | b2j[s] = indices
158 | }
159 |
160 | // Purge junk elements
161 | m.bJunk = map[string]struct{}{}
162 | if m.IsJunk != nil {
163 | junk := m.bJunk
164 | for s, _ := range b2j {
165 | if m.IsJunk(s) {
166 | junk[s] = struct{}{}
167 | }
168 | }
169 | for s, _ := range junk {
170 | delete(b2j, s)
171 | }
172 | }
173 |
174 | // Purge remaining popular elements
175 | popular := map[string]struct{}{}
176 | n := len(m.b)
177 | if m.autoJunk && n >= 200 {
178 | ntest := n/100 + 1
179 | for s, indices := range b2j {
180 | if len(indices) > ntest {
181 | popular[s] = struct{}{}
182 | }
183 | }
184 | for s, _ := range popular {
185 | delete(b2j, s)
186 | }
187 | }
188 | m.bPopular = popular
189 | m.b2j = b2j
190 | }
191 |
192 | func (m *SequenceMatcher) isBJunk(s string) bool {
193 | _, ok := m.bJunk[s]
194 | return ok
195 | }
196 |
197 | // Find longest matching block in a[alo:ahi] and b[blo:bhi].
198 | //
199 | // If IsJunk is not defined:
200 | //
201 | // Return (i,j,k) such that a[i:i+k] is equal to b[j:j+k], where
202 | // alo <= i <= i+k <= ahi
203 | // blo <= j <= j+k <= bhi
204 | // and for all (i',j',k') meeting those conditions,
205 | // k >= k'
206 | // i <= i'
207 | // and if i == i', j <= j'
208 | //
209 | // In other words, of all maximal matching blocks, return one that
210 | // starts earliest in a, and of all those maximal matching blocks that
211 | // start earliest in a, return the one that starts earliest in b.
212 | //
213 | // If IsJunk is defined, first the longest matching block is
214 | // determined as above, but with the additional restriction that no
215 | // junk element appears in the block. Then that block is extended as
216 | // far as possible by matching (only) junk elements on both sides. So
217 | // the resulting block never matches on junk except as identical junk
218 | // happens to be adjacent to an "interesting" match.
219 | //
220 | // If no blocks match, return (alo, blo, 0).
221 | func (m *SequenceMatcher) findLongestMatch(alo, ahi, blo, bhi int) Match {
222 | // CAUTION: stripping common prefix or suffix would be incorrect.
223 | // E.g.,
224 | // ab
225 | // acab
226 | // Longest matching block is "ab", but if common prefix is
227 | // stripped, it's "a" (tied with "b"). UNIX(tm) diff does so
228 | // strip, so ends up claiming that ab is changed to acab by
229 | // inserting "ca" in the middle. That's minimal but unintuitive:
230 | // "it's obvious" that someone inserted "ac" at the front.
231 | // Windiff ends up at the same place as diff, but by pairing up
232 | // the unique 'b's and then matching the first two 'a's.
233 | besti, bestj, bestsize := alo, blo, 0
234 |
235 | // find longest junk-free match
236 | // during an iteration of the loop, j2len[j] = length of longest
237 | // junk-free match ending with a[i-1] and b[j]
238 | j2len := map[int]int{}
239 | for i := alo; i != ahi; i++ {
240 | // look at all instances of a[i] in b; note that because
241 | // b2j has no junk keys, the loop is skipped if a[i] is junk
242 | newj2len := map[int]int{}
243 | for _, j := range m.b2j[m.a[i]] {
244 | // a[i] matches b[j]
245 | if j < blo {
246 | continue
247 | }
248 | if j >= bhi {
249 | break
250 | }
251 | k := j2len[j-1] + 1
252 | newj2len[j] = k
253 | if k > bestsize {
254 | besti, bestj, bestsize = i-k+1, j-k+1, k
255 | }
256 | }
257 | j2len = newj2len
258 | }
259 |
260 | // Extend the best by non-junk elements on each end. In particular,
261 | // "popular" non-junk elements aren't in b2j, which greatly speeds
262 | // the inner loop above, but also means "the best" match so far
263 | // doesn't contain any junk *or* popular non-junk elements.
264 | for besti > alo && bestj > blo && !m.isBJunk(m.b[bestj-1]) &&
265 | m.a[besti-1] == m.b[bestj-1] {
266 | besti, bestj, bestsize = besti-1, bestj-1, bestsize+1
267 | }
268 | for besti+bestsize < ahi && bestj+bestsize < bhi &&
269 | !m.isBJunk(m.b[bestj+bestsize]) &&
270 | m.a[besti+bestsize] == m.b[bestj+bestsize] {
271 | bestsize += 1
272 | }
273 |
274 | // Now that we have a wholly interesting match (albeit possibly
275 | // empty!), we may as well suck up the matching junk on each
276 | // side of it too. Can't think of a good reason not to, and it
277 | // saves post-processing the (possibly considerable) expense of
278 | // figuring out what to do with it. In the case of an empty
279 | // interesting match, this is clearly the right thing to do,
280 | // because no other kind of match is possible in the regions.
281 | for besti > alo && bestj > blo && m.isBJunk(m.b[bestj-1]) &&
282 | m.a[besti-1] == m.b[bestj-1] {
283 | besti, bestj, bestsize = besti-1, bestj-1, bestsize+1
284 | }
285 | for besti+bestsize < ahi && bestj+bestsize < bhi &&
286 | m.isBJunk(m.b[bestj+bestsize]) &&
287 | m.a[besti+bestsize] == m.b[bestj+bestsize] {
288 | bestsize += 1
289 | }
290 |
291 | return Match{A: besti, B: bestj, Size: bestsize}
292 | }
293 |
294 | // Return list of triples describing matching subsequences.
295 | //
296 | // Each triple is of the form (i, j, n), and means that
297 | // a[i:i+n] == b[j:j+n]. The triples are monotonically increasing in
298 | // i and in j. It's also guaranteed that if (i, j, n) and (i', j', n') are
299 | // adjacent triples in the list, and the second is not the last triple in the
300 | // list, then i+n != i' or j+n != j'. IOW, adjacent triples never describe
301 | // adjacent equal blocks.
302 | //
303 | // The last triple is a dummy, (len(a), len(b), 0), and is the only
304 | // triple with n==0.
305 | func (m *SequenceMatcher) GetMatchingBlocks() []Match {
306 | if m.matchingBlocks != nil {
307 | return m.matchingBlocks
308 | }
309 |
310 | var matchBlocks func(alo, ahi, blo, bhi int, matched []Match) []Match
311 | matchBlocks = func(alo, ahi, blo, bhi int, matched []Match) []Match {
312 | match := m.findLongestMatch(alo, ahi, blo, bhi)
313 | i, j, k := match.A, match.B, match.Size
314 | if match.Size > 0 {
315 | if alo < i && blo < j {
316 | matched = matchBlocks(alo, i, blo, j, matched)
317 | }
318 | matched = append(matched, match)
319 | if i+k < ahi && j+k < bhi {
320 | matched = matchBlocks(i+k, ahi, j+k, bhi, matched)
321 | }
322 | }
323 | return matched
324 | }
325 | matched := matchBlocks(0, len(m.a), 0, len(m.b), nil)
326 |
327 | // It's possible that we have adjacent equal blocks in the
328 | // matching_blocks list now.
329 | nonAdjacent := []Match{}
330 | i1, j1, k1 := 0, 0, 0
331 | for _, b := range matched {
332 | // Is this block adjacent to i1, j1, k1?
333 | i2, j2, k2 := b.A, b.B, b.Size
334 | if i1+k1 == i2 && j1+k1 == j2 {
335 | // Yes, so collapse them -- this just increases the length of
336 | // the first block by the length of the second, and the first
337 | // block so lengthened remains the block to compare against.
338 | k1 += k2
339 | } else {
340 | // Not adjacent. Remember the first block (k1==0 means it's
341 | // the dummy we started with), and make the second block the
342 | // new block to compare against.
343 | if k1 > 0 {
344 | nonAdjacent = append(nonAdjacent, Match{i1, j1, k1})
345 | }
346 | i1, j1, k1 = i2, j2, k2
347 | }
348 | }
349 | if k1 > 0 {
350 | nonAdjacent = append(nonAdjacent, Match{i1, j1, k1})
351 | }
352 |
353 | nonAdjacent = append(nonAdjacent, Match{len(m.a), len(m.b), 0})
354 | m.matchingBlocks = nonAdjacent
355 | return m.matchingBlocks
356 | }
357 |
358 | // Return list of 5-tuples describing how to turn a into b.
359 | //
360 | // Each tuple is of the form (tag, i1, i2, j1, j2). The first tuple
361 | // has i1 == j1 == 0, and remaining tuples have i1 == the i2 from the
362 | // tuple preceding it, and likewise for j1 == the previous j2.
363 | //
364 | // The tags are characters, with these meanings:
365 | //
366 | // 'r' (replace): a[i1:i2] should be replaced by b[j1:j2]
367 | //
368 | // 'd' (delete): a[i1:i2] should be deleted, j1==j2 in this case.
369 | //
370 | // 'i' (insert): b[j1:j2] should be inserted at a[i1:i1], i1==i2 in this case.
371 | //
372 | // 'e' (equal): a[i1:i2] == b[j1:j2]
373 | func (m *SequenceMatcher) GetOpCodes() []OpCode {
374 | if m.opCodes != nil {
375 | return m.opCodes
376 | }
377 | i, j := 0, 0
378 | matching := m.GetMatchingBlocks()
379 | opCodes := make([]OpCode, 0, len(matching))
380 | for _, m := range matching {
381 | // invariant: we've pumped out correct diffs to change
382 | // a[:i] into b[:j], and the next matching block is
383 | // a[ai:ai+size] == b[bj:bj+size]. So we need to pump
384 | // out a diff to change a[i:ai] into b[j:bj], pump out
385 | // the matching block, and move (i,j) beyond the match
386 | ai, bj, size := m.A, m.B, m.Size
387 | tag := byte(0)
388 | if i < ai && j < bj {
389 | tag = 'r'
390 | } else if i < ai {
391 | tag = 'd'
392 | } else if j < bj {
393 | tag = 'i'
394 | }
395 | if tag > 0 {
396 | opCodes = append(opCodes, OpCode{tag, i, ai, j, bj})
397 | }
398 | i, j = ai+size, bj+size
399 | // the list of matching blocks is terminated by a
400 | // sentinel with size 0
401 | if size > 0 {
402 | opCodes = append(opCodes, OpCode{'e', ai, i, bj, j})
403 | }
404 | }
405 | m.opCodes = opCodes
406 | return m.opCodes
407 | }
408 |
409 | // Isolate change clusters by eliminating ranges with no changes.
410 | //
411 | // Return a generator of groups with up to n lines of context.
412 | // Each group is in the same format as returned by GetOpCodes().
413 | func (m *SequenceMatcher) GetGroupedOpCodes(n int) [][]OpCode {
414 | if n < 0 {
415 | n = 3
416 | }
417 | codes := m.GetOpCodes()
418 | if len(codes) == 0 {
419 | codes = []OpCode{OpCode{'e', 0, 1, 0, 1}}
420 | }
421 | // Fixup leading and trailing groups if they show no changes.
422 | if codes[0].Tag == 'e' {
423 | c := codes[0]
424 | i1, i2, j1, j2 := c.I1, c.I2, c.J1, c.J2
425 | codes[0] = OpCode{c.Tag, max(i1, i2-n), i2, max(j1, j2-n), j2}
426 | }
427 | if codes[len(codes)-1].Tag == 'e' {
428 | c := codes[len(codes)-1]
429 | i1, i2, j1, j2 := c.I1, c.I2, c.J1, c.J2
430 | codes[len(codes)-1] = OpCode{c.Tag, i1, min(i2, i1+n), j1, min(j2, j1+n)}
431 | }
432 | nn := n + n
433 | groups := [][]OpCode{}
434 | group := []OpCode{}
435 | for _, c := range codes {
436 | i1, i2, j1, j2 := c.I1, c.I2, c.J1, c.J2
437 | // End the current group and start a new one whenever
438 | // there is a large range with no changes.
439 | if c.Tag == 'e' && i2-i1 > nn {
440 | group = append(group, OpCode{c.Tag, i1, min(i2, i1+n),
441 | j1, min(j2, j1+n)})
442 | groups = append(groups, group)
443 | group = []OpCode{}
444 | i1, j1 = max(i1, i2-n), max(j1, j2-n)
445 | }
446 | group = append(group, OpCode{c.Tag, i1, i2, j1, j2})
447 | }
448 | if len(group) > 0 && !(len(group) == 1 && group[0].Tag == 'e') {
449 | groups = append(groups, group)
450 | }
451 | return groups
452 | }
453 |
454 | // Return a measure of the sequences' similarity (float in [0,1]).
455 | //
456 | // Where T is the total number of elements in both sequences, and
457 | // M is the number of matches, this is 2.0*M / T.
458 | // Note that this is 1 if the sequences are identical, and 0 if
459 | // they have nothing in common.
460 | //
461 | // .Ratio() is expensive to compute if you haven't already computed
462 | // .GetMatchingBlocks() or .GetOpCodes(), in which case you may
463 | // want to try .QuickRatio() or .RealQuickRation() first to get an
464 | // upper bound.
465 | func (m *SequenceMatcher) Ratio() float64 {
466 | matches := 0
467 | for _, m := range m.GetMatchingBlocks() {
468 | matches += m.Size
469 | }
470 | return calculateRatio(matches, len(m.a)+len(m.b))
471 | }
472 |
473 | // Return an upper bound on ratio() relatively quickly.
474 | //
475 | // This isn't defined beyond that it is an upper bound on .Ratio(), and
476 | // is faster to compute.
477 | func (m *SequenceMatcher) QuickRatio() float64 {
478 | // viewing a and b as multisets, set matches to the cardinality
479 | // of their intersection; this counts the number of matches
480 | // without regard to order, so is clearly an upper bound
481 | if m.fullBCount == nil {
482 | m.fullBCount = map[string]int{}
483 | for _, s := range m.b {
484 | m.fullBCount[s] = m.fullBCount[s] + 1
485 | }
486 | }
487 |
488 | // avail[x] is the number of times x appears in 'b' less the
489 | // number of times we've seen it in 'a' so far ... kinda
490 | avail := map[string]int{}
491 | matches := 0
492 | for _, s := range m.a {
493 | n, ok := avail[s]
494 | if !ok {
495 | n = m.fullBCount[s]
496 | }
497 | avail[s] = n - 1
498 | if n > 0 {
499 | matches += 1
500 | }
501 | }
502 | return calculateRatio(matches, len(m.a)+len(m.b))
503 | }
504 |
505 | // Return an upper bound on ratio() very quickly.
506 | //
507 | // This isn't defined beyond that it is an upper bound on .Ratio(), and
508 | // is faster to compute than either .Ratio() or .QuickRatio().
509 | func (m *SequenceMatcher) RealQuickRatio() float64 {
510 | la, lb := len(m.a), len(m.b)
511 | return calculateRatio(min(la, lb), la+lb)
512 | }
513 |
514 | // Convert range to the "ed" format
515 | func formatRangeUnified(start, stop int) string {
516 | // Per the diff spec at http://www.unix.org/single_unix_specification/
517 | beginning := start + 1 // lines start numbering with one
518 | length := stop - start
519 | if length == 1 {
520 | return fmt.Sprintf("%d", beginning)
521 | }
522 | if length == 0 {
523 | beginning -= 1 // empty ranges begin at line just before the range
524 | }
525 | return fmt.Sprintf("%d,%d", beginning, length)
526 | }
527 |
528 | // Unified diff parameters
529 | type UnifiedDiff struct {
530 | A []string // First sequence lines
531 | FromFile string // First file name
532 | FromDate string // First file time
533 | B []string // Second sequence lines
534 | ToFile string // Second file name
535 | ToDate string // Second file time
536 | Eol string // Headers end of line, defaults to LF
537 | Context int // Number of context lines
538 | }
539 |
540 | // Compare two sequences of lines; generate the delta as a unified diff.
541 | //
542 | // Unified diffs are a compact way of showing line changes and a few
543 | // lines of context. The number of context lines is set by 'n' which
544 | // defaults to three.
545 | //
546 | // By default, the diff control lines (those with ---, +++, or @@) are
547 | // created with a trailing newline. This is helpful so that inputs
548 | // created from file.readlines() result in diffs that are suitable for
549 | // file.writelines() since both the inputs and outputs have trailing
550 | // newlines.
551 | //
552 | // For inputs that do not have trailing newlines, set the lineterm
553 | // argument to "" so that the output will be uniformly newline free.
554 | //
555 | // The unidiff format normally has a header for filenames and modification
556 | // times. Any or all of these may be specified using strings for
557 | // 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'.
558 | // The modification times are normally expressed in the ISO 8601 format.
559 | func WriteUnifiedDiff(writer io.Writer, diff UnifiedDiff) error {
560 | buf := bufio.NewWriter(writer)
561 | defer buf.Flush()
562 | wf := func(format string, args ...interface{}) error {
563 | _, err := buf.WriteString(fmt.Sprintf(format, args...))
564 | return err
565 | }
566 | ws := func(s string) error {
567 | _, err := buf.WriteString(s)
568 | return err
569 | }
570 |
571 | if len(diff.Eol) == 0 {
572 | diff.Eol = "\n"
573 | }
574 |
575 | started := false
576 | m := NewMatcher(diff.A, diff.B)
577 | for _, g := range m.GetGroupedOpCodes(diff.Context) {
578 | if !started {
579 | started = true
580 | fromDate := ""
581 | if len(diff.FromDate) > 0 {
582 | fromDate = "\t" + diff.FromDate
583 | }
584 | toDate := ""
585 | if len(diff.ToDate) > 0 {
586 | toDate = "\t" + diff.ToDate
587 | }
588 | if diff.FromFile != "" || diff.ToFile != "" {
589 | err := wf("--- %s%s%s", diff.FromFile, fromDate, diff.Eol)
590 | if err != nil {
591 | return err
592 | }
593 | err = wf("+++ %s%s%s", diff.ToFile, toDate, diff.Eol)
594 | if err != nil {
595 | return err
596 | }
597 | }
598 | }
599 | first, last := g[0], g[len(g)-1]
600 | range1 := formatRangeUnified(first.I1, last.I2)
601 | range2 := formatRangeUnified(first.J1, last.J2)
602 | if err := wf("@@ -%s +%s @@%s", range1, range2, diff.Eol); err != nil {
603 | return err
604 | }
605 | for _, c := range g {
606 | i1, i2, j1, j2 := c.I1, c.I2, c.J1, c.J2
607 | if c.Tag == 'e' {
608 | for _, line := range diff.A[i1:i2] {
609 | if err := ws(" " + line); err != nil {
610 | return err
611 | }
612 | }
613 | continue
614 | }
615 | if c.Tag == 'r' || c.Tag == 'd' {
616 | for _, line := range diff.A[i1:i2] {
617 | if err := ws("-" + line); err != nil {
618 | return err
619 | }
620 | }
621 | }
622 | if c.Tag == 'r' || c.Tag == 'i' {
623 | for _, line := range diff.B[j1:j2] {
624 | if err := ws("+" + line); err != nil {
625 | return err
626 | }
627 | }
628 | }
629 | }
630 | }
631 | return nil
632 | }
633 |
634 | // Like WriteUnifiedDiff but returns the diff a string.
635 | func GetUnifiedDiffString(diff UnifiedDiff) (string, error) {
636 | w := &bytes.Buffer{}
637 | err := WriteUnifiedDiff(w, diff)
638 | return string(w.Bytes()), err
639 | }
640 |
641 | // Convert range to the "ed" format.
642 | func formatRangeContext(start, stop int) string {
643 | // Per the diff spec at http://www.unix.org/single_unix_specification/
644 | beginning := start + 1 // lines start numbering with one
645 | length := stop - start
646 | if length == 0 {
647 | beginning -= 1 // empty ranges begin at line just before the range
648 | }
649 | if length <= 1 {
650 | return fmt.Sprintf("%d", beginning)
651 | }
652 | return fmt.Sprintf("%d,%d", beginning, beginning+length-1)
653 | }
654 |
655 | type ContextDiff UnifiedDiff
656 |
657 | // Compare two sequences of lines; generate the delta as a context diff.
658 | //
659 | // Context diffs are a compact way of showing line changes and a few
660 | // lines of context. The number of context lines is set by diff.Context
661 | // which defaults to three.
662 | //
663 | // By default, the diff control lines (those with *** or ---) are
664 | // created with a trailing newline.
665 | //
666 | // For inputs that do not have trailing newlines, set the diff.Eol
667 | // argument to "" so that the output will be uniformly newline free.
668 | //
669 | // The context diff format normally has a header for filenames and
670 | // modification times. Any or all of these may be specified using
671 | // strings for diff.FromFile, diff.ToFile, diff.FromDate, diff.ToDate.
672 | // The modification times are normally expressed in the ISO 8601 format.
673 | // If not specified, the strings default to blanks.
674 | func WriteContextDiff(writer io.Writer, diff ContextDiff) error {
675 | buf := bufio.NewWriter(writer)
676 | defer buf.Flush()
677 | var diffErr error
678 | wf := func(format string, args ...interface{}) {
679 | _, err := buf.WriteString(fmt.Sprintf(format, args...))
680 | if diffErr == nil && err != nil {
681 | diffErr = err
682 | }
683 | }
684 | ws := func(s string) {
685 | _, err := buf.WriteString(s)
686 | if diffErr == nil && err != nil {
687 | diffErr = err
688 | }
689 | }
690 |
691 | if len(diff.Eol) == 0 {
692 | diff.Eol = "\n"
693 | }
694 |
695 | prefix := map[byte]string{
696 | 'i': "+ ",
697 | 'd': "- ",
698 | 'r': "! ",
699 | 'e': " ",
700 | }
701 |
702 | started := false
703 | m := NewMatcher(diff.A, diff.B)
704 | for _, g := range m.GetGroupedOpCodes(diff.Context) {
705 | if !started {
706 | started = true
707 | fromDate := ""
708 | if len(diff.FromDate) > 0 {
709 | fromDate = "\t" + diff.FromDate
710 | }
711 | toDate := ""
712 | if len(diff.ToDate) > 0 {
713 | toDate = "\t" + diff.ToDate
714 | }
715 | if diff.FromFile != "" || diff.ToFile != "" {
716 | wf("*** %s%s%s", diff.FromFile, fromDate, diff.Eol)
717 | wf("--- %s%s%s", diff.ToFile, toDate, diff.Eol)
718 | }
719 | }
720 |
721 | first, last := g[0], g[len(g)-1]
722 | ws("***************" + diff.Eol)
723 |
724 | range1 := formatRangeContext(first.I1, last.I2)
725 | wf("*** %s ****%s", range1, diff.Eol)
726 | for _, c := range g {
727 | if c.Tag == 'r' || c.Tag == 'd' {
728 | for _, cc := range g {
729 | if cc.Tag == 'i' {
730 | continue
731 | }
732 | for _, line := range diff.A[cc.I1:cc.I2] {
733 | ws(prefix[cc.Tag] + line)
734 | }
735 | }
736 | break
737 | }
738 | }
739 |
740 | range2 := formatRangeContext(first.J1, last.J2)
741 | wf("--- %s ----%s", range2, diff.Eol)
742 | for _, c := range g {
743 | if c.Tag == 'r' || c.Tag == 'i' {
744 | for _, cc := range g {
745 | if cc.Tag == 'd' {
746 | continue
747 | }
748 | for _, line := range diff.B[cc.J1:cc.J2] {
749 | ws(prefix[cc.Tag] + line)
750 | }
751 | }
752 | break
753 | }
754 | }
755 | }
756 | return diffErr
757 | }
758 |
759 | // Like WriteContextDiff but returns the diff a string.
760 | func GetContextDiffString(diff ContextDiff) (string, error) {
761 | w := &bytes.Buffer{}
762 | err := WriteContextDiff(w, diff)
763 | return string(w.Bytes()), err
764 | }
765 |
766 | // Split a string on "\n" while preserving them. The output can be used
767 | // as input for UnifiedDiff and ContextDiff structures.
768 | func SplitLines(s string) []string {
769 | lines := strings.SplitAfter(s, "\n")
770 | lines[len(lines)-1] += "\n"
771 | return lines
772 | }
773 |
--------------------------------------------------------------------------------
/vendor/github.com/stretchr/testify/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2012-2018 Mat Ryer and Tyler Bunnell
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/vendor/github.com/stretchr/testify/assert/assertion_format.go:
--------------------------------------------------------------------------------
1 | /*
2 | * CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen
3 | * THIS FILE MUST NOT BE EDITED BY HAND
4 | */
5 |
6 | package assert
7 |
8 | import (
9 | http "net/http"
10 | url "net/url"
11 | time "time"
12 | )
13 |
14 | // Conditionf uses a Comparison to assert a complex condition.
15 | func Conditionf(t TestingT, comp Comparison, msg string, args ...interface{}) bool {
16 | if h, ok := t.(tHelper); ok {
17 | h.Helper()
18 | }
19 | return Condition(t, comp, append([]interface{}{msg}, args...)...)
20 | }
21 |
22 | // Containsf asserts that the specified string, list(array, slice...) or map contains the
23 | // specified substring or element.
24 | //
25 | // assert.Containsf(t, "Hello World", "World", "error message %s", "formatted")
26 | // assert.Containsf(t, ["Hello", "World"], "World", "error message %s", "formatted")
27 | // assert.Containsf(t, {"Hello": "World"}, "Hello", "error message %s", "formatted")
28 | func Containsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) bool {
29 | if h, ok := t.(tHelper); ok {
30 | h.Helper()
31 | }
32 | return Contains(t, s, contains, append([]interface{}{msg}, args...)...)
33 | }
34 |
35 | // DirExistsf checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists.
36 | func DirExistsf(t TestingT, path string, msg string, args ...interface{}) bool {
37 | if h, ok := t.(tHelper); ok {
38 | h.Helper()
39 | }
40 | return DirExists(t, path, append([]interface{}{msg}, args...)...)
41 | }
42 |
43 | // ElementsMatchf asserts that the specified listA(array, slice...) is equal to specified
44 | // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,
45 | // the number of appearances of each of them in both lists should match.
46 | //
47 | // assert.ElementsMatchf(t, [1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted")
48 | func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{}) bool {
49 | if h, ok := t.(tHelper); ok {
50 | h.Helper()
51 | }
52 | return ElementsMatch(t, listA, listB, append([]interface{}{msg}, args...)...)
53 | }
54 |
55 | // Emptyf asserts that the specified object is empty. I.e. nil, "", false, 0 or either
56 | // a slice or a channel with len == 0.
57 | //
58 | // assert.Emptyf(t, obj, "error message %s", "formatted")
59 | func Emptyf(t TestingT, object interface{}, msg string, args ...interface{}) bool {
60 | if h, ok := t.(tHelper); ok {
61 | h.Helper()
62 | }
63 | return Empty(t, object, append([]interface{}{msg}, args...)...)
64 | }
65 |
66 | // Equalf asserts that two objects are equal.
67 | //
68 | // assert.Equalf(t, 123, 123, "error message %s", "formatted")
69 | //
70 | // Pointer variable equality is determined based on the equality of the
71 | // referenced values (as opposed to the memory addresses). Function equality
72 | // cannot be determined and will always fail.
73 | func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
74 | if h, ok := t.(tHelper); ok {
75 | h.Helper()
76 | }
77 | return Equal(t, expected, actual, append([]interface{}{msg}, args...)...)
78 | }
79 |
80 | // EqualErrorf asserts that a function returned an error (i.e. not `nil`)
81 | // and that it is equal to the provided error.
82 | //
83 | // actualObj, err := SomeFunction()
84 | // assert.EqualErrorf(t, err, expectedErrorString, "error message %s", "formatted")
85 | func EqualErrorf(t TestingT, theError error, errString string, msg string, args ...interface{}) bool {
86 | if h, ok := t.(tHelper); ok {
87 | h.Helper()
88 | }
89 | return EqualError(t, theError, errString, append([]interface{}{msg}, args...)...)
90 | }
91 |
92 | // EqualValuesf asserts that two objects are equal or convertable to the same types
93 | // and equal.
94 | //
95 | // assert.EqualValuesf(t, uint32(123, "error message %s", "formatted"), int32(123))
96 | func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
97 | if h, ok := t.(tHelper); ok {
98 | h.Helper()
99 | }
100 | return EqualValues(t, expected, actual, append([]interface{}{msg}, args...)...)
101 | }
102 |
103 | // Errorf asserts that a function returned an error (i.e. not `nil`).
104 | //
105 | // actualObj, err := SomeFunction()
106 | // if assert.Errorf(t, err, "error message %s", "formatted") {
107 | // assert.Equal(t, expectedErrorf, err)
108 | // }
109 | func Errorf(t TestingT, err error, msg string, args ...interface{}) bool {
110 | if h, ok := t.(tHelper); ok {
111 | h.Helper()
112 | }
113 | return Error(t, err, append([]interface{}{msg}, args...)...)
114 | }
115 |
116 | // Exactlyf asserts that two objects are equal in value and type.
117 | //
118 | // assert.Exactlyf(t, int32(123, "error message %s", "formatted"), int64(123))
119 | func Exactlyf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
120 | if h, ok := t.(tHelper); ok {
121 | h.Helper()
122 | }
123 | return Exactly(t, expected, actual, append([]interface{}{msg}, args...)...)
124 | }
125 |
126 | // Failf reports a failure through
127 | func Failf(t TestingT, failureMessage string, msg string, args ...interface{}) bool {
128 | if h, ok := t.(tHelper); ok {
129 | h.Helper()
130 | }
131 | return Fail(t, failureMessage, append([]interface{}{msg}, args...)...)
132 | }
133 |
134 | // FailNowf fails test
135 | func FailNowf(t TestingT, failureMessage string, msg string, args ...interface{}) bool {
136 | if h, ok := t.(tHelper); ok {
137 | h.Helper()
138 | }
139 | return FailNow(t, failureMessage, append([]interface{}{msg}, args...)...)
140 | }
141 |
142 | // Falsef asserts that the specified value is false.
143 | //
144 | // assert.Falsef(t, myBool, "error message %s", "formatted")
145 | func Falsef(t TestingT, value bool, msg string, args ...interface{}) bool {
146 | if h, ok := t.(tHelper); ok {
147 | h.Helper()
148 | }
149 | return False(t, value, append([]interface{}{msg}, args...)...)
150 | }
151 |
152 | // FileExistsf checks whether a file exists in the given path. It also fails if the path points to a directory or there is an error when trying to check the file.
153 | func FileExistsf(t TestingT, path string, msg string, args ...interface{}) bool {
154 | if h, ok := t.(tHelper); ok {
155 | h.Helper()
156 | }
157 | return FileExists(t, path, append([]interface{}{msg}, args...)...)
158 | }
159 |
160 | // HTTPBodyContainsf asserts that a specified handler returns a
161 | // body that contains a string.
162 | //
163 | // assert.HTTPBodyContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")
164 | //
165 | // Returns whether the assertion was successful (true) or not (false).
166 | func HTTPBodyContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) bool {
167 | if h, ok := t.(tHelper); ok {
168 | h.Helper()
169 | }
170 | return HTTPBodyContains(t, handler, method, url, values, str, append([]interface{}{msg}, args...)...)
171 | }
172 |
173 | // HTTPBodyNotContainsf asserts that a specified handler returns a
174 | // body that does not contain a string.
175 | //
176 | // assert.HTTPBodyNotContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")
177 | //
178 | // Returns whether the assertion was successful (true) or not (false).
179 | func HTTPBodyNotContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) bool {
180 | if h, ok := t.(tHelper); ok {
181 | h.Helper()
182 | }
183 | return HTTPBodyNotContains(t, handler, method, url, values, str, append([]interface{}{msg}, args...)...)
184 | }
185 |
186 | // HTTPErrorf asserts that a specified handler returns an error status code.
187 | //
188 | // assert.HTTPErrorf(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
189 | //
190 | // Returns whether the assertion was successful (true, "error message %s", "formatted") or not (false).
191 | func HTTPErrorf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool {
192 | if h, ok := t.(tHelper); ok {
193 | h.Helper()
194 | }
195 | return HTTPError(t, handler, method, url, values, append([]interface{}{msg}, args...)...)
196 | }
197 |
198 | // HTTPRedirectf asserts that a specified handler returns a redirect status code.
199 | //
200 | // assert.HTTPRedirectf(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
201 | //
202 | // Returns whether the assertion was successful (true, "error message %s", "formatted") or not (false).
203 | func HTTPRedirectf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool {
204 | if h, ok := t.(tHelper); ok {
205 | h.Helper()
206 | }
207 | return HTTPRedirect(t, handler, method, url, values, append([]interface{}{msg}, args...)...)
208 | }
209 |
210 | // HTTPSuccessf asserts that a specified handler returns a success status code.
211 | //
212 | // assert.HTTPSuccessf(t, myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted")
213 | //
214 | // Returns whether the assertion was successful (true) or not (false).
215 | func HTTPSuccessf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool {
216 | if h, ok := t.(tHelper); ok {
217 | h.Helper()
218 | }
219 | return HTTPSuccess(t, handler, method, url, values, append([]interface{}{msg}, args...)...)
220 | }
221 |
222 | // Implementsf asserts that an object is implemented by the specified interface.
223 | //
224 | // assert.Implementsf(t, (*MyInterface, "error message %s", "formatted")(nil), new(MyObject))
225 | func Implementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) bool {
226 | if h, ok := t.(tHelper); ok {
227 | h.Helper()
228 | }
229 | return Implements(t, interfaceObject, object, append([]interface{}{msg}, args...)...)
230 | }
231 |
232 | // InDeltaf asserts that the two numerals are within delta of each other.
233 | //
234 | // assert.InDeltaf(t, math.Pi, (22 / 7.0, "error message %s", "formatted"), 0.01)
235 | func InDeltaf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool {
236 | if h, ok := t.(tHelper); ok {
237 | h.Helper()
238 | }
239 | return InDelta(t, expected, actual, delta, append([]interface{}{msg}, args...)...)
240 | }
241 |
242 | // InDeltaMapValuesf is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.
243 | func InDeltaMapValuesf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool {
244 | if h, ok := t.(tHelper); ok {
245 | h.Helper()
246 | }
247 | return InDeltaMapValues(t, expected, actual, delta, append([]interface{}{msg}, args...)...)
248 | }
249 |
250 | // InDeltaSlicef is the same as InDelta, except it compares two slices.
251 | func InDeltaSlicef(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool {
252 | if h, ok := t.(tHelper); ok {
253 | h.Helper()
254 | }
255 | return InDeltaSlice(t, expected, actual, delta, append([]interface{}{msg}, args...)...)
256 | }
257 |
258 | // InEpsilonf asserts that expected and actual have a relative error less than epsilon
259 | func InEpsilonf(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) bool {
260 | if h, ok := t.(tHelper); ok {
261 | h.Helper()
262 | }
263 | return InEpsilon(t, expected, actual, epsilon, append([]interface{}{msg}, args...)...)
264 | }
265 |
266 | // InEpsilonSlicef is the same as InEpsilon, except it compares each value from two slices.
267 | func InEpsilonSlicef(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) bool {
268 | if h, ok := t.(tHelper); ok {
269 | h.Helper()
270 | }
271 | return InEpsilonSlice(t, expected, actual, epsilon, append([]interface{}{msg}, args...)...)
272 | }
273 |
274 | // IsTypef asserts that the specified objects are of the same type.
275 | func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, args ...interface{}) bool {
276 | if h, ok := t.(tHelper); ok {
277 | h.Helper()
278 | }
279 | return IsType(t, expectedType, object, append([]interface{}{msg}, args...)...)
280 | }
281 |
282 | // JSONEqf asserts that two JSON strings are equivalent.
283 | //
284 | // assert.JSONEqf(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted")
285 | func JSONEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) bool {
286 | if h, ok := t.(tHelper); ok {
287 | h.Helper()
288 | }
289 | return JSONEq(t, expected, actual, append([]interface{}{msg}, args...)...)
290 | }
291 |
292 | // Lenf asserts that the specified object has specific length.
293 | // Lenf also fails if the object has a type that len() not accept.
294 | //
295 | // assert.Lenf(t, mySlice, 3, "error message %s", "formatted")
296 | func Lenf(t TestingT, object interface{}, length int, msg string, args ...interface{}) bool {
297 | if h, ok := t.(tHelper); ok {
298 | h.Helper()
299 | }
300 | return Len(t, object, length, append([]interface{}{msg}, args...)...)
301 | }
302 |
303 | // Nilf asserts that the specified object is nil.
304 | //
305 | // assert.Nilf(t, err, "error message %s", "formatted")
306 | func Nilf(t TestingT, object interface{}, msg string, args ...interface{}) bool {
307 | if h, ok := t.(tHelper); ok {
308 | h.Helper()
309 | }
310 | return Nil(t, object, append([]interface{}{msg}, args...)...)
311 | }
312 |
313 | // NoErrorf asserts that a function returned no error (i.e. `nil`).
314 | //
315 | // actualObj, err := SomeFunction()
316 | // if assert.NoErrorf(t, err, "error message %s", "formatted") {
317 | // assert.Equal(t, expectedObj, actualObj)
318 | // }
319 | func NoErrorf(t TestingT, err error, msg string, args ...interface{}) bool {
320 | if h, ok := t.(tHelper); ok {
321 | h.Helper()
322 | }
323 | return NoError(t, err, append([]interface{}{msg}, args...)...)
324 | }
325 |
326 | // NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the
327 | // specified substring or element.
328 | //
329 | // assert.NotContainsf(t, "Hello World", "Earth", "error message %s", "formatted")
330 | // assert.NotContainsf(t, ["Hello", "World"], "Earth", "error message %s", "formatted")
331 | // assert.NotContainsf(t, {"Hello": "World"}, "Earth", "error message %s", "formatted")
332 | func NotContainsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) bool {
333 | if h, ok := t.(tHelper); ok {
334 | h.Helper()
335 | }
336 | return NotContains(t, s, contains, append([]interface{}{msg}, args...)...)
337 | }
338 |
339 | // NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
340 | // a slice or a channel with len == 0.
341 | //
342 | // if assert.NotEmptyf(t, obj, "error message %s", "formatted") {
343 | // assert.Equal(t, "two", obj[1])
344 | // }
345 | func NotEmptyf(t TestingT, object interface{}, msg string, args ...interface{}) bool {
346 | if h, ok := t.(tHelper); ok {
347 | h.Helper()
348 | }
349 | return NotEmpty(t, object, append([]interface{}{msg}, args...)...)
350 | }
351 |
352 | // NotEqualf asserts that the specified values are NOT equal.
353 | //
354 | // assert.NotEqualf(t, obj1, obj2, "error message %s", "formatted")
355 | //
356 | // Pointer variable equality is determined based on the equality of the
357 | // referenced values (as opposed to the memory addresses).
358 | func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
359 | if h, ok := t.(tHelper); ok {
360 | h.Helper()
361 | }
362 | return NotEqual(t, expected, actual, append([]interface{}{msg}, args...)...)
363 | }
364 |
365 | // NotNilf asserts that the specified object is not nil.
366 | //
367 | // assert.NotNilf(t, err, "error message %s", "formatted")
368 | func NotNilf(t TestingT, object interface{}, msg string, args ...interface{}) bool {
369 | if h, ok := t.(tHelper); ok {
370 | h.Helper()
371 | }
372 | return NotNil(t, object, append([]interface{}{msg}, args...)...)
373 | }
374 |
375 | // NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic.
376 | //
377 | // assert.NotPanicsf(t, func(){ RemainCalm() }, "error message %s", "formatted")
378 | func NotPanicsf(t TestingT, f PanicTestFunc, msg string, args ...interface{}) bool {
379 | if h, ok := t.(tHelper); ok {
380 | h.Helper()
381 | }
382 | return NotPanics(t, f, append([]interface{}{msg}, args...)...)
383 | }
384 |
385 | // NotRegexpf asserts that a specified regexp does not match a string.
386 | //
387 | // assert.NotRegexpf(t, regexp.MustCompile("starts", "error message %s", "formatted"), "it's starting")
388 | // assert.NotRegexpf(t, "^start", "it's not starting", "error message %s", "formatted")
389 | func NotRegexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) bool {
390 | if h, ok := t.(tHelper); ok {
391 | h.Helper()
392 | }
393 | return NotRegexp(t, rx, str, append([]interface{}{msg}, args...)...)
394 | }
395 |
396 | // NotSubsetf asserts that the specified list(array, slice...) contains not all
397 | // elements given in the specified subset(array, slice...).
398 | //
399 | // assert.NotSubsetf(t, [1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]", "error message %s", "formatted")
400 | func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) bool {
401 | if h, ok := t.(tHelper); ok {
402 | h.Helper()
403 | }
404 | return NotSubset(t, list, subset, append([]interface{}{msg}, args...)...)
405 | }
406 |
407 | // NotZerof asserts that i is not the zero value for its type.
408 | func NotZerof(t TestingT, i interface{}, msg string, args ...interface{}) bool {
409 | if h, ok := t.(tHelper); ok {
410 | h.Helper()
411 | }
412 | return NotZero(t, i, append([]interface{}{msg}, args...)...)
413 | }
414 |
415 | // Panicsf asserts that the code inside the specified PanicTestFunc panics.
416 | //
417 | // assert.Panicsf(t, func(){ GoCrazy() }, "error message %s", "formatted")
418 | func Panicsf(t TestingT, f PanicTestFunc, msg string, args ...interface{}) bool {
419 | if h, ok := t.(tHelper); ok {
420 | h.Helper()
421 | }
422 | return Panics(t, f, append([]interface{}{msg}, args...)...)
423 | }
424 |
425 | // PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that
426 | // the recovered panic value equals the expected panic value.
427 | //
428 | // assert.PanicsWithValuef(t, "crazy error", func(){ GoCrazy() }, "error message %s", "formatted")
429 | func PanicsWithValuef(t TestingT, expected interface{}, f PanicTestFunc, msg string, args ...interface{}) bool {
430 | if h, ok := t.(tHelper); ok {
431 | h.Helper()
432 | }
433 | return PanicsWithValue(t, expected, f, append([]interface{}{msg}, args...)...)
434 | }
435 |
436 | // Regexpf asserts that a specified regexp matches a string.
437 | //
438 | // assert.Regexpf(t, regexp.MustCompile("start", "error message %s", "formatted"), "it's starting")
439 | // assert.Regexpf(t, "start...$", "it's not starting", "error message %s", "formatted")
440 | func Regexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) bool {
441 | if h, ok := t.(tHelper); ok {
442 | h.Helper()
443 | }
444 | return Regexp(t, rx, str, append([]interface{}{msg}, args...)...)
445 | }
446 |
447 | // Subsetf asserts that the specified list(array, slice...) contains all
448 | // elements given in the specified subset(array, slice...).
449 | //
450 | // assert.Subsetf(t, [1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]", "error message %s", "formatted")
451 | func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, args ...interface{}) bool {
452 | if h, ok := t.(tHelper); ok {
453 | h.Helper()
454 | }
455 | return Subset(t, list, subset, append([]interface{}{msg}, args...)...)
456 | }
457 |
458 | // Truef asserts that the specified value is true.
459 | //
460 | // assert.Truef(t, myBool, "error message %s", "formatted")
461 | func Truef(t TestingT, value bool, msg string, args ...interface{}) bool {
462 | if h, ok := t.(tHelper); ok {
463 | h.Helper()
464 | }
465 | return True(t, value, append([]interface{}{msg}, args...)...)
466 | }
467 |
468 | // WithinDurationf asserts that the two times are within duration delta of each other.
469 | //
470 | // assert.WithinDurationf(t, time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted")
471 | func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) bool {
472 | if h, ok := t.(tHelper); ok {
473 | h.Helper()
474 | }
475 | return WithinDuration(t, expected, actual, delta, append([]interface{}{msg}, args...)...)
476 | }
477 |
478 | // Zerof asserts that i is the zero value for its type.
479 | func Zerof(t TestingT, i interface{}, msg string, args ...interface{}) bool {
480 | if h, ok := t.(tHelper); ok {
481 | h.Helper()
482 | }
483 | return Zero(t, i, append([]interface{}{msg}, args...)...)
484 | }
485 |
--------------------------------------------------------------------------------
/vendor/github.com/stretchr/testify/assert/assertion_format.go.tmpl:
--------------------------------------------------------------------------------
1 | {{.CommentFormat}}
2 | func {{.DocInfo.Name}}f(t TestingT, {{.ParamsFormat}}) bool {
3 | if h, ok := t.(tHelper); ok { h.Helper() }
4 | return {{.DocInfo.Name}}(t, {{.ForwardedParamsFormat}})
5 | }
6 |
--------------------------------------------------------------------------------
/vendor/github.com/stretchr/testify/assert/assertion_forward.go:
--------------------------------------------------------------------------------
1 | /*
2 | * CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen
3 | * THIS FILE MUST NOT BE EDITED BY HAND
4 | */
5 |
6 | package assert
7 |
8 | import (
9 | http "net/http"
10 | url "net/url"
11 | time "time"
12 | )
13 |
14 | // Condition uses a Comparison to assert a complex condition.
15 | func (a *Assertions) Condition(comp Comparison, msgAndArgs ...interface{}) bool {
16 | if h, ok := a.t.(tHelper); ok {
17 | h.Helper()
18 | }
19 | return Condition(a.t, comp, msgAndArgs...)
20 | }
21 |
22 | // Conditionf uses a Comparison to assert a complex condition.
23 | func (a *Assertions) Conditionf(comp Comparison, msg string, args ...interface{}) bool {
24 | if h, ok := a.t.(tHelper); ok {
25 | h.Helper()
26 | }
27 | return Conditionf(a.t, comp, msg, args...)
28 | }
29 |
30 | // Contains asserts that the specified string, list(array, slice...) or map contains the
31 | // specified substring or element.
32 | //
33 | // a.Contains("Hello World", "World")
34 | // a.Contains(["Hello", "World"], "World")
35 | // a.Contains({"Hello": "World"}, "Hello")
36 | func (a *Assertions) Contains(s interface{}, contains interface{}, msgAndArgs ...interface{}) bool {
37 | if h, ok := a.t.(tHelper); ok {
38 | h.Helper()
39 | }
40 | return Contains(a.t, s, contains, msgAndArgs...)
41 | }
42 |
43 | // Containsf asserts that the specified string, list(array, slice...) or map contains the
44 | // specified substring or element.
45 | //
46 | // a.Containsf("Hello World", "World", "error message %s", "formatted")
47 | // a.Containsf(["Hello", "World"], "World", "error message %s", "formatted")
48 | // a.Containsf({"Hello": "World"}, "Hello", "error message %s", "formatted")
49 | func (a *Assertions) Containsf(s interface{}, contains interface{}, msg string, args ...interface{}) bool {
50 | if h, ok := a.t.(tHelper); ok {
51 | h.Helper()
52 | }
53 | return Containsf(a.t, s, contains, msg, args...)
54 | }
55 |
56 | // DirExists checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists.
57 | func (a *Assertions) DirExists(path string, msgAndArgs ...interface{}) bool {
58 | if h, ok := a.t.(tHelper); ok {
59 | h.Helper()
60 | }
61 | return DirExists(a.t, path, msgAndArgs...)
62 | }
63 |
64 | // DirExistsf checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists.
65 | func (a *Assertions) DirExistsf(path string, msg string, args ...interface{}) bool {
66 | if h, ok := a.t.(tHelper); ok {
67 | h.Helper()
68 | }
69 | return DirExistsf(a.t, path, msg, args...)
70 | }
71 |
72 | // ElementsMatch asserts that the specified listA(array, slice...) is equal to specified
73 | // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,
74 | // the number of appearances of each of them in both lists should match.
75 | //
76 | // a.ElementsMatch([1, 3, 2, 3], [1, 3, 3, 2])
77 | func (a *Assertions) ElementsMatch(listA interface{}, listB interface{}, msgAndArgs ...interface{}) bool {
78 | if h, ok := a.t.(tHelper); ok {
79 | h.Helper()
80 | }
81 | return ElementsMatch(a.t, listA, listB, msgAndArgs...)
82 | }
83 |
84 | // ElementsMatchf asserts that the specified listA(array, slice...) is equal to specified
85 | // listB(array, slice...) ignoring the order of the elements. If there are duplicate elements,
86 | // the number of appearances of each of them in both lists should match.
87 | //
88 | // a.ElementsMatchf([1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted")
89 | func (a *Assertions) ElementsMatchf(listA interface{}, listB interface{}, msg string, args ...interface{}) bool {
90 | if h, ok := a.t.(tHelper); ok {
91 | h.Helper()
92 | }
93 | return ElementsMatchf(a.t, listA, listB, msg, args...)
94 | }
95 |
96 | // Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either
97 | // a slice or a channel with len == 0.
98 | //
99 | // a.Empty(obj)
100 | func (a *Assertions) Empty(object interface{}, msgAndArgs ...interface{}) bool {
101 | if h, ok := a.t.(tHelper); ok {
102 | h.Helper()
103 | }
104 | return Empty(a.t, object, msgAndArgs...)
105 | }
106 |
107 | // Emptyf asserts that the specified object is empty. I.e. nil, "", false, 0 or either
108 | // a slice or a channel with len == 0.
109 | //
110 | // a.Emptyf(obj, "error message %s", "formatted")
111 | func (a *Assertions) Emptyf(object interface{}, msg string, args ...interface{}) bool {
112 | if h, ok := a.t.(tHelper); ok {
113 | h.Helper()
114 | }
115 | return Emptyf(a.t, object, msg, args...)
116 | }
117 |
118 | // Equal asserts that two objects are equal.
119 | //
120 | // a.Equal(123, 123)
121 | //
122 | // Pointer variable equality is determined based on the equality of the
123 | // referenced values (as opposed to the memory addresses). Function equality
124 | // cannot be determined and will always fail.
125 | func (a *Assertions) Equal(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {
126 | if h, ok := a.t.(tHelper); ok {
127 | h.Helper()
128 | }
129 | return Equal(a.t, expected, actual, msgAndArgs...)
130 | }
131 |
132 | // EqualError asserts that a function returned an error (i.e. not `nil`)
133 | // and that it is equal to the provided error.
134 | //
135 | // actualObj, err := SomeFunction()
136 | // a.EqualError(err, expectedErrorString)
137 | func (a *Assertions) EqualError(theError error, errString string, msgAndArgs ...interface{}) bool {
138 | if h, ok := a.t.(tHelper); ok {
139 | h.Helper()
140 | }
141 | return EqualError(a.t, theError, errString, msgAndArgs...)
142 | }
143 |
144 | // EqualErrorf asserts that a function returned an error (i.e. not `nil`)
145 | // and that it is equal to the provided error.
146 | //
147 | // actualObj, err := SomeFunction()
148 | // a.EqualErrorf(err, expectedErrorString, "error message %s", "formatted")
149 | func (a *Assertions) EqualErrorf(theError error, errString string, msg string, args ...interface{}) bool {
150 | if h, ok := a.t.(tHelper); ok {
151 | h.Helper()
152 | }
153 | return EqualErrorf(a.t, theError, errString, msg, args...)
154 | }
155 |
156 | // EqualValues asserts that two objects are equal or convertable to the same types
157 | // and equal.
158 | //
159 | // a.EqualValues(uint32(123), int32(123))
160 | func (a *Assertions) EqualValues(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {
161 | if h, ok := a.t.(tHelper); ok {
162 | h.Helper()
163 | }
164 | return EqualValues(a.t, expected, actual, msgAndArgs...)
165 | }
166 |
167 | // EqualValuesf asserts that two objects are equal or convertable to the same types
168 | // and equal.
169 | //
170 | // a.EqualValuesf(uint32(123, "error message %s", "formatted"), int32(123))
171 | func (a *Assertions) EqualValuesf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
172 | if h, ok := a.t.(tHelper); ok {
173 | h.Helper()
174 | }
175 | return EqualValuesf(a.t, expected, actual, msg, args...)
176 | }
177 |
178 | // Equalf asserts that two objects are equal.
179 | //
180 | // a.Equalf(123, 123, "error message %s", "formatted")
181 | //
182 | // Pointer variable equality is determined based on the equality of the
183 | // referenced values (as opposed to the memory addresses). Function equality
184 | // cannot be determined and will always fail.
185 | func (a *Assertions) Equalf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
186 | if h, ok := a.t.(tHelper); ok {
187 | h.Helper()
188 | }
189 | return Equalf(a.t, expected, actual, msg, args...)
190 | }
191 |
192 | // Error asserts that a function returned an error (i.e. not `nil`).
193 | //
194 | // actualObj, err := SomeFunction()
195 | // if a.Error(err) {
196 | // assert.Equal(t, expectedError, err)
197 | // }
198 | func (a *Assertions) Error(err error, msgAndArgs ...interface{}) bool {
199 | if h, ok := a.t.(tHelper); ok {
200 | h.Helper()
201 | }
202 | return Error(a.t, err, msgAndArgs...)
203 | }
204 |
205 | // Errorf asserts that a function returned an error (i.e. not `nil`).
206 | //
207 | // actualObj, err := SomeFunction()
208 | // if a.Errorf(err, "error message %s", "formatted") {
209 | // assert.Equal(t, expectedErrorf, err)
210 | // }
211 | func (a *Assertions) Errorf(err error, msg string, args ...interface{}) bool {
212 | if h, ok := a.t.(tHelper); ok {
213 | h.Helper()
214 | }
215 | return Errorf(a.t, err, msg, args...)
216 | }
217 |
218 | // Exactly asserts that two objects are equal in value and type.
219 | //
220 | // a.Exactly(int32(123), int64(123))
221 | func (a *Assertions) Exactly(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {
222 | if h, ok := a.t.(tHelper); ok {
223 | h.Helper()
224 | }
225 | return Exactly(a.t, expected, actual, msgAndArgs...)
226 | }
227 |
228 | // Exactlyf asserts that two objects are equal in value and type.
229 | //
230 | // a.Exactlyf(int32(123, "error message %s", "formatted"), int64(123))
231 | func (a *Assertions) Exactlyf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
232 | if h, ok := a.t.(tHelper); ok {
233 | h.Helper()
234 | }
235 | return Exactlyf(a.t, expected, actual, msg, args...)
236 | }
237 |
238 | // Fail reports a failure through
239 | func (a *Assertions) Fail(failureMessage string, msgAndArgs ...interface{}) bool {
240 | if h, ok := a.t.(tHelper); ok {
241 | h.Helper()
242 | }
243 | return Fail(a.t, failureMessage, msgAndArgs...)
244 | }
245 |
246 | // FailNow fails test
247 | func (a *Assertions) FailNow(failureMessage string, msgAndArgs ...interface{}) bool {
248 | if h, ok := a.t.(tHelper); ok {
249 | h.Helper()
250 | }
251 | return FailNow(a.t, failureMessage, msgAndArgs...)
252 | }
253 |
254 | // FailNowf fails test
255 | func (a *Assertions) FailNowf(failureMessage string, msg string, args ...interface{}) bool {
256 | if h, ok := a.t.(tHelper); ok {
257 | h.Helper()
258 | }
259 | return FailNowf(a.t, failureMessage, msg, args...)
260 | }
261 |
262 | // Failf reports a failure through
263 | func (a *Assertions) Failf(failureMessage string, msg string, args ...interface{}) bool {
264 | if h, ok := a.t.(tHelper); ok {
265 | h.Helper()
266 | }
267 | return Failf(a.t, failureMessage, msg, args...)
268 | }
269 |
270 | // False asserts that the specified value is false.
271 | //
272 | // a.False(myBool)
273 | func (a *Assertions) False(value bool, msgAndArgs ...interface{}) bool {
274 | if h, ok := a.t.(tHelper); ok {
275 | h.Helper()
276 | }
277 | return False(a.t, value, msgAndArgs...)
278 | }
279 |
280 | // Falsef asserts that the specified value is false.
281 | //
282 | // a.Falsef(myBool, "error message %s", "formatted")
283 | func (a *Assertions) Falsef(value bool, msg string, args ...interface{}) bool {
284 | if h, ok := a.t.(tHelper); ok {
285 | h.Helper()
286 | }
287 | return Falsef(a.t, value, msg, args...)
288 | }
289 |
290 | // FileExists checks whether a file exists in the given path. It also fails if the path points to a directory or there is an error when trying to check the file.
291 | func (a *Assertions) FileExists(path string, msgAndArgs ...interface{}) bool {
292 | if h, ok := a.t.(tHelper); ok {
293 | h.Helper()
294 | }
295 | return FileExists(a.t, path, msgAndArgs...)
296 | }
297 |
298 | // FileExistsf checks whether a file exists in the given path. It also fails if the path points to a directory or there is an error when trying to check the file.
299 | func (a *Assertions) FileExistsf(path string, msg string, args ...interface{}) bool {
300 | if h, ok := a.t.(tHelper); ok {
301 | h.Helper()
302 | }
303 | return FileExistsf(a.t, path, msg, args...)
304 | }
305 |
306 | // HTTPBodyContains asserts that a specified handler returns a
307 | // body that contains a string.
308 | //
309 | // a.HTTPBodyContains(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky")
310 | //
311 | // Returns whether the assertion was successful (true) or not (false).
312 | func (a *Assertions) HTTPBodyContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) bool {
313 | if h, ok := a.t.(tHelper); ok {
314 | h.Helper()
315 | }
316 | return HTTPBodyContains(a.t, handler, method, url, values, str, msgAndArgs...)
317 | }
318 |
319 | // HTTPBodyContainsf asserts that a specified handler returns a
320 | // body that contains a string.
321 | //
322 | // a.HTTPBodyContainsf(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")
323 | //
324 | // Returns whether the assertion was successful (true) or not (false).
325 | func (a *Assertions) HTTPBodyContainsf(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) bool {
326 | if h, ok := a.t.(tHelper); ok {
327 | h.Helper()
328 | }
329 | return HTTPBodyContainsf(a.t, handler, method, url, values, str, msg, args...)
330 | }
331 |
332 | // HTTPBodyNotContains asserts that a specified handler returns a
333 | // body that does not contain a string.
334 | //
335 | // a.HTTPBodyNotContains(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky")
336 | //
337 | // Returns whether the assertion was successful (true) or not (false).
338 | func (a *Assertions) HTTPBodyNotContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) bool {
339 | if h, ok := a.t.(tHelper); ok {
340 | h.Helper()
341 | }
342 | return HTTPBodyNotContains(a.t, handler, method, url, values, str, msgAndArgs...)
343 | }
344 |
345 | // HTTPBodyNotContainsf asserts that a specified handler returns a
346 | // body that does not contain a string.
347 | //
348 | // a.HTTPBodyNotContainsf(myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")
349 | //
350 | // Returns whether the assertion was successful (true) or not (false).
351 | func (a *Assertions) HTTPBodyNotContainsf(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) bool {
352 | if h, ok := a.t.(tHelper); ok {
353 | h.Helper()
354 | }
355 | return HTTPBodyNotContainsf(a.t, handler, method, url, values, str, msg, args...)
356 | }
357 |
358 | // HTTPError asserts that a specified handler returns an error status code.
359 | //
360 | // a.HTTPError(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
361 | //
362 | // Returns whether the assertion was successful (true) or not (false).
363 | func (a *Assertions) HTTPError(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) bool {
364 | if h, ok := a.t.(tHelper); ok {
365 | h.Helper()
366 | }
367 | return HTTPError(a.t, handler, method, url, values, msgAndArgs...)
368 | }
369 |
370 | // HTTPErrorf asserts that a specified handler returns an error status code.
371 | //
372 | // a.HTTPErrorf(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
373 | //
374 | // Returns whether the assertion was successful (true, "error message %s", "formatted") or not (false).
375 | func (a *Assertions) HTTPErrorf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool {
376 | if h, ok := a.t.(tHelper); ok {
377 | h.Helper()
378 | }
379 | return HTTPErrorf(a.t, handler, method, url, values, msg, args...)
380 | }
381 |
382 | // HTTPRedirect asserts that a specified handler returns a redirect status code.
383 | //
384 | // a.HTTPRedirect(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
385 | //
386 | // Returns whether the assertion was successful (true) or not (false).
387 | func (a *Assertions) HTTPRedirect(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) bool {
388 | if h, ok := a.t.(tHelper); ok {
389 | h.Helper()
390 | }
391 | return HTTPRedirect(a.t, handler, method, url, values, msgAndArgs...)
392 | }
393 |
394 | // HTTPRedirectf asserts that a specified handler returns a redirect status code.
395 | //
396 | // a.HTTPRedirectf(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
397 | //
398 | // Returns whether the assertion was successful (true, "error message %s", "formatted") or not (false).
399 | func (a *Assertions) HTTPRedirectf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool {
400 | if h, ok := a.t.(tHelper); ok {
401 | h.Helper()
402 | }
403 | return HTTPRedirectf(a.t, handler, method, url, values, msg, args...)
404 | }
405 |
406 | // HTTPSuccess asserts that a specified handler returns a success status code.
407 | //
408 | // a.HTTPSuccess(myHandler, "POST", "http://www.google.com", nil)
409 | //
410 | // Returns whether the assertion was successful (true) or not (false).
411 | func (a *Assertions) HTTPSuccess(handler http.HandlerFunc, method string, url string, values url.Values, msgAndArgs ...interface{}) bool {
412 | if h, ok := a.t.(tHelper); ok {
413 | h.Helper()
414 | }
415 | return HTTPSuccess(a.t, handler, method, url, values, msgAndArgs...)
416 | }
417 |
418 | // HTTPSuccessf asserts that a specified handler returns a success status code.
419 | //
420 | // a.HTTPSuccessf(myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted")
421 | //
422 | // Returns whether the assertion was successful (true) or not (false).
423 | func (a *Assertions) HTTPSuccessf(handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool {
424 | if h, ok := a.t.(tHelper); ok {
425 | h.Helper()
426 | }
427 | return HTTPSuccessf(a.t, handler, method, url, values, msg, args...)
428 | }
429 |
430 | // Implements asserts that an object is implemented by the specified interface.
431 | //
432 | // a.Implements((*MyInterface)(nil), new(MyObject))
433 | func (a *Assertions) Implements(interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) bool {
434 | if h, ok := a.t.(tHelper); ok {
435 | h.Helper()
436 | }
437 | return Implements(a.t, interfaceObject, object, msgAndArgs...)
438 | }
439 |
440 | // Implementsf asserts that an object is implemented by the specified interface.
441 | //
442 | // a.Implementsf((*MyInterface, "error message %s", "formatted")(nil), new(MyObject))
443 | func (a *Assertions) Implementsf(interfaceObject interface{}, object interface{}, msg string, args ...interface{}) bool {
444 | if h, ok := a.t.(tHelper); ok {
445 | h.Helper()
446 | }
447 | return Implementsf(a.t, interfaceObject, object, msg, args...)
448 | }
449 |
450 | // InDelta asserts that the two numerals are within delta of each other.
451 | //
452 | // a.InDelta(math.Pi, (22 / 7.0), 0.01)
453 | func (a *Assertions) InDelta(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {
454 | if h, ok := a.t.(tHelper); ok {
455 | h.Helper()
456 | }
457 | return InDelta(a.t, expected, actual, delta, msgAndArgs...)
458 | }
459 |
460 | // InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.
461 | func (a *Assertions) InDeltaMapValues(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {
462 | if h, ok := a.t.(tHelper); ok {
463 | h.Helper()
464 | }
465 | return InDeltaMapValues(a.t, expected, actual, delta, msgAndArgs...)
466 | }
467 |
468 | // InDeltaMapValuesf is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.
469 | func (a *Assertions) InDeltaMapValuesf(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool {
470 | if h, ok := a.t.(tHelper); ok {
471 | h.Helper()
472 | }
473 | return InDeltaMapValuesf(a.t, expected, actual, delta, msg, args...)
474 | }
475 |
476 | // InDeltaSlice is the same as InDelta, except it compares two slices.
477 | func (a *Assertions) InDeltaSlice(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {
478 | if h, ok := a.t.(tHelper); ok {
479 | h.Helper()
480 | }
481 | return InDeltaSlice(a.t, expected, actual, delta, msgAndArgs...)
482 | }
483 |
484 | // InDeltaSlicef is the same as InDelta, except it compares two slices.
485 | func (a *Assertions) InDeltaSlicef(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool {
486 | if h, ok := a.t.(tHelper); ok {
487 | h.Helper()
488 | }
489 | return InDeltaSlicef(a.t, expected, actual, delta, msg, args...)
490 | }
491 |
492 | // InDeltaf asserts that the two numerals are within delta of each other.
493 | //
494 | // a.InDeltaf(math.Pi, (22 / 7.0, "error message %s", "formatted"), 0.01)
495 | func (a *Assertions) InDeltaf(expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool {
496 | if h, ok := a.t.(tHelper); ok {
497 | h.Helper()
498 | }
499 | return InDeltaf(a.t, expected, actual, delta, msg, args...)
500 | }
501 |
502 | // InEpsilon asserts that expected and actual have a relative error less than epsilon
503 | func (a *Assertions) InEpsilon(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool {
504 | if h, ok := a.t.(tHelper); ok {
505 | h.Helper()
506 | }
507 | return InEpsilon(a.t, expected, actual, epsilon, msgAndArgs...)
508 | }
509 |
510 | // InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices.
511 | func (a *Assertions) InEpsilonSlice(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool {
512 | if h, ok := a.t.(tHelper); ok {
513 | h.Helper()
514 | }
515 | return InEpsilonSlice(a.t, expected, actual, epsilon, msgAndArgs...)
516 | }
517 |
518 | // InEpsilonSlicef is the same as InEpsilon, except it compares each value from two slices.
519 | func (a *Assertions) InEpsilonSlicef(expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) bool {
520 | if h, ok := a.t.(tHelper); ok {
521 | h.Helper()
522 | }
523 | return InEpsilonSlicef(a.t, expected, actual, epsilon, msg, args...)
524 | }
525 |
526 | // InEpsilonf asserts that expected and actual have a relative error less than epsilon
527 | func (a *Assertions) InEpsilonf(expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) bool {
528 | if h, ok := a.t.(tHelper); ok {
529 | h.Helper()
530 | }
531 | return InEpsilonf(a.t, expected, actual, epsilon, msg, args...)
532 | }
533 |
534 | // IsType asserts that the specified objects are of the same type.
535 | func (a *Assertions) IsType(expectedType interface{}, object interface{}, msgAndArgs ...interface{}) bool {
536 | if h, ok := a.t.(tHelper); ok {
537 | h.Helper()
538 | }
539 | return IsType(a.t, expectedType, object, msgAndArgs...)
540 | }
541 |
542 | // IsTypef asserts that the specified objects are of the same type.
543 | func (a *Assertions) IsTypef(expectedType interface{}, object interface{}, msg string, args ...interface{}) bool {
544 | if h, ok := a.t.(tHelper); ok {
545 | h.Helper()
546 | }
547 | return IsTypef(a.t, expectedType, object, msg, args...)
548 | }
549 |
550 | // JSONEq asserts that two JSON strings are equivalent.
551 | //
552 | // a.JSONEq(`{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`)
553 | func (a *Assertions) JSONEq(expected string, actual string, msgAndArgs ...interface{}) bool {
554 | if h, ok := a.t.(tHelper); ok {
555 | h.Helper()
556 | }
557 | return JSONEq(a.t, expected, actual, msgAndArgs...)
558 | }
559 |
560 | // JSONEqf asserts that two JSON strings are equivalent.
561 | //
562 | // a.JSONEqf(`{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`, "error message %s", "formatted")
563 | func (a *Assertions) JSONEqf(expected string, actual string, msg string, args ...interface{}) bool {
564 | if h, ok := a.t.(tHelper); ok {
565 | h.Helper()
566 | }
567 | return JSONEqf(a.t, expected, actual, msg, args...)
568 | }
569 |
570 | // Len asserts that the specified object has specific length.
571 | // Len also fails if the object has a type that len() not accept.
572 | //
573 | // a.Len(mySlice, 3)
574 | func (a *Assertions) Len(object interface{}, length int, msgAndArgs ...interface{}) bool {
575 | if h, ok := a.t.(tHelper); ok {
576 | h.Helper()
577 | }
578 | return Len(a.t, object, length, msgAndArgs...)
579 | }
580 |
581 | // Lenf asserts that the specified object has specific length.
582 | // Lenf also fails if the object has a type that len() not accept.
583 | //
584 | // a.Lenf(mySlice, 3, "error message %s", "formatted")
585 | func (a *Assertions) Lenf(object interface{}, length int, msg string, args ...interface{}) bool {
586 | if h, ok := a.t.(tHelper); ok {
587 | h.Helper()
588 | }
589 | return Lenf(a.t, object, length, msg, args...)
590 | }
591 |
592 | // Nil asserts that the specified object is nil.
593 | //
594 | // a.Nil(err)
595 | func (a *Assertions) Nil(object interface{}, msgAndArgs ...interface{}) bool {
596 | if h, ok := a.t.(tHelper); ok {
597 | h.Helper()
598 | }
599 | return Nil(a.t, object, msgAndArgs...)
600 | }
601 |
602 | // Nilf asserts that the specified object is nil.
603 | //
604 | // a.Nilf(err, "error message %s", "formatted")
605 | func (a *Assertions) Nilf(object interface{}, msg string, args ...interface{}) bool {
606 | if h, ok := a.t.(tHelper); ok {
607 | h.Helper()
608 | }
609 | return Nilf(a.t, object, msg, args...)
610 | }
611 |
612 | // NoError asserts that a function returned no error (i.e. `nil`).
613 | //
614 | // actualObj, err := SomeFunction()
615 | // if a.NoError(err) {
616 | // assert.Equal(t, expectedObj, actualObj)
617 | // }
618 | func (a *Assertions) NoError(err error, msgAndArgs ...interface{}) bool {
619 | if h, ok := a.t.(tHelper); ok {
620 | h.Helper()
621 | }
622 | return NoError(a.t, err, msgAndArgs...)
623 | }
624 |
625 | // NoErrorf asserts that a function returned no error (i.e. `nil`).
626 | //
627 | // actualObj, err := SomeFunction()
628 | // if a.NoErrorf(err, "error message %s", "formatted") {
629 | // assert.Equal(t, expectedObj, actualObj)
630 | // }
631 | func (a *Assertions) NoErrorf(err error, msg string, args ...interface{}) bool {
632 | if h, ok := a.t.(tHelper); ok {
633 | h.Helper()
634 | }
635 | return NoErrorf(a.t, err, msg, args...)
636 | }
637 |
638 | // NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the
639 | // specified substring or element.
640 | //
641 | // a.NotContains("Hello World", "Earth")
642 | // a.NotContains(["Hello", "World"], "Earth")
643 | // a.NotContains({"Hello": "World"}, "Earth")
644 | func (a *Assertions) NotContains(s interface{}, contains interface{}, msgAndArgs ...interface{}) bool {
645 | if h, ok := a.t.(tHelper); ok {
646 | h.Helper()
647 | }
648 | return NotContains(a.t, s, contains, msgAndArgs...)
649 | }
650 |
651 | // NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the
652 | // specified substring or element.
653 | //
654 | // a.NotContainsf("Hello World", "Earth", "error message %s", "formatted")
655 | // a.NotContainsf(["Hello", "World"], "Earth", "error message %s", "formatted")
656 | // a.NotContainsf({"Hello": "World"}, "Earth", "error message %s", "formatted")
657 | func (a *Assertions) NotContainsf(s interface{}, contains interface{}, msg string, args ...interface{}) bool {
658 | if h, ok := a.t.(tHelper); ok {
659 | h.Helper()
660 | }
661 | return NotContainsf(a.t, s, contains, msg, args...)
662 | }
663 |
664 | // NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
665 | // a slice or a channel with len == 0.
666 | //
667 | // if a.NotEmpty(obj) {
668 | // assert.Equal(t, "two", obj[1])
669 | // }
670 | func (a *Assertions) NotEmpty(object interface{}, msgAndArgs ...interface{}) bool {
671 | if h, ok := a.t.(tHelper); ok {
672 | h.Helper()
673 | }
674 | return NotEmpty(a.t, object, msgAndArgs...)
675 | }
676 |
677 | // NotEmptyf asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either
678 | // a slice or a channel with len == 0.
679 | //
680 | // if a.NotEmptyf(obj, "error message %s", "formatted") {
681 | // assert.Equal(t, "two", obj[1])
682 | // }
683 | func (a *Assertions) NotEmptyf(object interface{}, msg string, args ...interface{}) bool {
684 | if h, ok := a.t.(tHelper); ok {
685 | h.Helper()
686 | }
687 | return NotEmptyf(a.t, object, msg, args...)
688 | }
689 |
690 | // NotEqual asserts that the specified values are NOT equal.
691 | //
692 | // a.NotEqual(obj1, obj2)
693 | //
694 | // Pointer variable equality is determined based on the equality of the
695 | // referenced values (as opposed to the memory addresses).
696 | func (a *Assertions) NotEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool {
697 | if h, ok := a.t.(tHelper); ok {
698 | h.Helper()
699 | }
700 | return NotEqual(a.t, expected, actual, msgAndArgs...)
701 | }
702 |
703 | // NotEqualf asserts that the specified values are NOT equal.
704 | //
705 | // a.NotEqualf(obj1, obj2, "error message %s", "formatted")
706 | //
707 | // Pointer variable equality is determined based on the equality of the
708 | // referenced values (as opposed to the memory addresses).
709 | func (a *Assertions) NotEqualf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool {
710 | if h, ok := a.t.(tHelper); ok {
711 | h.Helper()
712 | }
713 | return NotEqualf(a.t, expected, actual, msg, args...)
714 | }
715 |
716 | // NotNil asserts that the specified object is not nil.
717 | //
718 | // a.NotNil(err)
719 | func (a *Assertions) NotNil(object interface{}, msgAndArgs ...interface{}) bool {
720 | if h, ok := a.t.(tHelper); ok {
721 | h.Helper()
722 | }
723 | return NotNil(a.t, object, msgAndArgs...)
724 | }
725 |
726 | // NotNilf asserts that the specified object is not nil.
727 | //
728 | // a.NotNilf(err, "error message %s", "formatted")
729 | func (a *Assertions) NotNilf(object interface{}, msg string, args ...interface{}) bool {
730 | if h, ok := a.t.(tHelper); ok {
731 | h.Helper()
732 | }
733 | return NotNilf(a.t, object, msg, args...)
734 | }
735 |
736 | // NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.
737 | //
738 | // a.NotPanics(func(){ RemainCalm() })
739 | func (a *Assertions) NotPanics(f PanicTestFunc, msgAndArgs ...interface{}) bool {
740 | if h, ok := a.t.(tHelper); ok {
741 | h.Helper()
742 | }
743 | return NotPanics(a.t, f, msgAndArgs...)
744 | }
745 |
746 | // NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic.
747 | //
748 | // a.NotPanicsf(func(){ RemainCalm() }, "error message %s", "formatted")
749 | func (a *Assertions) NotPanicsf(f PanicTestFunc, msg string, args ...interface{}) bool {
750 | if h, ok := a.t.(tHelper); ok {
751 | h.Helper()
752 | }
753 | return NotPanicsf(a.t, f, msg, args...)
754 | }
755 |
756 | // NotRegexp asserts that a specified regexp does not match a string.
757 | //
758 | // a.NotRegexp(regexp.MustCompile("starts"), "it's starting")
759 | // a.NotRegexp("^start", "it's not starting")
760 | func (a *Assertions) NotRegexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool {
761 | if h, ok := a.t.(tHelper); ok {
762 | h.Helper()
763 | }
764 | return NotRegexp(a.t, rx, str, msgAndArgs...)
765 | }
766 |
767 | // NotRegexpf asserts that a specified regexp does not match a string.
768 | //
769 | // a.NotRegexpf(regexp.MustCompile("starts", "error message %s", "formatted"), "it's starting")
770 | // a.NotRegexpf("^start", "it's not starting", "error message %s", "formatted")
771 | func (a *Assertions) NotRegexpf(rx interface{}, str interface{}, msg string, args ...interface{}) bool {
772 | if h, ok := a.t.(tHelper); ok {
773 | h.Helper()
774 | }
775 | return NotRegexpf(a.t, rx, str, msg, args...)
776 | }
777 |
778 | // NotSubset asserts that the specified list(array, slice...) contains not all
779 | // elements given in the specified subset(array, slice...).
780 | //
781 | // a.NotSubset([1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]")
782 | func (a *Assertions) NotSubset(list interface{}, subset interface{}, msgAndArgs ...interface{}) bool {
783 | if h, ok := a.t.(tHelper); ok {
784 | h.Helper()
785 | }
786 | return NotSubset(a.t, list, subset, msgAndArgs...)
787 | }
788 |
789 | // NotSubsetf asserts that the specified list(array, slice...) contains not all
790 | // elements given in the specified subset(array, slice...).
791 | //
792 | // a.NotSubsetf([1, 3, 4], [1, 2], "But [1, 3, 4] does not contain [1, 2]", "error message %s", "formatted")
793 | func (a *Assertions) NotSubsetf(list interface{}, subset interface{}, msg string, args ...interface{}) bool {
794 | if h, ok := a.t.(tHelper); ok {
795 | h.Helper()
796 | }
797 | return NotSubsetf(a.t, list, subset, msg, args...)
798 | }
799 |
800 | // NotZero asserts that i is not the zero value for its type.
801 | func (a *Assertions) NotZero(i interface{}, msgAndArgs ...interface{}) bool {
802 | if h, ok := a.t.(tHelper); ok {
803 | h.Helper()
804 | }
805 | return NotZero(a.t, i, msgAndArgs...)
806 | }
807 |
808 | // NotZerof asserts that i is not the zero value for its type.
809 | func (a *Assertions) NotZerof(i interface{}, msg string, args ...interface{}) bool {
810 | if h, ok := a.t.(tHelper); ok {
811 | h.Helper()
812 | }
813 | return NotZerof(a.t, i, msg, args...)
814 | }
815 |
816 | // Panics asserts that the code inside the specified PanicTestFunc panics.
817 | //
818 | // a.Panics(func(){ GoCrazy() })
819 | func (a *Assertions) Panics(f PanicTestFunc, msgAndArgs ...interface{}) bool {
820 | if h, ok := a.t.(tHelper); ok {
821 | h.Helper()
822 | }
823 | return Panics(a.t, f, msgAndArgs...)
824 | }
825 |
826 | // PanicsWithValue asserts that the code inside the specified PanicTestFunc panics, and that
827 | // the recovered panic value equals the expected panic value.
828 | //
829 | // a.PanicsWithValue("crazy error", func(){ GoCrazy() })
830 | func (a *Assertions) PanicsWithValue(expected interface{}, f PanicTestFunc, msgAndArgs ...interface{}) bool {
831 | if h, ok := a.t.(tHelper); ok {
832 | h.Helper()
833 | }
834 | return PanicsWithValue(a.t, expected, f, msgAndArgs...)
835 | }
836 |
837 | // PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that
838 | // the recovered panic value equals the expected panic value.
839 | //
840 | // a.PanicsWithValuef("crazy error", func(){ GoCrazy() }, "error message %s", "formatted")
841 | func (a *Assertions) PanicsWithValuef(expected interface{}, f PanicTestFunc, msg string, args ...interface{}) bool {
842 | if h, ok := a.t.(tHelper); ok {
843 | h.Helper()
844 | }
845 | return PanicsWithValuef(a.t, expected, f, msg, args...)
846 | }
847 |
848 | // Panicsf asserts that the code inside the specified PanicTestFunc panics.
849 | //
850 | // a.Panicsf(func(){ GoCrazy() }, "error message %s", "formatted")
851 | func (a *Assertions) Panicsf(f PanicTestFunc, msg string, args ...interface{}) bool {
852 | if h, ok := a.t.(tHelper); ok {
853 | h.Helper()
854 | }
855 | return Panicsf(a.t, f, msg, args...)
856 | }
857 |
858 | // Regexp asserts that a specified regexp matches a string.
859 | //
860 | // a.Regexp(regexp.MustCompile("start"), "it's starting")
861 | // a.Regexp("start...$", "it's not starting")
862 | func (a *Assertions) Regexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool {
863 | if h, ok := a.t.(tHelper); ok {
864 | h.Helper()
865 | }
866 | return Regexp(a.t, rx, str, msgAndArgs...)
867 | }
868 |
869 | // Regexpf asserts that a specified regexp matches a string.
870 | //
871 | // a.Regexpf(regexp.MustCompile("start", "error message %s", "formatted"), "it's starting")
872 | // a.Regexpf("start...$", "it's not starting", "error message %s", "formatted")
873 | func (a *Assertions) Regexpf(rx interface{}, str interface{}, msg string, args ...interface{}) bool {
874 | if h, ok := a.t.(tHelper); ok {
875 | h.Helper()
876 | }
877 | return Regexpf(a.t, rx, str, msg, args...)
878 | }
879 |
880 | // Subset asserts that the specified list(array, slice...) contains all
881 | // elements given in the specified subset(array, slice...).
882 | //
883 | // a.Subset([1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]")
884 | func (a *Assertions) Subset(list interface{}, subset interface{}, msgAndArgs ...interface{}) bool {
885 | if h, ok := a.t.(tHelper); ok {
886 | h.Helper()
887 | }
888 | return Subset(a.t, list, subset, msgAndArgs...)
889 | }
890 |
891 | // Subsetf asserts that the specified list(array, slice...) contains all
892 | // elements given in the specified subset(array, slice...).
893 | //
894 | // a.Subsetf([1, 2, 3], [1, 2], "But [1, 2, 3] does contain [1, 2]", "error message %s", "formatted")
895 | func (a *Assertions) Subsetf(list interface{}, subset interface{}, msg string, args ...interface{}) bool {
896 | if h, ok := a.t.(tHelper); ok {
897 | h.Helper()
898 | }
899 | return Subsetf(a.t, list, subset, msg, args...)
900 | }
901 |
902 | // True asserts that the specified value is true.
903 | //
904 | // a.True(myBool)
905 | func (a *Assertions) True(value bool, msgAndArgs ...interface{}) bool {
906 | if h, ok := a.t.(tHelper); ok {
907 | h.Helper()
908 | }
909 | return True(a.t, value, msgAndArgs...)
910 | }
911 |
912 | // Truef asserts that the specified value is true.
913 | //
914 | // a.Truef(myBool, "error message %s", "formatted")
915 | func (a *Assertions) Truef(value bool, msg string, args ...interface{}) bool {
916 | if h, ok := a.t.(tHelper); ok {
917 | h.Helper()
918 | }
919 | return Truef(a.t, value, msg, args...)
920 | }
921 |
922 | // WithinDuration asserts that the two times are within duration delta of each other.
923 | //
924 | // a.WithinDuration(time.Now(), time.Now(), 10*time.Second)
925 | func (a *Assertions) WithinDuration(expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) bool {
926 | if h, ok := a.t.(tHelper); ok {
927 | h.Helper()
928 | }
929 | return WithinDuration(a.t, expected, actual, delta, msgAndArgs...)
930 | }
931 |
932 | // WithinDurationf asserts that the two times are within duration delta of each other.
933 | //
934 | // a.WithinDurationf(time.Now(), time.Now(), 10*time.Second, "error message %s", "formatted")
935 | func (a *Assertions) WithinDurationf(expected time.Time, actual time.Time, delta time.Duration, msg string, args ...interface{}) bool {
936 | if h, ok := a.t.(tHelper); ok {
937 | h.Helper()
938 | }
939 | return WithinDurationf(a.t, expected, actual, delta, msg, args...)
940 | }
941 |
942 | // Zero asserts that i is the zero value for its type.
943 | func (a *Assertions) Zero(i interface{}, msgAndArgs ...interface{}) bool {
944 | if h, ok := a.t.(tHelper); ok {
945 | h.Helper()
946 | }
947 | return Zero(a.t, i, msgAndArgs...)
948 | }
949 |
950 | // Zerof asserts that i is the zero value for its type.
951 | func (a *Assertions) Zerof(i interface{}, msg string, args ...interface{}) bool {
952 | if h, ok := a.t.(tHelper); ok {
953 | h.Helper()
954 | }
955 | return Zerof(a.t, i, msg, args...)
956 | }
957 |
--------------------------------------------------------------------------------
/vendor/github.com/stretchr/testify/assert/assertion_forward.go.tmpl:
--------------------------------------------------------------------------------
1 | {{.CommentWithoutT "a"}}
2 | func (a *Assertions) {{.DocInfo.Name}}({{.Params}}) bool {
3 | if h, ok := a.t.(tHelper); ok { h.Helper() }
4 | return {{.DocInfo.Name}}(a.t, {{.ForwardedParams}})
5 | }
6 |
--------------------------------------------------------------------------------
/vendor/github.com/stretchr/testify/assert/doc.go:
--------------------------------------------------------------------------------
1 | // Package assert provides a set of comprehensive testing tools for use with the normal Go testing system.
2 | //
3 | // Example Usage
4 | //
5 | // The following is a complete example using assert in a standard test function:
6 | // import (
7 | // "testing"
8 | // "github.com/stretchr/testify/assert"
9 | // )
10 | //
11 | // func TestSomething(t *testing.T) {
12 | //
13 | // var a string = "Hello"
14 | // var b string = "Hello"
15 | //
16 | // assert.Equal(t, a, b, "The two words should be the same.")
17 | //
18 | // }
19 | //
20 | // if you assert many times, use the format below:
21 | //
22 | // import (
23 | // "testing"
24 | // "github.com/stretchr/testify/assert"
25 | // )
26 | //
27 | // func TestSomething(t *testing.T) {
28 | // assert := assert.New(t)
29 | //
30 | // var a string = "Hello"
31 | // var b string = "Hello"
32 | //
33 | // assert.Equal(a, b, "The two words should be the same.")
34 | // }
35 | //
36 | // Assertions
37 | //
38 | // Assertions allow you to easily write test code, and are global funcs in the `assert` package.
39 | // All assertion functions take, as the first argument, the `*testing.T` object provided by the
40 | // testing framework. This allows the assertion funcs to write the failings and other details to
41 | // the correct place.
42 | //
43 | // Every assertion function also takes an optional string message as the final argument,
44 | // allowing custom error messages to be appended to the message the assertion method outputs.
45 | package assert
46 |
--------------------------------------------------------------------------------
/vendor/github.com/stretchr/testify/assert/errors.go:
--------------------------------------------------------------------------------
1 | package assert
2 |
3 | import (
4 | "errors"
5 | )
6 |
7 | // AnError is an error instance useful for testing. If the code does not care
8 | // about error specifics, and only needs to return the error for example, this
9 | // error should be used to make the test code more readable.
10 | var AnError = errors.New("assert.AnError general error for testing")
11 |
--------------------------------------------------------------------------------
/vendor/github.com/stretchr/testify/assert/forward_assertions.go:
--------------------------------------------------------------------------------
1 | package assert
2 |
3 | // Assertions provides assertion methods around the
4 | // TestingT interface.
5 | type Assertions struct {
6 | t TestingT
7 | }
8 |
9 | // New makes a new Assertions object for the specified TestingT.
10 | func New(t TestingT) *Assertions {
11 | return &Assertions{
12 | t: t,
13 | }
14 | }
15 |
16 | //go:generate go run ../_codegen/main.go -output-package=assert -template=assertion_forward.go.tmpl -include-format-funcs
17 |
--------------------------------------------------------------------------------
/vendor/github.com/stretchr/testify/assert/http_assertions.go:
--------------------------------------------------------------------------------
1 | package assert
2 |
3 | import (
4 | "fmt"
5 | "net/http"
6 | "net/http/httptest"
7 | "net/url"
8 | "strings"
9 | )
10 |
11 | // httpCode is a helper that returns HTTP code of the response. It returns -1 and
12 | // an error if building a new request fails.
13 | func httpCode(handler http.HandlerFunc, method, url string, values url.Values) (int, error) {
14 | w := httptest.NewRecorder()
15 | req, err := http.NewRequest(method, url, nil)
16 | if err != nil {
17 | return -1, err
18 | }
19 | req.URL.RawQuery = values.Encode()
20 | handler(w, req)
21 | return w.Code, nil
22 | }
23 |
24 | // HTTPSuccess asserts that a specified handler returns a success status code.
25 | //
26 | // assert.HTTPSuccess(t, myHandler, "POST", "http://www.google.com", nil)
27 | //
28 | // Returns whether the assertion was successful (true) or not (false).
29 | func HTTPSuccess(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, msgAndArgs ...interface{}) bool {
30 | if h, ok := t.(tHelper); ok {
31 | h.Helper()
32 | }
33 | code, err := httpCode(handler, method, url, values)
34 | if err != nil {
35 | Fail(t, fmt.Sprintf("Failed to build test request, got error: %s", err))
36 | return false
37 | }
38 |
39 | isSuccessCode := code >= http.StatusOK && code <= http.StatusPartialContent
40 | if !isSuccessCode {
41 | Fail(t, fmt.Sprintf("Expected HTTP success status code for %q but received %d", url+"?"+values.Encode(), code))
42 | }
43 |
44 | return isSuccessCode
45 | }
46 |
47 | // HTTPRedirect asserts that a specified handler returns a redirect status code.
48 | //
49 | // assert.HTTPRedirect(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
50 | //
51 | // Returns whether the assertion was successful (true) or not (false).
52 | func HTTPRedirect(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, msgAndArgs ...interface{}) bool {
53 | if h, ok := t.(tHelper); ok {
54 | h.Helper()
55 | }
56 | code, err := httpCode(handler, method, url, values)
57 | if err != nil {
58 | Fail(t, fmt.Sprintf("Failed to build test request, got error: %s", err))
59 | return false
60 | }
61 |
62 | isRedirectCode := code >= http.StatusMultipleChoices && code <= http.StatusTemporaryRedirect
63 | if !isRedirectCode {
64 | Fail(t, fmt.Sprintf("Expected HTTP redirect status code for %q but received %d", url+"?"+values.Encode(), code))
65 | }
66 |
67 | return isRedirectCode
68 | }
69 |
70 | // HTTPError asserts that a specified handler returns an error status code.
71 | //
72 | // assert.HTTPError(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
73 | //
74 | // Returns whether the assertion was successful (true) or not (false).
75 | func HTTPError(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, msgAndArgs ...interface{}) bool {
76 | if h, ok := t.(tHelper); ok {
77 | h.Helper()
78 | }
79 | code, err := httpCode(handler, method, url, values)
80 | if err != nil {
81 | Fail(t, fmt.Sprintf("Failed to build test request, got error: %s", err))
82 | return false
83 | }
84 |
85 | isErrorCode := code >= http.StatusBadRequest
86 | if !isErrorCode {
87 | Fail(t, fmt.Sprintf("Expected HTTP error status code for %q but received %d", url+"?"+values.Encode(), code))
88 | }
89 |
90 | return isErrorCode
91 | }
92 |
93 | // HTTPBody is a helper that returns HTTP body of the response. It returns
94 | // empty string if building a new request fails.
95 | func HTTPBody(handler http.HandlerFunc, method, url string, values url.Values) string {
96 | w := httptest.NewRecorder()
97 | req, err := http.NewRequest(method, url+"?"+values.Encode(), nil)
98 | if err != nil {
99 | return ""
100 | }
101 | handler(w, req)
102 | return w.Body.String()
103 | }
104 |
105 | // HTTPBodyContains asserts that a specified handler returns a
106 | // body that contains a string.
107 | //
108 | // assert.HTTPBodyContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky")
109 | //
110 | // Returns whether the assertion was successful (true) or not (false).
111 | func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) bool {
112 | if h, ok := t.(tHelper); ok {
113 | h.Helper()
114 | }
115 | body := HTTPBody(handler, method, url, values)
116 |
117 | contains := strings.Contains(body, fmt.Sprint(str))
118 | if !contains {
119 | Fail(t, fmt.Sprintf("Expected response body for \"%s\" to contain \"%s\" but found \"%s\"", url+"?"+values.Encode(), str, body))
120 | }
121 |
122 | return contains
123 | }
124 |
125 | // HTTPBodyNotContains asserts that a specified handler returns a
126 | // body that does not contain a string.
127 | //
128 | // assert.HTTPBodyNotContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky")
129 | //
130 | // Returns whether the assertion was successful (true) or not (false).
131 | func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) bool {
132 | if h, ok := t.(tHelper); ok {
133 | h.Helper()
134 | }
135 | body := HTTPBody(handler, method, url, values)
136 |
137 | contains := strings.Contains(body, fmt.Sprint(str))
138 | if contains {
139 | Fail(t, fmt.Sprintf("Expected response body for \"%s\" to NOT contain \"%s\" but found \"%s\"", url+"?"+values.Encode(), str, body))
140 | }
141 |
142 | return !contains
143 | }
144 |
--------------------------------------------------------------------------------
/vendor/modules.txt:
--------------------------------------------------------------------------------
1 | # github.com/davecgh/go-spew v1.1.0
2 | github.com/davecgh/go-spew/spew
3 | # github.com/pmezard/go-difflib v1.0.0
4 | github.com/pmezard/go-difflib/difflib
5 | # github.com/stretchr/testify v1.3.0
6 | github.com/stretchr/testify/assert
7 |
--------------------------------------------------------------------------------