Skip to content

Commit 3cd035f

Browse files
authored
Left pad Node#inspect hex digits with zeros.
1 parent 1f4d4f8 commit 3cd035f

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/async/node.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def annotate(annotation)
218218
end
219219

220220
def description
221-
@object_name ||= "#{self.class}:0x#{object_id.to_s(16)}#{@transient ? ' transient' : nil}"
221+
@object_name ||= "#{self.class}:#{format '%#018x', object_id}#{@transient ? ' transient' : nil}"
222222

223223
if @annotation
224224
"#{@object_name} #{@annotation}"

spec/async/node_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,30 @@
6262
expect(lines[1]).to be =~ /\t#<Async::Node:0x\h+>\n/
6363
end
6464
end
65+
66+
describe '#inspect' do
67+
let(:node) {Async::Node.new}
68+
69+
it 'should begin with the class name' do
70+
expect(node.inspect).to start_with "#<#{node.class.name}"
71+
end
72+
73+
it 'should end with hex digits' do
74+
expect(node.inspect).to match(/\h>\z/)
75+
end
76+
77+
it 'should have a standard number of hex digits' do
78+
expect(node.inspect).to match(/:0x\h{16}>/)
79+
end
80+
81+
it 'should have a colon in the middle' do
82+
name, middle, hex = node.inspect.rpartition(':')
83+
84+
expect(name).to end_with node.class.name
85+
expect(middle).to eq ':'
86+
expect(hex).to match(/\A\h+/)
87+
end
88+
end
6589

6690
describe '#consume' do
6791
it "can't consume middle node" do

0 commit comments

Comments
 (0)