Class: GuidTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/guid.rb

Instance Method Summary collapse

Instance Method Details

#test_from_rawObject



155
156
157
158
159
# File 'lib/guid.rb', line 155

def test_from_raw
  g = Guid.new
  g2 = Guid.from_raw(g.raw)
  assert_equal(g, g2)
end

#test_from_sObject



149
150
151
152
153
# File 'lib/guid.rb', line 149

def test_from_s
  g = Guid.new
  g2 = Guid.from_s(g.to_s)
  assert_equal(g, g2)
end

#test_newObject



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/guid.rb', line 131

def test_new
  g = Guid.new
  
  # different representations of guid: hexdigest, hex+dashes, raw bytes
  assert_equal(0, g.to_s =~ /\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/)
  assert_equal(16, g.raw.length)
  assert_equal(0, g.hexdigest =~ /\A[0-9a-f]{32}\z/)
  assert_equal(g.hexdigest, g.to_s.gsub(/-/, ''))

  # must be different each time we produce (this is just a simple test)
  g2 = Guid.new
  assert_equal(true, g != g2)
  assert_equal(true, g.to_s != g2.to_s)
  assert_equal(true, g.raw != g2.raw)
  assert_equal(true, g.hexdigest != g2.hexdigest)
  assert_equal(1000, (1..1000).select { |i| g != Guid.new }.length)
end