Debian Codegraph @

comment.go

raw
1 // Licensed under the MIT license, see LICENSE file for details.
2
3 package quicktest
4
5 import "fmt"
6
7 // Commentf returns a test comment whose output is formatted according to
8 // the given format specifier and args. It may be provided as the last argument
9 // to any check or assertion and will be displayed if the check or assertion
10 // fails. For instance:
11 //
12 // c.Assert(a, qt.Equals, 42, qt.Commentf("answer is not %d", 42))
13 func Commentf(format string, args ...interface{}) Comment {
14 return Comment{
15 format: format,
16 args: args,
17 }
18 }
19
20 // Comment represents additional information on a check or an assertion which is
21 // displayed when the check or assertion fails.
22 type Comment struct {
23 format string
24 args []interface{}
25 }
26
27 // String outputs a string formatted according to the stored format specifier
28 // and args.
29 func (c Comment) String() string {
30 return fmt.Sprintf(c.format, c.args...)
31 }