-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhamcrest_contains_test.go
More file actions
54 lines (51 loc) · 1.31 KB
/
hamcrest_contains_test.go
File metadata and controls
54 lines (51 loc) · 1.31 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
package assert
import "testing"
func TestContains(t *testing.T) {
{
err := AssertThat("hello world", Contains("hello"))
if err != nil {
t.Fatal("expect nil")
}
}
{
err := AssertThat("hello world", Contains("world"))
if err != nil {
t.Fatal("expect nil")
}
}
{
err := AssertThat("hello world", Contains("foo bar"))
if err == nil {
t.Fatal("expect error")
}
}
{
err := AssertThat("hello world", Contains("foo bar"))
expectedValue := "expected <hello world> contains <foo bar>"
if err.Error() != expectedValue {
t.Fatalf("error message missmatch, expected '%v' but was '%v'", expectedValue, err.Error())
}
}
{
err := AssertThat("hello world", Contains("foo bar").Message("msg"))
expectedValue := "msg, expected <hello world> contains <foo bar>"
if err.Error() != expectedValue {
t.Fatalf("error message missmatch, expected '%v' but was '%v'", expectedValue, err.Error())
}
}
}
func TestContainsTypeMissmatch(t *testing.T) {
{
err := AssertThat([]byte{}, Contains("world"))
if err == nil {
t.Fatal("expect error")
}
}
{
err := AssertThat([]byte{}, Contains("world"))
expectedValue := "expected type string but got []uint8"
if err.Error() != expectedValue {
t.Fatalf("error message missmatch, expected '%v' but was '%v'", expectedValue, err.Error())
}
}
}