Skip to content

Left pad Node#inspect hex digits with zeros. #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/async/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
24 changes: 24 additions & 0 deletions spec/async/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,30 @@
expect(lines[1]).to be =~ /\t#<Async::Node:0x\h+>\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
Expand Down