uuidtools 1.0.7 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/Rakefile +0 -1
- data/lib/uuidtools.rb +480 -479
- data/lib/uuidtools/version.rb +2 -2
- data/spec/uuidtools/mac_address_spec.rb +3 -3
- data/spec/uuidtools/uuid_creation_spec.rb +31 -30
- data/spec/uuidtools/uuid_parsing_spec.rb +35 -34
- metadata +2 -2
data/lib/uuidtools/version.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), "../spec_helper.rb")
|
2
2
|
|
3
|
-
describe UUID, "when obtaining a MAC address" do
|
3
|
+
describe UUIDTools::UUID, "when obtaining a MAC address" do
|
4
4
|
before do
|
5
|
-
@mac_address = UUID.mac_address
|
5
|
+
@mac_address = UUIDTools::UUID.mac_address
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should obtain a MAC address" do
|
@@ -10,6 +10,6 @@ describe UUID, "when obtaining a MAC address" do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should cache the MAC address" do
|
13
|
-
@mac_address.object_id.should == UUID.mac_address.object_id
|
13
|
+
@mac_address.object_id.should == UUIDTools::UUID.mac_address.object_id
|
14
14
|
end
|
15
15
|
end
|
@@ -1,43 +1,44 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), "../spec_helper.rb")
|
2
2
|
|
3
|
-
describe UUID, "when generating" do
|
3
|
+
describe UUIDTools::UUID, "when generating" do
|
4
4
|
it "should correctly generate SHA1 variant UUIDs" do
|
5
|
-
UUID.sha1_create(
|
6
|
-
UUID_URL_NAMESPACE, 'http://sporkmonger.com'
|
5
|
+
UUIDTools::UUID.sha1_create(
|
6
|
+
UUIDTools::UUID_URL_NAMESPACE, 'http://sporkmonger.com'
|
7
7
|
).to_s.should == "f2d04685-b787-55da-8644-9bd28a6f5a53"
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should correctly generate MD5 variant UUIDs" do
|
11
|
-
UUID.md5_create(
|
12
|
-
UUID_URL_NAMESPACE, 'http://sporkmonger.com'
|
11
|
+
UUIDTools::UUID.md5_create(
|
12
|
+
UUIDTools::UUID_URL_NAMESPACE, 'http://sporkmonger.com'
|
13
13
|
).to_s.should == "15074785-9071-3fe3-89bd-876e4b9e919b"
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should correctly generate timestamp variant UUIDs" do
|
17
|
-
UUID.timestamp_create.should_not be_random_node_id
|
18
|
-
UUID.timestamp_create.to_s.should_not ==
|
17
|
+
UUIDTools::UUID.timestamp_create.should_not be_random_node_id
|
18
|
+
UUIDTools::UUID.timestamp_create.to_s.should_not ==
|
19
|
+
UUIDTools::UUID.timestamp_create.to_s
|
19
20
|
current_time = Time.now
|
20
|
-
UUID.timestamp_create(current_time).to_s.should_not ==
|
21
|
-
UUID.timestamp_create(current_time).to_s
|
21
|
+
UUIDTools::UUID.timestamp_create(current_time).to_s.should_not ==
|
22
|
+
UUIDTools::UUID.timestamp_create(current_time).to_s
|
22
23
|
uuids = []
|
23
24
|
1000.times do
|
24
|
-
uuids << UUID.timestamp_create
|
25
|
+
uuids << UUIDTools::UUID.timestamp_create
|
25
26
|
end
|
26
27
|
# Check to make sure that none of the 1,000 UUIDs were duplicates
|
27
28
|
(uuids.map {|x| x.to_s}).uniq.size.should == uuids.size
|
28
29
|
end
|
29
30
|
|
30
31
|
it "should correctly generate UUIDs without a MAC address" do
|
31
|
-
mac_address = UUID.mac_address
|
32
|
-
UUID.mac_address = nil
|
33
|
-
UUID.timestamp_create.should be_random_node_id
|
34
|
-
UUID.mac_address = mac_address
|
32
|
+
mac_address = UUIDTools::UUID.mac_address
|
33
|
+
UUIDTools::UUID.mac_address = nil
|
34
|
+
UUIDTools::UUID.timestamp_create.should be_random_node_id
|
35
|
+
UUIDTools::UUID.mac_address = mac_address
|
35
36
|
end
|
36
37
|
|
37
38
|
it "should correctly generate random number variant UUIDs" do
|
38
39
|
uuids = []
|
39
40
|
1000.times do
|
40
|
-
uuids << UUID.random_create
|
41
|
+
uuids << UUIDTools::UUID.random_create
|
41
42
|
end
|
42
43
|
# Check to make sure that none of the 1,000 UUIDs were duplicates
|
43
44
|
(uuids.map {|x| x.to_s}).uniq.size.should == uuids.size
|
@@ -45,76 +46,76 @@ describe UUID, "when generating" do
|
|
45
46
|
|
46
47
|
it "should throw an exception if a segment has an invalid value" do
|
47
48
|
(lambda do
|
48
|
-
UUID.new(-1, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0])
|
49
|
+
UUIDTools::UUID.new(-1, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0])
|
49
50
|
end).should raise_error(ArgumentError)
|
50
51
|
(lambda do
|
51
|
-
UUID.new(4294967296, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0])
|
52
|
+
UUIDTools::UUID.new(4294967296, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0])
|
52
53
|
end).should raise_error(ArgumentError)
|
53
54
|
end
|
54
55
|
|
55
56
|
it "should throw an exception if a segment has an invalid value" do
|
56
57
|
(lambda do
|
57
|
-
UUID.new(0, -1, 0, 0, 0, [0, 0, 0, 0, 0, 0])
|
58
|
+
UUIDTools::UUID.new(0, -1, 0, 0, 0, [0, 0, 0, 0, 0, 0])
|
58
59
|
end).should raise_error(ArgumentError)
|
59
60
|
(lambda do
|
60
|
-
UUID.new(0, 65536, 0, 0, 0, [0, 0, 0, 0, 0, 0])
|
61
|
+
UUIDTools::UUID.new(0, 65536, 0, 0, 0, [0, 0, 0, 0, 0, 0])
|
61
62
|
end).should raise_error(ArgumentError)
|
62
63
|
end
|
63
64
|
|
64
65
|
it "should throw an exception if a segment has an invalid value" do
|
65
66
|
(lambda do
|
66
|
-
UUID.new(0, 0, -1, 0, 0, [0, 0, 0, 0, 0, 0])
|
67
|
+
UUIDTools::UUID.new(0, 0, -1, 0, 0, [0, 0, 0, 0, 0, 0])
|
67
68
|
end).should raise_error(ArgumentError)
|
68
69
|
(lambda do
|
69
|
-
UUID.new(0, 0, 65536, 0, 0, [0, 0, 0, 0, 0, 0])
|
70
|
+
UUIDTools::UUID.new(0, 0, 65536, 0, 0, [0, 0, 0, 0, 0, 0])
|
70
71
|
end).should raise_error(ArgumentError)
|
71
72
|
end
|
72
73
|
|
73
74
|
it "should throw an exception if a segment has an invalid value" do
|
74
75
|
(lambda do
|
75
|
-
UUID.new(0, 0, 0, -1, 0, [0, 0, 0, 0, 0, 0])
|
76
|
+
UUIDTools::UUID.new(0, 0, 0, -1, 0, [0, 0, 0, 0, 0, 0])
|
76
77
|
end).should raise_error(ArgumentError)
|
77
78
|
(lambda do
|
78
|
-
UUID.new(0, 0, 0, 256, 0, [0, 0, 0, 0, 0, 0])
|
79
|
+
UUIDTools::UUID.new(0, 0, 0, 256, 0, [0, 0, 0, 0, 0, 0])
|
79
80
|
end).should raise_error(ArgumentError)
|
80
81
|
end
|
81
82
|
|
82
83
|
it "should throw an exception if a segment has an invalid value" do
|
83
84
|
(lambda do
|
84
|
-
UUID.new(0, 0, 0, 0, -1, [0, 0, 0, 0, 0, 0])
|
85
|
+
UUIDTools::UUID.new(0, 0, 0, 0, -1, [0, 0, 0, 0, 0, 0])
|
85
86
|
end).should raise_error(ArgumentError)
|
86
87
|
(lambda do
|
87
|
-
UUID.new(0, 0, 0, 0, 256, [0, 0, 0, 0, 0, 0])
|
88
|
+
UUIDTools::UUID.new(0, 0, 0, 0, 256, [0, 0, 0, 0, 0, 0])
|
88
89
|
end).should raise_error(ArgumentError)
|
89
90
|
end
|
90
91
|
|
91
92
|
it "should throw an exception if nodes are not a collection" do
|
92
93
|
(lambda do
|
93
|
-
UUID.new(0, 0, 0, 0, 0, :bogus)
|
94
|
+
UUIDTools::UUID.new(0, 0, 0, 0, 0, :bogus)
|
94
95
|
end).should raise_error(TypeError)
|
95
96
|
end
|
96
97
|
|
97
98
|
it "should throw an exception if nodes are the wrong size" do
|
98
99
|
(lambda do
|
99
|
-
UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0])
|
100
|
+
UUIDTools::UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0])
|
100
101
|
end).should raise_error(ArgumentError)
|
101
102
|
end
|
102
103
|
|
103
104
|
it "should throw an exception if any nodes have invalid values" do
|
104
105
|
(lambda do
|
105
|
-
UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 256])
|
106
|
+
UUIDTools::UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 256])
|
106
107
|
end).should raise_error(ArgumentError)
|
107
108
|
end
|
108
109
|
|
109
110
|
it "should throw an exception if parsing anything but a String" do
|
110
111
|
(lambda do
|
111
|
-
UUID.parse(:bogus)
|
112
|
+
UUIDTools::UUID.parse(:bogus)
|
112
113
|
end).should raise_error(TypeError)
|
113
114
|
end
|
114
115
|
|
115
116
|
it "should throw an exception if raw parsing anything but a String" do
|
116
117
|
(lambda do
|
117
|
-
UUID.parse_raw(:bogus)
|
118
|
+
UUIDTools::UUID.parse_raw(:bogus)
|
118
119
|
end).should raise_error(TypeError)
|
119
120
|
end
|
120
121
|
end
|
@@ -1,71 +1,72 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), "../spec_helper.rb")
|
2
2
|
|
3
|
-
describe UUID, "when parsing" do
|
3
|
+
describe UUIDTools::UUID, "when parsing" do
|
4
4
|
it "should correctly parse the MAC address from a timestamp version UUID" do
|
5
|
-
UUID.timestamp_create.mac_address.should ==
|
5
|
+
UUIDTools::UUID.timestamp_create.mac_address.should ==
|
6
|
+
UUIDTools::UUID.mac_address
|
6
7
|
end
|
7
8
|
|
8
9
|
it "should correctly parse the variant from a timestamp version UUID" do
|
9
|
-
UUID.timestamp_create.variant.should == 0b100
|
10
|
+
UUIDTools::UUID.timestamp_create.variant.should == 0b100
|
10
11
|
end
|
11
12
|
|
12
13
|
it "should correctly parse the version from a timestamp version UUID" do
|
13
|
-
UUID.timestamp_create.version.should == 1
|
14
|
+
UUIDTools::UUID.timestamp_create.version.should == 1
|
14
15
|
end
|
15
16
|
|
16
17
|
it "should correctly parse the timestamp from a timestamp version UUID" do
|
17
|
-
UUID.timestamp_create.timestamp.should < Time.now + 1
|
18
|
-
UUID.timestamp_create.timestamp.should > Time.now - 1
|
18
|
+
UUIDTools::UUID.timestamp_create.timestamp.should < Time.now + 1
|
19
|
+
UUIDTools::UUID.timestamp_create.timestamp.should > Time.now - 1
|
19
20
|
end
|
20
21
|
|
21
22
|
it "should not treat a timestamp version UUID as a nil UUID" do
|
22
|
-
UUID.timestamp_create.should_not be_nil_uuid
|
23
|
+
UUIDTools::UUID.timestamp_create.should_not be_nil_uuid
|
23
24
|
end
|
24
25
|
|
25
26
|
it "should not treat a timestamp version UUID as a random node UUID" do
|
26
|
-
UUID.timestamp_create.should_not be_random_node_id
|
27
|
+
UUIDTools::UUID.timestamp_create.should_not be_random_node_id
|
27
28
|
end
|
28
29
|
|
29
30
|
it "should treat a timestamp version UUID as a random node UUID " +
|
30
31
|
"if there is no MAC address" do
|
31
|
-
old_mac_address = UUID.mac_address
|
32
|
-
UUID.mac_address = nil
|
33
|
-
UUID.timestamp_create.should be_random_node_id
|
34
|
-
UUID.mac_address = old_mac_address
|
32
|
+
old_mac_address = UUIDTools::UUID.mac_address
|
33
|
+
UUIDTools::UUID.mac_address = nil
|
34
|
+
UUIDTools::UUID.timestamp_create.should be_random_node_id
|
35
|
+
UUIDTools::UUID.mac_address = old_mac_address
|
35
36
|
end
|
36
37
|
|
37
38
|
it "should correctly identify the nil UUID" do
|
38
|
-
UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0]).should be_nil_uuid
|
39
|
+
UUIDTools::UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0]).should be_nil_uuid
|
39
40
|
end
|
40
41
|
|
41
42
|
it "should correctly identify timestamp version UUIDs as valid" do
|
42
|
-
UUID.timestamp_create.should be_valid
|
43
|
+
UUIDTools::UUID.timestamp_create.should be_valid
|
43
44
|
end
|
44
45
|
|
45
46
|
it "should correctly identify random number version UUIDs as valid" do
|
46
|
-
UUID.random_create.should be_valid
|
47
|
+
UUIDTools::UUID.random_create.should be_valid
|
47
48
|
end
|
48
49
|
|
49
50
|
it "should correctly identify SHA1 hash version UUIDs as valid" do
|
50
|
-
UUID.sha1_create(
|
51
|
-
UUID_URL_NAMESPACE, 'http://sporkmonger.com'
|
51
|
+
UUIDTools::UUID.sha1_create(
|
52
|
+
UUIDTools::UUID_URL_NAMESPACE, 'http://sporkmonger.com'
|
52
53
|
).should be_valid
|
53
54
|
end
|
54
55
|
|
55
56
|
it "should correctly identify MD5 hash version UUIDs as valid" do
|
56
|
-
UUID.md5_create(
|
57
|
-
UUID_URL_NAMESPACE, 'http://sporkmonger.com'
|
57
|
+
UUIDTools::UUID.md5_create(
|
58
|
+
UUIDTools::UUID_URL_NAMESPACE, 'http://sporkmonger.com'
|
58
59
|
).should be_valid
|
59
60
|
end
|
60
61
|
|
61
62
|
it "should not identify the nil UUID as valid" do
|
62
|
-
UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0]).should_not be_valid
|
63
|
+
UUIDTools::UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0]).should_not be_valid
|
63
64
|
end
|
64
65
|
|
65
66
|
it "should allow for sorting of UUID arrays" do
|
66
67
|
uuids = []
|
67
68
|
1000.times do
|
68
|
-
uuids << UUID.timestamp_create
|
69
|
+
uuids << UUIDTools::UUID.timestamp_create
|
69
70
|
end
|
70
71
|
uuids.sort!
|
71
72
|
uuids.first.should < uuids.last
|
@@ -73,36 +74,36 @@ describe UUID, "when parsing" do
|
|
73
74
|
end
|
74
75
|
|
75
76
|
it "should allow for comparison of UUIDs" do
|
76
|
-
UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0]).should <
|
77
|
-
UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 1])
|
78
|
-
UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 1]).should >
|
79
|
-
UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0])
|
80
|
-
UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0]).should ==
|
81
|
-
UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0])
|
77
|
+
UUIDTools::UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0]).should <
|
78
|
+
UUIDTools::UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 1])
|
79
|
+
UUIDTools::UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 1]).should >
|
80
|
+
UUIDTools::UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0])
|
81
|
+
UUIDTools::UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0]).should ==
|
82
|
+
UUIDTools::UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0])
|
82
83
|
end
|
83
84
|
|
84
85
|
it "should produce the correct hexdigest for a UUID" do
|
85
|
-
UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0]).hexdigest.should ==
|
86
|
+
UUIDTools::UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0]).hexdigest.should ==
|
86
87
|
"00000000000000000000000000000000"
|
87
|
-
UUID.new(1, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0]).hexdigest.should ==
|
88
|
+
UUIDTools::UUID.new(1, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0]).hexdigest.should ==
|
88
89
|
"00000001000000000000000000000000"
|
89
|
-
UUID.timestamp_create.hexdigest.size.should == 32
|
90
|
+
UUIDTools::UUID.timestamp_create.hexdigest.size.should == 32
|
90
91
|
end
|
91
92
|
|
92
93
|
it "should produce a sane hash value for a UUID" do
|
93
|
-
uuid = UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0])
|
94
|
+
uuid = UUIDTools::UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0])
|
94
95
|
uuid.to_i.should == 0
|
95
96
|
uuid.hash.should be_kind_of(Fixnum)
|
96
97
|
end
|
97
98
|
|
98
99
|
it "should produce the correct URI for a UUID" do
|
99
|
-
UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0]).to_uri.should ==
|
100
|
+
UUIDTools::UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0]).to_uri.should ==
|
100
101
|
"urn:uuid:00000000-0000-0000-0000-000000000000"
|
101
102
|
end
|
102
103
|
|
103
104
|
it "should correctly test UUID equality" do
|
104
|
-
UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0]).should be_eql(
|
105
|
-
UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0])
|
105
|
+
UUIDTools::UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0]).should be_eql(
|
106
|
+
UUIDTools::UUID.new(0, 0, 0, 0, 0, [0, 0, 0, 0, 0, 0])
|
106
107
|
)
|
107
108
|
end
|
108
109
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uuidtools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Aman
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-06-02 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|