diff --git a/lib/async/node.rb b/lib/async/node.rb index 48821486..2237b98d 100644 --- a/lib/async/node.rb +++ b/lib/async/node.rb @@ -218,7 +218,7 @@ def annotate(annotation) end def description - @object_name ||= "#{self.class}:0x#{object_id.to_s(16)}#{@transient ? ' transient' : nil}" + @object_name ||= "#{self.class}:#{format '%#018x', object_id}#{@transient ? ' transient' : nil}" if @annotation "#{@object_name} #{@annotation}" diff --git a/spec/async/node_spec.rb b/spec/async/node_spec.rb index 2886591e..9667890d 100644 --- a/spec/async/node_spec.rb +++ b/spec/async/node_spec.rb @@ -62,6 +62,30 @@ expect(lines[1]).to be =~ /\t#\n/ end end + + describe '#inspect' do + let(:node) {Async::Node.new} + + it 'should begin with the class name' do + expect(node.inspect).to start_with "#<#{node.class.name}" + end + + it 'should end with hex digits' do + expect(node.inspect).to match(/\h>\z/) + end + + it 'should have a standard number of hex digits' do + expect(node.inspect).to match(/:0x\h{16}>/) + end + + it 'should have a colon in the middle' do + name, middle, hex = node.inspect.rpartition(':') + + expect(name).to end_with node.class.name + expect(middle).to eq ':' + expect(hex).to match(/\A\h+/) + end + end describe '#consume' do it "can't consume middle node" do