code_analyzer 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6c252e6214745ff2bcf507702a49553d0ca90c75a12614ee3e5c197c1994656c
4
- data.tar.gz: 85bb0e3b8ea846132ba4a159f4477749751cb54a94611a7402d241a2e296f1c6
3
+ metadata.gz: 792496737344902c984457c4a153f5e7e5717e7f9568f130cdc039c1779e9627
4
+ data.tar.gz: 8b15a24c9ede966353b1100328fe1d5dcc14937fc6d2a4401a455cfe42176d27
5
5
  SHA512:
6
- metadata.gz: 73fc0d1d771feafb646ff218837ae19e8de9556acd25b4fb3a3bad93b76899d950037145c603b1b5e48a38815b1be086102f65c3e77ad2bc2898931858988e6c
7
- data.tar.gz: 3fd7c957fc9c2ceeb6714cf4a6a4f1db7b00f7ea6d4a9e73553b460c59f0bd42a4f5d4538e7bf00bc2f39d441f29bed8891a3d200a65b0653830d30c735b7dc0
6
+ metadata.gz: 2bd9cd8d09ffaab831f417207e0003082408ddb61e8a513884a0d137adb567c1c6f3aed5f68d2460d58a5799ef56a514cb49af4d1c5f2b92b017500193709e54
7
+ data.tar.gz: dd4bf2b587ca333c7eeabcd088586eeebc421c9e41931d1637a7dd0bb3f1b403959b95c0cc697eb81cd6d818e198f4648b1fc8e1d585c8896600f528ec2511fe
@@ -844,7 +844,7 @@ class Sexp
844
844
  case sexp_type
845
845
  when :string_literal, :xstring_literal, :string_content, :const_ref,
846
846
  :symbol_literal, :symbol, :args_add_block, :var_ref, :vcall, :var_field,
847
- :@ident, :@tstring_content, :@const, :@ivar, :@kw, :@gvar, :@cvar
847
+ :@ident, :@tstring_content, :@const, :@ivar, :@kw, :@gvar, :@cvar, :@period
848
848
  self[1].to_s
849
849
  when :string_add
850
850
  s(:string_content) == self[1] ? self[2].to_s : self[1].to_s
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module CodeAnalyzer
3
- VERSION = '0.5.0'
3
+ VERSION = '0.5.1'
4
4
  end
@@ -87,25 +87,14 @@ describe Sexp do
87
87
  @node.grep_nodes(sexp_type: :call, receiver: 'current_user') do |node|
88
88
  nodes << node
89
89
  end
90
- if RUBY_VERSION == '1.9.2'
91
- expect(nodes).to eq [
92
- s(
93
- :call,
94
- s(:var_ref, s(:@ident, 'current_user', s(2, 8))),
95
- s(:@period, ".", s(2, 20)),
96
- s(:@ident, 'posts', s(2, 21))
97
- )
98
- ]
99
- else
100
- expect(nodes).to eq [
101
- s(
102
- :call,
103
- s(:vcall, s(:@ident, 'current_user', s(2, 8))),
104
- s(:@period, ".", s(2, 20)),
105
- s(:@ident, 'posts', s(2, 21))
106
- )
107
- ]
108
- end
90
+ expect(nodes).to eq [
91
+ s(
92
+ :call,
93
+ s(:vcall, s(:@ident, 'current_user', s(2, 8))),
94
+ s(:@period, ".", s(2, 20)),
95
+ s(:@ident, 'posts', s(2, 21))
96
+ )
97
+ ]
109
98
  end
110
99
 
111
100
  it 'should get the call nodes with different messages' do
@@ -113,65 +102,33 @@ describe Sexp do
113
102
  @node.grep_nodes(sexp_type: :call, message: %w[posts find]) do |node|
114
103
  nodes << node
115
104
  end
116
- if RUBY_VERSION == '1.9.2'
117
- expect(nodes).to eq [
118
- s(
119
- :call,
120
- s(
121
- :call,
122
- s(:var_ref, s(:@ident, 'current_user', s(2, 8))),
123
- s(:@period, ".", s(2, 20)),
124
- s(:@ident, 'posts', s(2, 21))
125
- ),
126
- s(:@period, ".", s(2, 26)),
127
- s(:@ident, 'find', s(2, 27))
128
- ),
129
- s(
130
- :call,
131
- s(:var_ref, s(:@ident, 'current_user', s(2, 8))),
132
- s(:@period, ".", s(2, 20)),
133
- s(:@ident, 'posts', s(2, 21))
134
- )
135
- ]
136
- else
137
- expect(nodes).to eq [
138
- s(
139
- :call,
140
- s(
141
- :call,
142
- s(:vcall, s(:@ident, 'current_user', s(2, 8))),
143
- s(:@period, ".", s(2, 20)),
144
- s(:@ident, 'posts', s(2, 21))
145
- ),
146
- s(:@period, ".", s(2, 26)),
147
- s(:@ident, 'find', s(2, 27))
148
- ),
105
+ expect(nodes).to eq [
106
+ s(
107
+ :call,
149
108
  s(
150
109
  :call,
151
110
  s(:vcall, s(:@ident, 'current_user', s(2, 8))),
152
111
  s(:@period, ".", s(2, 20)),
153
112
  s(:@ident, 'posts', s(2, 21))
154
- )
155
- ]
156
- end
113
+ ),
114
+ s(:@period, ".", s(2, 26)),
115
+ s(:@ident, 'find', s(2, 27))
116
+ ),
117
+ s(
118
+ :call,
119
+ s(:vcall, s(:@ident, 'current_user', s(2, 8))),
120
+ s(:@period, ".", s(2, 20)),
121
+ s(:@ident, 'posts', s(2, 21))
122
+ )
123
+ ]
157
124
  end
