Repository navigation
Expand file tree
/
Copy pathbe_example_test.go
More file actions
63 lines (52 loc) · 1.69 KB
/
Copy pathbe_example_test.go
File metadata and controls
63 lines (52 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package be_test
import (
"errors"
"os"
"strings"
"github.com/carlmjohnson/be"
)
func Example() {
// mock *testing.T for example purposes
t := be.Relaxed(&mockingT{})
be.Equal(t, "hello", "world") // bad
be.Equal(t, "goodbye", "goodbye") // good
be.Unequal(t, "hello", "world") // good
be.Unequal(t, "goodbye", "goodbye") // bad
s := []int{1, 2, 3}
be.AllEqual(t, []int{1, 2, 3}, s) // good
be.AllEqual(t, []int{3, 2, 1}, s) // bad
var err error
be.Zero(t, err) // good
be.ErrorIs(t, nil, err) // good
be.Nonzero(t, err) // bad
be.ErrorIs(t, os.ErrPermission, err) // bad
err = errors.New("(O_o)")
var asErr *os.PathError
be.ErrorAs(t, &asErr, err) // bad
be.Nonzero(t, err) // good
type mytype string
var mystring mytype = "hello, world"
be.Match(t, `world`, mystring) // good
be.Match(t, `World`, mystring) // bad
be.Match(t, `^\W*$`, []byte("\a\b\x00\r\t")) // good
be.NoMatch(t, `^\W*$`, []byte("\a\b\x00\r\t")) // bad
seq := strings.FieldsSeq("1 2 3 4")
be.EqualLength(t, 4, seq) // good
be.EqualLength(t, 1, seq) // bad
be.AtLeastLength(t, 1, seq) // good
be.AtLeastLength(t, 5, seq) // bad
be.AtLeastLength(t, 3, "123") // good
be.AtLeastLength(t, 4, "123") // bad
// Output:
// want: hello; got: world
// got: goodbye
// want: [3 2 1]; got: [1 2 3]
// got: <nil>
// got errors.Is(<nil>, permission denied) == false
// got errors.As((O_o), **fs.PathError) == false
// missing match: /World/ !~ "hello, world"
// unexpected match: /^\W*$/ =~ "\a\b\x00\r\t"
// want len(seq) == 1; got at least 2
// want len(seq) >= 5; got 4
// want len(seq) >= 4; got 3
}