Changed ObjectID#legal_oid_string to ObjectID#legal?

This commit is contained in:
Jim Menard 2009-02-09 11:38:24 -05:00
parent f82925e4a1
commit 5c2ef0176e
2 changed files with 10 additions and 10 deletions

View File

@ -64,7 +64,7 @@ module XGen
# Given a string representation of an ObjectID, return a new ObjectID
# with that value.
def self.from_string(str)
raise "illegal ObjectID format" unless legal_oid_string(str)
raise "illegal ObjectID format" unless legal?(str)
data = []
BYTE_ORDER.each_with_index { |string_position, data_index|
data[data_index] = str[string_position * 2, 2].to_i(16)
@ -72,7 +72,7 @@ module XGen
self.new(data)
end
def self.legal_oid_string(str)
def self.legal?(str)
len = BYTE_ORDER.length * 2
str =~ /([0-9a-f]+)/i
match = $1

View File

@ -73,14 +73,14 @@ class ObjectIDTest < Test::Unit::TestCase
assert_equal @o.to_s, o2.to_s
end
def test_legal_oid_string
assert !ObjectID.legal_oid_string(nil)
assert !ObjectID.legal_oid_string("fred")
assert !ObjectID.legal_oid_string("0000")
assert !ObjectID.legal_oid_string('000102030405060708090A0')
assert ObjectID.legal_oid_string('000102030405060708090A0B')
assert ObjectID.legal_oid_string('abcdefABCDEF123456789012')
assert !ObjectID.legal_oid_string('abcdefABCDEF12345678901x')
def test_legal
assert !ObjectID.legal?(nil)
assert !ObjectID.legal?("fred")
assert !ObjectID.legal?("0000")
assert !ObjectID.legal?('000102030405060708090A0')
assert ObjectID.legal?('000102030405060708090A0B')
assert ObjectID.legal?('abcdefABCDEF123456789012')
assert !ObjectID.legal?('abcdefABCDEF12345678901x')
end
def test_from_string_leading_zeroes