158
125
 
159
- if RUBY_VERSION == '1.9.2'
160
- it 'should get the var_ref node with to_s' do
161
- nodes = []
162
- @node.grep_nodes(sexp_type: :var_ref, to_s: 'current_user') do |node|
163
- nodes << node
164
- end
165
- expect(nodes).to eq [s(:var_ref, s(:@ident, 'current_user', s(2, 8)))]
166
- end
167
- else
168
- it 'should get the vcall node with to_s' do
169
- nodes = []
170
- @node.grep_nodes(sexp_type: :vcall, to_s: 'current_user') do |node|
171
- nodes << node
172
- end
173
- expect(nodes).to eq [s(:vcall, s(:@ident, 'current_user', s(2, 8)))]
126
+ it 'should get the vcall node with to_s' do
127
+ nodes = []
128
+ @node.grep_nodes(sexp_type: :vcall, to_s: 'current_user') do |node|
129
+ nodes << node
174
130
  end
131
+ expect(nodes).to eq [s(:vcall, s(:@ident, 'current_user', s(2, 8)))]
175
132
  end
176
133
  end
177
134
 
@@ -187,21 +144,12 @@ describe Sexp do
187
144
 
188
145
  it 'should get first node with empty argument' do
189
146
  node = @node.grep_node(sexp_type: :call, receiver: 'current_user')
190
- if RUBY_VERSION == '1.9.2'
191
- expect(node).to eq s(
192
- :call,
193
- s(:var_ref, s(:@ident, 'current_user', s(2, 8))),
194
- s(:@period, ".", s(2, 20)),
195
- s(:@ident, 'posts', s(2, 21))
196
- )
197
- else
198
- expect(node).to eq s(
199
- :call,
200
- s(:vcall, s(:@ident, 'current_user', s(2, 8))),
201
- s(:@period, ".", s(2, 20)),
202
- s(:@ident, 'posts', s(2, 21))
203
- )
204
- end
147
+ expect(node).to eq s(
148
+ :call,
149
+ s(:vcall, s(:@ident, 'current_user', s(2, 8))),
150
+ s(:@period, ".", s(2, 20)),
151
+ s(:@ident, 'posts', s(2, 21))
152
+ )
205
153
  end
206
154
  end
207
155
 
@@ -415,43 +363,23 @@ describe Sexp do
415
363
  node =
416
364
  parse_content('options_for_select(Account.get_business current_user)')
417
365
  .grep_node(sexp_type: :args_add)
418
- if RUBY_VERSION == '1.9.2'
419
- expect(node.all).to eq [
366
+ expect(node.all).to eq [
367
+ s(
368
+ :command_call,
369
+ s(:var_ref, s(:@const, 'Account', s(1, 19))),
370
+ s(:@period, ".", s(1, 26)),
371
+ s(:@ident, 'get_business', s(1, 27)),
420
372
  s(
421
- :command_call,
422
- s(:var_ref, s(:@const, 'Account', s(1, 19))),
423
- :".",
424
- s(:@ident, 'get_business', s(1, 27)),
373
+ :args_add_block,
425
374
  s(
426
- :args_add_block,
427
- s(
428
- :args_add,
429
- s(:args_new),
430
- s(:var_ref, s(:@ident, 'current_user', s(1, 40)))
431
- ),
432
- false
433
- )
434
- )
435
- ]
436
- else
437
- expect(node.all).to eq [
438
- s(
439
- :command_call,
440
- s(:var_ref, s(:@const, 'Account', s(1, 19))),
441
- s(:@period, ".", s(1, 26)),
442
- s(:@ident, 'get_business', s(1, 27)),
443
- s(
444
- :args_add_block,
445
- s(
446
- :args_add,
447
- s(:args_new),
448
- s(:vcall, s(:@ident, 'current_user', s(1, 40)))
449
- ),
450
- false
451
- )
375
+ :args_add,
376
+ s(:args_new),
377
+ s(:vcall, s(:@ident, 'current_user', s(1, 40)))
378
+ ),
379
+ false
452
380
  )
453
- ]
454
- end
381
+ )
382
+ ]
455
383
  end
456
384
 
457
385
  it 'no error for args_add_star' do
@@ -885,6 +813,11 @@ describe Sexp do
885
813
  expect(node.to_s).to eq '@user'
886
814
  end
887
815
 
816
+ it 'should get to_s for period' do
817
+ node = parse_content('@user.name').grep_node(sexp_type: :@period)
818
+ expect(node.to_s).to eq '.'
819
+ end
820
+
888
821
  it 'should get to_s for class with module' do
889
822
  node =
890
823
  parse_content('ActiveRecord::Base').grep_node(
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_analyzer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang