| 1 |
package assert |
| 2 |
|
| 3 |
import "testing" |
| 4 |
|
| 5 |
const equalError string = "%s: expected %v but got %v" |
| 6 |
|
| 7 |
type Assertion func() bool |
| 8 |
|
| 9 |
func StringEqual(name string, expected, current string, t *testing.T) { |
| 10 |
if current != expected { |
| 11 |
t.Fatalf(equalError, name, expected, current) |
| 12 |
} |
| 13 |
} |
| 14 |
|
| 15 |
func IntEqual(name string, expected, current int, t *testing.T) { |
| 16 |
if current != expected { |
| 17 |
t.Fatalf(equalError, name, expected, current) |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
func ByteEqual(name string, expected, current byte, t *testing.T) { |
| 22 |
if current != expected { |
| 23 |
t.Fatalf(equalError, name, expected, current) |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
func Int32Equal(name string, expected, current int32, t *testing.T) { |
| 28 |
if current != expected { |
| 29 |
t.Fatalf(equalError, name, expected, current) |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
func Int64Equal(name string, expected, current int64, t *testing.T) { |
| 34 |
if current != expected { |
| 35 |
t.Fatalf(equalError, name, expected, current) |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
func Float32Equal(name string, expected, current float32, t *testing.T) { |
| 40 |
if current != expected { |
| 41 |
t.Fatalf(equalError, name, expected, current) |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
func Float64Equal(name string, expected, current float64, t *testing.T) { |
| 46 |
if current != expected { |
| 47 |
t.Fatalf(equalError, name, expected, current) |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
func Complex64Equal(name string, expected, current complex64, t *testing.T) { |
| 52 |
if current != expected { |
| 53 |
t.Fatalf(equalError, name, expected, current) |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
func Complex128Equal(name string, expected, current complex128, t *testing.T) { |
| 58 |
if current != expected { |
| 59 |
t.Fatalf(equalError, name, expected, current) |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
func True(name string, current bool, t *testing.T) { |
| 64 |
if !current { |
| 65 |
t.Fatalf(equalError, name, true, false) |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
func False(name string, current bool, t *testing.T) { |
| 70 |
if current { |
| 71 |
t.Fatalf(equalError, name, false, true) |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
func That(name, text string, assertion Assertion, t *testing.T) { |
| 76 |
if !assertion() { |
| 77 |
t.Fatalf("%s: %s", name, text) |
| 78 |
} |
| 79 |
} |