Skip to content

Commit eb9b4b3

Browse files
committed
doc: update readme and function descriptions.
1 parent cac3341 commit eb9b4b3

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ go get -u github.com/ghosind/go-assert
1818

1919
## Getting Started
2020

21-
This library provided assertion functions to verify the equality of values:
21+
This library provided assertion functions to verify the equality of values, or assert for nil:
2222

2323
```go
2424
func TestExample(t *testing.T) {
@@ -27,6 +27,12 @@ func TestExample(t *testing.T) {
2727

2828
// assert inequality
2929
assert.NotDeepEqual(t, actual, expect)
30+
31+
// assert for nil
32+
assert.Nil(t, object)
33+
34+
// assert for not nil
35+
assert.NotNil(t, object)
3036
}
3137
```
3238

assertion.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ type Assertion struct {
99
t *testing.T
1010
}
1111

12-
// #########################
13-
// ## Assertion Functions ##
14-
// #########################
15-
1612
// New returns an assertion instance for verifying invariants.
1713
func New(t *testing.T) *Assertion {
1814
a := new(Assertion)
@@ -25,6 +21,10 @@ func New(t *testing.T) *Assertion {
2521
return a
2622
}
2723

24+
// #########################
25+
// ## Assertion Functions ##
26+
// #########################
27+
2828
// DeepEqual tests deeply equality between actual and expect parameters.
2929
func (a *Assertion) DeepEqual(actual, expect any, message ...string) error {
3030
return DeepEqual(a.t, actual, expect, message...)
@@ -35,12 +35,16 @@ func (a *Assertion) NotDeepEqual(actual, expect any, message ...string) error {
3535
return NotDeepEqual(a.t, actual, expect, message...)
3636
}
3737

38-
// Nil tests a value is nil or not, and it'll failed when the value is not nil.
38+
// Nil tests whether a value is nil or not, and it'll fail when the value is not nil. It will
39+
// always return false if the value is a bool, an integer, a floating number, a complex, or a
40+
// string.
3941
func (a *Assertion) Nil(val any, message ...string) error {
4042
return Nil(a.t, val, message...)
4143
}
4244

43-
// NotNil tests a value is nil or not, and it'll failed when the value is nil.
45+
// NotNil tests whether a value is nil or not, and it'll fail when the value is nil. It will
46+
// always return true if the value is a bool, an integer, a floating number, a complex, or a
47+
// string.
4448
func (a *Assertion) NotNil(val any, message ...string) error {
4549
return NotNil(a.t, val, message...)
4650
}

equal.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ func NotDeepEqual(t *testing.T, actual, expect any, message ...string) error {
3232
return err
3333
}
3434

35-
// Nil tests a value is nil or not, and it'll failed when the value is not nil.
35+
// Nil tests whether a value is nil or not, and it'll fail when the value is not nil. It will
36+
// always return false if the value is a bool, an integer, a floating number, a complex, or a
37+
// string.
3638
func Nil(t *testing.T, val any, message ...string) error {
3739
if isNil(val) {
3840
return nil
@@ -45,7 +47,9 @@ func Nil(t *testing.T, val any, message ...string) error {
4547
return err
4648
}
4749

48-
// NotNil tests a value is nil or not, and it'll failed when the value is nil.
50+
// NotNil tests whether a value is nil or not, and it'll fail when the value is nil. It will
51+
// always return true if the value is a bool, an integer, a floating number, a complex, or a
52+
// string.
4953
func NotNil(t *testing.T, val any, message ...string) error {
5054
if !isNil(val) {
5155
return nil

0 commit comments

Comments
 (0)