Skip to content

Commit 1883877

Browse files
committed
Merge branch 'release/1.0.0' into develop
2 parents f42c27e + 1009f7e commit 1883877

9 files changed

Lines changed: 38 additions & 58 deletions

File tree

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CodeBreaker
22

3-
[![Build Status](https://travis-ci.org/daigaku-ruby/code_breaker.svg?branch=main)](https://travis-ci.org/daigaku-ruby/code_breaker)
3+
[![Build Status](https://github.com/daigaku-ruby/code_breaker/workflows/main/badge.svg)](https://github.com/daigaku-ruby/code_breaker/workflows/main/badge.svg)
44
[![Gem Version](https://badge.fury.io/rb/code_breaker.svg)](http://badge.fury.io/rb/code_breaker)
55

66
CodeBreaker breaks a line of Ruby code into its receiver classes and the methods
@@ -44,10 +44,6 @@ require 'code_breaker'
4444

4545
code_snippet = 'crazy_number = Rational(3, 5) + 42 - Complex(2.3, 6.4) * 1.2'
4646
CodeBreaker.parse(code_snippet)
47-
# for Ruby < v2.4.0:
48-
# => {:lvasgn=>[:crazy_number, [Rational, :+, Fixnum, :-, Complex, :*, Float]]}
49-
#
50-
# for Ruby >= v2.4.0:
5147
# => {:lvasgn=>[:crazy_number, [Rational, :+, Integer, :-, Complex, :*, Float]]}
5248

5349
code_snippet = '"hello" + "World"'

spec/code_breaker/parser/assignments_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,31 @@
55
context 'for a local variable assignment' do
66
it 'returns a Hash with key :lvasgn' do
77
input = "name = 'John Doe' + 24.to_s"
8-
output = { lvasgn: [:name, [String, :+, fixnum_or_integer, :to_s]] }
8+
output = { lvasgn: [:name, [String, :+, Integer, :to_s]] }
99
expect(input).to be_parsed_as output
1010
end
1111
end
1212

1313
context 'for an instance variable assignment' do
1414
it 'returns a Hash with key :ivasgn' do
1515
input = "@name = 'John Doe' + 24.to_s"
16-
output = { ivasgn: [:@name, [String, :+, fixnum_or_integer, :to_s]] }
16+
output = { ivasgn: [:@name, [String, :+, Integer, :to_s]] }
1717
expect(input).to be_parsed_as output
1818
end
1919
end
2020

2121
context 'for a class variable assignment' do
2222
it 'returns a Hash with key :cvasgn' do
2323
input = "@@name = 'John Doe' + 24.to_s"
24-
output = { cvasgn: [:@@name, [String, :+, fixnum_or_integer, :to_s]] }
24+
output = { cvasgn: [:@@name, [String, :+, Integer, :to_s]] }
2525
expect(input).to be_parsed_as output
2626
end
2727
end
2828

2929
context 'for a global variable assignment' do
3030
it 'returns a Hash with key :cvasgn' do
3131
input = "$name = 'John Doe' + 24.to_s"
32-
output = { gvasgn: [:'$name', [String, :+, fixnum_or_integer, :to_s]] }
32+
output = { gvasgn: [:'$name', [String, :+, Integer, :to_s]] }
3333
expect(input).to be_parsed_as output
3434
end
3535
end
@@ -45,13 +45,13 @@
4545
context 'for a multiple variable assignment' do
4646
it 'returns an assignment hash if RHS is an Array' do
4747
input = "x, y = ['holy', 108]"
48-
output = { masgn: { [:x, :y] => [String, fixnum_or_integer] } }
48+
output = { masgn: { [:x, :y] => [String, Integer] } }
4949
expect(input).to be_parsed_as output
5050
end
5151

5252
it 'returns an assignment hash if RHS is a variable list' do
5353
input = "x, y = 'holy', 108"
54-
output = { masgn: { [:x, :y] => [String, fixnum_or_integer] } }
54+
output = { masgn: { [:x, :y] => [String, Integer] } }
5555
expect(input).to be_parsed_as output
5656
end
5757

@@ -65,7 +65,7 @@
6565
context 'for an operation assignment' do
6666
it 'returns a Hash with key :op_asgn' do
6767
input = 'a += 1'
68-
output = { op_asgn: [{ lvasgn: [:a] }, :+, fixnum_or_integer] }
68+
output = { op_asgn: [{ lvasgn: [:a] }, :+, Integer] }
6969
expect(input).to be_parsed_as output
7070
end
7171
end

spec/code_breaker/parser/data_types_spec.rb

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,18 @@
1515
it "returns #{output} for #{input}" do
1616
expect(input).to be_parsed_as output
1717
end
18+
end
1819

19-
it 'returns Fixnum or Integer for 1' do
20-
expect(1).to be_parsed_as fixnum_or_integer
21-
end
22-
23-
it 'returns Bignum or Integer for 4_611_686_018_427_387_904' do
24-
expect(4_611_686_018_427_387_904).to be_parsed_as bignum_or_integer
25-
end
20+
it 'returns Integer for integers' do
21+
expect(1).to be_parsed_as Integer
22+
expect(4_611_686_018_427_387_904).to be_parsed_as Integer
2623
end
2724
end
2825

2926
context 'for a root node representing an Array' do
3027
it 'returns a Hash with key :array and an Array of items' do
3128
input = "[1, 'apple', :a, Day]"
32-
output = { array: [fixnum_or_integer, String, Symbol, { const: :Day }] }
29+
output = { array: [Integer, String, Symbol, { const: :Day }] }
3330
expect(input).to be_parsed_as output
3431
end
3532
end
@@ -59,7 +56,7 @@
5956
context 'for a root node representing an interpolated string' do
6057
it 'returns a Hash with key :dstr and an Array of interpolation values' do
6158
input = '"#{1 + 2} interpolated string #{\'here\'}"'
62-
output = { dstr: [[fixnum_or_integer, :+, fixnum_or_integer], String, [String]] }
59+
output = { dstr: [[Integer, :+, Integer], String, [String]] }
6360
expect(input).to be_parsed_as output
6461
end
6562
end

spec/code_breaker/parser/keywords_spec.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
context "for a root node representing an #{connector} connection" do
77
it 'returns a Hash with key :or and the connected children' do
88
input = "1.to_s #{connector} 5.5"
9-
output = { or: [[fixnum_or_integer, :to_s], Float] }
9+
output = { or: [[Integer, :to_s], Float] }
1010
expect(input).to be_parsed_as output
1111
end
1212
end
@@ -16,7 +16,7 @@
1616
context "for a root node representing an #{connector} connection" do
1717
it 'returns a Hash with key :and and the connected children' do
1818
input = "1.to_s #{connector} 5.5"
19-
output = { and: [[fixnum_or_integer, :to_s], Float] }
19+
output = { and: [[Integer, :to_s], Float] }
2020
expect(input).to be_parsed_as output
2121
end
2222
end
@@ -26,15 +26,15 @@
2626
context 'with only an if clause' do
2727
it 'returns a Hash with key :if and the if clause body' do
2828
input = "'2'.to_i if 2 == '2'"
29-
output = { if: [fixnum_or_integer, :==, String], then: [String, :to_i] }
29+
output = { if: [Integer, :==, String], then: [String, :to_i] }
3030
expect(input).to be_parsed_as output
3131
end
3232
end
3333

3434
context 'with an if/then clause' do
3535
it 'returns a Hash with key :if and the if clause body' do
3636
input = "if 2 == '2' then '2'.to_i end"
37-
output = { if: [fixnum_or_integer, :==, String], then: [String, :to_i] }
37+
output = { if: [Integer, :==, String], then: [String, :to_i] }
3838
expect(input).to be_parsed_as output
3939
end
4040
end
@@ -43,7 +43,7 @@
4343
it 'returns a Hash with key :if and the if clause body' do
4444
input = "if 2 == '2' then '2'.to_i else Rational(2, 3).to_s end"
4545
output = {
46-
if: [fixnum_or_integer, :==, String],
46+
if: [Integer, :==, String],
4747
then: [String, :to_i],
4848
else: [Rational, :to_s]
4949
}
@@ -56,7 +56,7 @@
5656
it 'returns a Hash with key :if and the if clause body' do
5757
input = "if 2 == '2' then '2'.to_i elsif true then Object.new end"
5858
output = {
59-
if: [fixnum_or_integer, :==, String],
59+
if: [Integer, :==, String],
6060
then: [String, :to_i],
6161
else: {
6262
if: TrueClass,
@@ -124,7 +124,7 @@
124124
module: [
125125
{ const: :Breakable },
126126
[
127-
{ casgn: [:CONST, fixnum_or_integer] },
127+
{ casgn: [:CONST, Integer] },
128128
{ casgn: [:OTHER_CONST, [String, :freeze]] }
129129
]
130130
]
@@ -138,21 +138,21 @@
138138
context 'for a root node representing a return' do
139139
it 'returns a Hash with key :return and the returned value' do
140140
input = 'return 3'
141-
output = { return: fixnum_or_integer }
141+
output = { return: Integer }
142142
expect(input).to be_parsed_as output
143143
end
144144

145145
it 'returns a Hash with key :return and the returned values as Array' do
146146
input = 'return 3 + 2'
147-
output = { return: [fixnum_or_integer, :+, fixnum_or_integer] }
147+
output = { return: [Integer, :+, Integer] }
148148
expect(input).to be_parsed_as output
149149
end
150150
end
151151

152152
context 'for a root node representing a yield' do
153153
it 'returns a Hash with key :yield and the types of given arguments' do
154154
input = "yield(3, 'beer')"
155-
output = { yield: [fixnum_or_integer, String] }
155+
output = { yield: [Integer, String] }
156156
expect(input).to be_parsed_as output
157157
end
158158

@@ -184,7 +184,7 @@
184184
input = "for i in 1..5 do\nputs i\nend"
185185
output = {
186186
for: { lvasgn: [:i] },
187-
in: { irange: [fixnum_or_integer, fixnum_or_integer] },
187+
in: { irange: [Integer, Integer] },
188188
do: [:puts, { lvar: :i }]
189189
}
190190

@@ -247,9 +247,9 @@
247247
{
248248
case: [
249249
{ lvar: :state },
250-
{ when: Symbol, then: [fixnum_or_integer, :to_s] },
251-
{ when: Symbol, then: [fixnum_or_integer, :to_s] },
252-
{ else: fixnum_or_integer }
250+
{ when: Symbol, then: [Integer, :to_s] },
251+
{ when: Symbol, then: [Integer, :to_s] },
252+
{ else: Integer }
253253
]
254254
}
255255
]
@@ -266,8 +266,8 @@
266266
{
267267
case: [
268268
{ lvar: :state },
269-
{ when: Symbol, then: [fixnum_or_integer, :to_s] },
270-
{ when: Symbol, then: [fixnum_or_integer, :to_s] },
269+
{ when: Symbol, then: [Integer, :to_s] },
270+
{ when: Symbol, then: [Integer, :to_s] },
271271
{ else: NilClass }
272272
]
273273
}

spec/code_breaker/parser/language_elements_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
input = '5.times { |n| n.to_s }'
88
output = {
99
block: [
10-
[fixnum_or_integer, :times],
10+
[Integer, :times],
1111
{ args: [{ arg: :n }] },
1212
[{ lvar: :n }, :to_s]
1313
]
@@ -22,7 +22,7 @@
2222
input = '[1, 2].reduce(0) { |sum, n| sum += n }'
2323
output = {
2424
block: [
25-
[{ array: [fixnum_or_integer, fixnum_or_integer] }, :reduce, fixnum_or_integer],
25+
[{ array: [Integer, Integer] }, :reduce, Integer],
2626
{ args: [{ arg: :sum }, { arg: :n }] },
2727
{ op_asgn: [{ lvasgn: [:sum] }, :+, { lvar: :n }] }
2828
]
@@ -35,7 +35,7 @@
3535
context 'for a root node representing a block pass' do
3636
it 'returns an array with a Hash with the :block_pass key' do
3737
input = '[1, 2].map &:to_s'
38-
output = [{ array: [fixnum_or_integer, fixnum_or_integer] }, :map, { block_pass: :to_s }]
38+
output = [{ array: [Integer, Integer] }, :map, { block_pass: :to_s }]
3939
expect(input).to be_parsed_as output
4040
end
4141
end
@@ -79,7 +79,7 @@
7979
{
8080
args: [
8181
{ arg: :name },
82-
{ optarg: [:options, { hash: [{ Symbol => fixnum_or_integer }] }] }
82+
{ optarg: [:options, { hash: [{ Symbol => Integer }] }] }
8383
]
8484
},
8585
String
@@ -134,7 +134,7 @@
134134
context 'for a root node representing a splat operator' do
135135
it 'returns a Hash with key :splat and the splat values' do
136136
input = 'puts(*[1,2])'
137-
output = [:puts, { splat: { array: [fixnum_or_integer, fixnum_or_integer] } }]
137+
output = [:puts, { splat: { array: [Integer, Integer] } }]
138138
expect(input).to be_parsed_as output
139139
end
140140
end

spec/code_breaker/parser/ranges_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
context 'for a root node representing an exclusive range' do
1414
it 'returns a Hash with key :erange and the bounding types' do
1515
input = '1.2...4'
16-
output = { erange: [Float, fixnum_or_integer] }
16+
output = { erange: [Float, Integer] }
1717
expect(input).to be_parsed_as output
1818
end
1919
end

spec/code_breaker/parser/wrappers_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
context 'for a simple method call on Objects' do
1515
it 'returns an Array with the classes and methods' do
1616
input = '1 + 3.5 * Rational(2,3) - Complex(1, 2)'
17-
output = [fixnum_or_integer, :+, Float, :*, Rational, :-, Complex]
17+
output = [Integer, :+, Float, :*, Rational, :-, Complex]
1818
expect(input).to be_parsed_as output
1919
end
2020

2121
describe 'with braces' do
2222
it 'returns a nested Array with the classes and methods' do
2323
input = '((1 + 3.5) - Rational(2,3)) * Complex(1, 2)'
24-
output = [[[fixnum_or_integer, :+, Float], :-, Rational], :*, Complex]
24+
output = [[[Integer, :+, Float], :-, Rational], :*, Complex]
2525
expect(input).to be_parsed_as output
2626
end
2727
end

spec/spec_helper.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,3 @@
22
require 'code_breaker'
33

44
Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each { |f| require f }
5-
6-
RSpec.configure do |config|
7-
config.include VersionHelpers
8-
end

spec/support/helpers/version_helpers.rb

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)