Skip to content

Commit

Permalink
adding IsNil method to uuid (#95)
Browse files Browse the repository at this point in the history
* adding IsZero method to uuid

* rename isZero to IsNil
  • Loading branch information
jordan-chalupka committed Nov 26, 2021
1 parent 6fe74ff commit 0c84a43
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions uuid.go
Expand Up @@ -151,6 +151,11 @@ var (
NamespaceX500 = Must(FromString("6ba7b814-9dad-11d1-80b4-00c04fd430c8"))
)

// IsNil returns if the UUID is equal to the nil UUID
func (u UUID) IsNil() bool {
return u == Nil
}

// Version returns the algorithm version used to generate the UUID.
func (u UUID) Version() byte {
return u[6] >> 4
Expand Down
10 changes: 10 additions & 0 deletions uuid_test.go
Expand Up @@ -29,6 +29,7 @@ import (
)

func TestUUID(t *testing.T) {
t.Run("IsNil", testUUIDIsNil)
t.Run("Bytes", testUUIDBytes)
t.Run("String", testUUIDString)
t.Run("Version", testUUIDVersion)
Expand All @@ -38,6 +39,15 @@ func TestUUID(t *testing.T) {
t.Run("Format", testUUIDFormat)
}

func testUUIDIsNil(t *testing.T) {
u := UUID{}
got := u.IsNil()
want := true
if got != want {
t.Errorf("%v.IsNil() = %t, want %t", u, got, want)
}
}

func testUUIDBytes(t *testing.T) {
got := codecTestUUID.Bytes()
want := codecTestData
Expand Down

0 comments on commit 0c84a43

Please sign in to comment.