Skip to content
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

Add IntNode#value and FloatNode#value #85

Merged
merged 1 commit into from
Aug 1, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### New features

* [#70](https://github.com/rubocop-hq/rubocop-ast/pull/70): Add `NextNode` ([@marcandre][])
* [#85](https://github.com/rubocop-hq/rubocop-ast/pull/85): Add `IntNode#value` and `FloatNode#value`. ([@fatkodima][])

### Bug fixes

Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/ast/node/float_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module AST
# node when the builder constructs the AST, making its methods available to
# all `float` nodes within RuboCop.
class FloatNode < Node
include BasicLiteralNode
include NumericNode
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/ast/node/int_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module AST
# node when the builder constructs the AST, making its methods available to
# all `int` nodes within RuboCop.
class IntNode < Node
include BasicLiteralNode
include NumericNode
end
end
Expand Down
16 changes: 12 additions & 4 deletions spec/rubocop/ast/float_node_spec.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
# frozen_string_literal: true

RSpec.describe RuboCop::AST::FloatNode do
let(:int_node) { parse_source(source).ast }
let(:float_node) { parse_source(source).ast }

describe '.new' do
let(:source) { '42.0' }

it { expect(int_node.is_a?(described_class)).to be_truthy }
it { expect(float_node.is_a?(described_class)).to be_truthy }
end

describe '#sign?' do
context 'explicit positive float' do
let(:source) { '+42.0' }

it { expect(int_node.sign?).to be_truthy }
it { expect(float_node.sign?).to be_truthy }
end

context 'explicit negative float' do
let(:source) { '-42.0' }

it { expect(int_node.sign?).to be_truthy }
it { expect(float_node.sign?).to be_truthy }
end
end

describe '#value' do
let(:source) do
'1.5'
end

it { expect(float_node.value).to eq(1.5) }
end
end
8 changes: 8 additions & 0 deletions spec/rubocop/ast/int_node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@
it { expect(int_node.sign?).to be_truthy }
end
end

describe '#value' do
let(:source) do
'10'
end

it { expect(int_node.value).to eq(10) }
end
end