Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding IsNil method to uuid #95

Merged
merged 2 commits into from Nov 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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