code_analyzer 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/code_analyzer/sexp.rb +1 -1
- data/lib/code_analyzer/version.rb +1 -1
- data/spec/code_analyzer/sexp_spec.rb +52 -119
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 792496737344902c984457c4a153f5e7e5717e7f9568f130cdc039c1779e9627
|
4
|
+
data.tar.gz: 8b15a24c9ede966353b1100328fe1d5dcc14937fc6d2a4401a455cfe42176d27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bd9cd8d09ffaab831f417207e0003082408ddb61e8a513884a0d137adb567c1c6f3aed5f68d2460d58a5799ef56a514cb49af4d1c5f2b92b017500193709e54
|
7
|
+
data.tar.gz: dd4bf2b587ca333c7eeabcd088586eeebc421c9e41931d1637a7dd0bb3f1b403959b95c0cc697eb81cd6d818e198f4648b1fc8e1d585c8896600f528ec2511fe
|
data/lib/code_analyzer/sexp.rb
CHANGED
@@ -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
|
@@ -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
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
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
|
-
|
117
|
-
|
118
|
-
|
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
|
-
|
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
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
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
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
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
|
-
|
419
|
-
|
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
|
-
:
|
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
|
-
:
|
427
|
-
s(
|
428
|
-
|
429
|
-
|
430
|
-
|
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
|
-
|
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(
|