Skip to content

Commit

Permalink
Add IntNode#value and FloatNode#value
Browse files Browse the repository at this point in the history
  • Loading branch information
fatkodima authored and marcandre committed Aug 1, 2020
1 parent bff5017 commit 14c729b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
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
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
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
@@ -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
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

0 comments on commit 14c729b

Please sign in to comment.