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

Make Node#numeric_type? aware of rational and complex literals #213

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1 @@
* [#213](https://github.com/rubocop/rubocop-ast/pull/213): Make `Node#numeric_type?` aware of rational and complex literals. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/ast/node.rb
Expand Up @@ -464,7 +464,7 @@ def boolean_type?
end

def numeric_type?
int_type? || float_type?
int_type? || float_type? || rational_type? || complex_type?
end

def range_type?
Expand Down
50 changes: 50 additions & 0 deletions spec/rubocop/ast/node_spec.rb
Expand Up @@ -786,4 +786,54 @@ class << expr
it { is_expected.to eq nil }
end
end

describe '#nurimec_type?' do
context 'when integer literal' do
let(:src) { '42' }

it 'is true' do
expect(node).to be_numeric_type
end
end

context 'when float literal' do
let(:src) { '42.0' }

it 'is true' do
expect(node).to be_numeric_type
end
end

context 'when rational literal' do
let(:src) { '42r' }

it 'is true' do
expect(node).to be_numeric_type
end
end

context 'when complex literal' do
let(:src) { '42i' }

it 'is true' do
expect(node).to be_numeric_type
end
end

context 'when complex literal whose imaginary part is a rational' do
let(:src) { '42ri' }

it 'is true' do
expect(node).to be_numeric_type
end
end

context 'when string literal' do
let(:src) { '"42"' }

it 'is true' do
expect(node).not_to be_numeric_type
end
end
end
end