diff --git a/spec/ulid_spec.cr b/spec/ulid_spec.cr index c98f754..35cde98 100644 --- a/spec/ulid_spec.cr +++ b/spec/ulid_spec.cr @@ -71,6 +71,16 @@ describe Ulid::ULID do ulid.inspect.should eq "#" end + it "should have the same hash for the same bytes" do + bytes = array_slice [ + 101, 102, 103, 104, 105, 106, + 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, + ] of UInt8 + ulid1 = Ulid::ULID.new("CNK6ET39D9NPRVBEDXR72WKKEG") + ulid2 = Ulid::ULID.new("CNK6ET39D9NPRVBEDXR72WKKEG") + ulid1.hash.should eq ulid2.hash + end + it "should instantiate from a string" do ulid = Ulid::ULID.new "CNK6ET39D9NPRVBEDXR72WKKEG" ulid.to_s.should eq "CNK6ET39D9NPRVBEDXR72WKKEG" diff --git a/src/ulid.cr b/src/ulid.cr index cf6bcc4..733d740 100644 --- a/src/ulid.cr +++ b/src/ulid.cr @@ -10,6 +10,8 @@ module Ulid BYTE_COUNT = 16 + def_hash @bytes + getter bytes : Bytes def initialize(bytes : Bytes)