synvert-core 0.41.2 → 0.42.0
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/CHANGELOG.md +5 -0
- data/lib/synvert/core/node_ext.rb +13 -8
- data/lib/synvert/core/version.rb +1 -1
- data/spec/synvert/core/node_ext_spec.rb +29 -10
- data/spec/synvert/core/rewriter/instance_spec.rb +48 -56
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19c77660c79cc18a6c2d720d7a8bada136dc0397a2cc73610cc87d3412ac5306
|
4
|
+
data.tar.gz: '083cc96fa1b41d83a4bd5c3512440ec88223bbc67969aca2d03dd58f87a26b24'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6403332404a070851c4817321702097cbff8cc34f75bc23d8dba236be878c83948012f79ba36ed51bea4e275f61f4adf4a5b638e35b0c8fd88dfd370b720854f
|
7
|
+
data.tar.gz: dc6bbc40dc208bb9ed9b8f9003b7a11e59ece0e79fb8db3cc4466f7c5b6f70574f71a5c7e4e161e762498854954293105b2023a996802b2906df04af51286f9a
|
data/CHANGELOG.md
CHANGED
@@ -240,7 +240,7 @@ module Parser::AST
|
|
240
240
|
# @raise [Synvert::Core::MethodNotSupported] if calls on other node.
|
241
241
|
def to_value
|
242
242
|
case type
|
243
|
-
when :int, :str, :sym
|
243
|
+
when :int, :float, :str, :sym
|
244
244
|
children.last
|
245
245
|
when :true
|
246
246
|
true
|
@@ -253,7 +253,7 @@ module Parser::AST
|
|
253
253
|
when :begin
|
254
254
|
children.first.to_value
|
255
255
|
else
|
256
|
-
|
256
|
+
self
|
257
257
|
end
|
258
258
|
end
|
259
259
|
|
@@ -504,10 +504,11 @@ module Parser::AST
|
|
504
504
|
end
|
505
505
|
when String
|
506
506
|
if actual.is_a?(Parser::AST::Node)
|
507
|
+
return true if (Parser::CurrentRuby.parse(expected) == actual rescue nil)
|
507
508
|
actual.to_source == expected || (actual.to_source[0] == ':' && actual.to_source[1..-1] == expected) ||
|
508
509
|
actual.to_source[1...-1] == expected
|
509
510
|
else
|
510
|
-
actual.to_s == expected
|
511
|
+
actual.to_s == expected || wrap_quote(actual.to_s) == expected
|
511
512
|
end
|
512
513
|
when Regexp
|
513
514
|
if actual.is_a?(Parser::AST::Node)
|
@@ -565,11 +566,7 @@ module Parser::AST
|
|
565
566
|
# @param multi_keys [Array<Symbol>]
|
566
567
|
# @return [Object] actual value.
|
567
568
|
def actual_value(node, multi_keys)
|
568
|
-
multi_keys.inject(node) { |n, key|
|
569
|
-
if n
|
570
|
-
key == :source ? n.send(key) : n.send(key)
|
571
|
-
end
|
572
|
-
}
|
569
|
+
multi_keys.inject(node) { |n, key| n.send(key) if n }
|
573
570
|
end
|
574
571
|
|
575
572
|
# Get expected value from rules.
|
@@ -580,5 +577,13 @@ module Parser::AST
|
|
580
577
|
def expected_value(rules, multi_keys)
|
581
578
|
multi_keys.inject(rules) { |o, key| o[key] }
|
582
579
|
end
|
580
|
+
|
581
|
+
def wrap_quote(string)
|
582
|
+
if string.include?("'")
|
583
|
+
"\"#{string}\""
|
584
|
+
else
|
585
|
+
"'#{string}'"
|
586
|
+
end
|
587
|
+
end
|
583
588
|
end
|
584
589
|
end
|
data/lib/synvert/core/version.rb
CHANGED
@@ -291,6 +291,11 @@ describe Parser::AST::Node do
|
|
291
291
|
expect(node.to_value).to eq 1
|
292
292
|
end
|
293
293
|
|
294
|
+
it 'gets for float' do
|
295
|
+
node = parse('1.5')
|
296
|
+
expect(node.to_value).to eq 1.5
|
297
|
+
end
|
298
|
+
|
294
299
|
it 'gets for string' do
|
295
300
|
node = parse("'str'")
|
296
301
|
expect(node.to_value).to eq 'str'
|
@@ -385,11 +390,6 @@ describe Parser::AST::Node do
|
|
385
390
|
end
|
386
391
|
|
387
392
|
describe '#match?' do
|
388
|
-
let(:instance) {
|
389
|
-
rewriter = Synvert::Rewriter.new('foo', 'bar')
|
390
|
-
Synvert::Rewriter::Instance.new(rewriter, 'file pattern')
|
391
|
-
}
|
392
|
-
|
393
393
|
it 'matches class name' do
|
394
394
|
source = 'class Synvert; end'
|
395
395
|
node = parse(source)
|
@@ -414,18 +414,42 @@ describe Parser::AST::Node do
|
|
414
414
|
expect(node).to be_match(type: 'send', arguments: [0])
|
415
415
|
end
|
416
416
|
|
417
|
+
it 'matches assign float' do
|
418
|
+
source = 'at_least(1.5)'
|
419
|
+
node = parse(source)
|
420
|
+
expect(node).to be_match(type: 'send', arguments: [1.5])
|
421
|
+
end
|
422
|
+
|
417
423
|
it 'matches arguments with string' do
|
418
424
|
source = 'params["user"]'
|
419
425
|
node = parse(source)
|
420
426
|
expect(node).to be_match(type: 'send', receiver: 'params', message: '[]', arguments: ['user'])
|
421
427
|
end
|
422
428
|
|
429
|
+
it 'matches arguments with string 2' do
|
430
|
+
source = 'params["user"]'
|
431
|
+
node = parse(source)
|
432
|
+
expect(node).to be_match(type: 'send', receiver: 'params', message: '[]', arguments: ["'user'"])
|
433
|
+
end
|
434
|
+
|
435
|
+
it 'matches arguments with string 3' do
|
436
|
+
source = "{ notice: 'Welcome' }"
|
437
|
+
node = parse(source)
|
438
|
+
expect(node).to be_match(type: 'hash', notice_value: "'Welcome'")
|
439
|
+
end
|
440
|
+
|
423
441
|
it 'matches arguments any' do
|
424
442
|
source = 'config.middleware.insert_after ActiveRecord::QueryCache, Lifo::Cache, page_cache: false'
|
425
443
|
node = parse(source)
|
426
444
|
expect(node).to be_match(type: 'send', arguments: { any: 'Lifo::Cache' })
|
427
445
|
end
|
428
446
|
|
447
|
+
it 'matches arguments with nested hash' do
|
448
|
+
source = '{ user_id: user.id }'
|
449
|
+
node = parse(source)
|
450
|
+
expect(node).to be_match(type: 'hash', user_id_value: { type: 'send', receiver: { type: 'send', message: 'user' }, message: 'id' })
|
451
|
+
end
|
452
|
+
|
429
453
|
it 'matches arguments contain' do
|
430
454
|
source = 'def slow(foo, bar, &block); end'
|
431
455
|
node = parse(source)
|
@@ -594,11 +618,6 @@ describe Parser::AST::Node do
|
|
594
618
|
end
|
595
619
|
|
596
620
|
describe '#rewritten_source' do
|
597
|
-
let(:instance) {
|
598
|
-
rewriter = Synvert::Rewriter.new('foo', 'bar')
|
599
|
-
Synvert::Rewriter::Instance.new(rewriter, 'file pattern')
|
600
|
-
}
|
601
|
-
|
602
621
|
it 'does not rewrite with unknown method' do
|
603
622
|
source = 'class Synvert; end'
|
604
623
|
node = parse(source)
|
@@ -155,22 +155,20 @@ module Synvert::Core
|
|
155
155
|
replace_with 'create {{arguments}}'
|
156
156
|
end
|
157
157
|
end
|
158
|
-
input =
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
end
|
173
|
-
"
|
158
|
+
input = <<~EOS
|
159
|
+
it 'uses factory_girl' do
|
160
|
+
user = FactoryGirl.create :user
|
161
|
+
post = FactoryGirl.create :post, user: user
|
162
|
+
assert post.valid?
|
163
|
+
end
|
164
|
+
EOS
|
165
|
+
output = <<~EOS
|
166
|
+
it 'uses factory_girl' do
|
167
|
+
user = create :user
|
168
|
+
post = create :post, user: user
|
169
|
+
assert post.valid?
|
170
|
+
end
|
171
|
+
EOS
|
174
172
|
expect(Dir).to receive(:glob).with('./spec/**/*_spec.rb').and_return(['spec/models/post_spec.rb'])
|
175
173
|
expect(File).to receive(:read).with('spec/models/post_spec.rb').and_return(input)
|
176
174
|
expect(File).to receive(:write).with('spec/models/post_spec.rb', output)
|
@@ -186,18 +184,16 @@ end
|
|
186
184
|
end
|
187
185
|
end
|
188
186
|
end
|
189
|
-
input =
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
end
|
200
|
-
'
|
187
|
+
input = <<~EOS
|
188
|
+
RSpec.configure do |config|
|
189
|
+
config.include FactoryGirl::Syntax::Methods
|
190
|
+
end
|
191
|
+
EOS
|
192
|
+
output = <<~EOS
|
193
|
+
RSpec.configure do |config|
|
194
|
+
config.include FactoryGirl::Syntax::Methods
|
195
|
+
end
|
196
|
+
EOS
|
201
197
|
expect(Dir).to receive(:glob).with('./spec/spec_helper.rb').and_return(['spec/spec_helper.rb'])
|
202
198
|
expect(File).to receive(:read).with('spec/spec_helper.rb').and_return(input)
|
203
199
|
expect(File).not_to receive(:write).with('spec/spec_helper.rb', output)
|
@@ -213,18 +209,16 @@ end
|
|
213
209
|
end
|
214
210
|
end
|
215
211
|
end
|
216
|
-
input =
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
end
|
227
|
-
'
|
212
|
+
input = <<~EOS
|
213
|
+
RSpec.configure do |config|
|
214
|
+
config.include FactoryGirl::Syntax::Methods
|
215
|
+
end
|
216
|
+
EOS
|
217
|
+
output = <<~EOS
|
218
|
+
RSpec.configure do |config|
|
219
|
+
config.include FactoryGirl::Syntax::Methods
|
220
|
+
end
|
221
|
+
EOS
|
228
222
|
expect(Dir).to receive(:glob).with('./spec/spec_helper.rb').and_return(['spec/spec_helper.rb']).twice
|
229
223
|
expect(File).to receive(:read).with('spec/spec_helper.rb').and_return(input).once
|
230
224
|
expect(File).not_to receive(:write).with('spec/spec_helper.rb', output)
|
@@ -239,22 +233,20 @@ end
|
|
239
233
|
replace_with 'create {{arguments}}'
|
240
234
|
end
|
241
235
|
end
|
242
|
-
input =
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
end
|
257
|
-
"
|
236
|
+
input = <<~EOS
|
237
|
+
it 'uses factory_girl' do
|
238
|
+
user = FactoryGirl.create :user
|
239
|
+
post = FactoryGirl.create :post, user: user
|
240
|
+
assert post.valid?
|
241
|
+
end
|
242
|
+
EOS
|
243
|
+
output = <<~EOS
|
244
|
+
it 'uses factory_girl' do
|
245
|
+
user = create :user
|
246
|
+
post = create :post, user: user
|
247
|
+
assert post.valid?
|
248
|
+
end
|
249
|
+
EOS
|
258
250
|
expect(Dir).to receive(:glob).with('./spec/**/*_spec.rb').and_return(['spec/models/post_spec.rb']).twice
|
259
251
|
expect(File).to receive(:read).with('spec/models/post_spec.rb').and_return(input)
|
260
252
|
expect(File).to receive(:write).with('spec/models/post_spec.rb', output)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: synvert-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.42.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Huang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|