synvert-core 0.41.2 → 0.42.0

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: 9e9e29097976ca69f755a698d9a3a78769105c4043b07c96a7ac1e714ae659a0
4
- data.tar.gz: 12d45e30a5de2ffc03bb440b503ff1a230e7baa55eb6a69e43518023e7d24f08
3
+ metadata.gz: 19c77660c79cc18a6c2d720d7a8bada136dc0397a2cc73610cc87d3412ac5306
4
+ data.tar.gz: '083cc96fa1b41d83a4bd5c3512440ec88223bbc67969aca2d03dd58f87a26b24'
5
5
  SHA512:
6
- metadata.gz: 28802dbdd2f53b267c621f811b959a0041064f97ff4f54ee009f75d230eeb2a1ff3fbb9b1c3cee524d990f53b8e7447105fa57e86cb4ee2b042cd4e17ef63c9e
7
- data.tar.gz: 8c0f5604e24d9ea0034214aa2b4d36f26d6c5f181d7d0d70f75a78fe71b0cab1868379953b2d071ea3ab922e62855a51ee5a0cb14ed7b4e26ebb8cc57adcb396
6
+ metadata.gz: 6403332404a070851c4817321702097cbff8cc34f75bc23d8dba236be878c83948012f79ba36ed51bea4e275f61f4adf4a5b638e35b0c8fd88dfd370b720854f
7
+ data.tar.gz: dc6bbc40dc208bb9ed9b8f9003b7a11e59ece0e79fb8db3cc4466f7c5b6f70574f71a5c7e4e161e762498854954293105b2023a996802b2906df04af51286f9a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ # 0.42.0 (2021-07-11)
4
+
5
+ * Match string with quote
6
+ * `match_value?` returns true if actual and expected are the same
7
+
3
8
  ## 0.41.0 (2021-06-24)
4
9
 
5
10
  * Remove unused autoindent option
@@ -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
- raise Synvert::Core::MethodNotSupported, "to_value is not handled for #{debug_info}"
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '0.41.2'
5
+ VERSION = '0.42.0'
6
6
  end
7
7
  end
@@ -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
- it 'uses factory_girl' do
161
- user = FactoryGirl.create :user
162
- post = FactoryGirl.create :post, user: user
163
- assert post.valid?
164
- end
165
- "
166
- output =
167
- "
168
- it 'uses factory_girl' do
169
- user = create :user
170
- post = create :post, user: user
171
- assert post.valid?
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
- RSpec.configure do |config|
192
- config.include FactoryGirl::Syntax::Methods
193
- end
194
- '
195
- output =
196
- '
197
- RSpec.configure do |config|
198
- config.include FactoryGirl::Syntax::Methods
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
- RSpec.configure do |config|
219
- config.include FactoryGirl::Syntax::Methods
220
- end
221
- '
222
- output =
223
- '
224
- RSpec.configure do |config|
225
- config.include FactoryGirl::Syntax::Methods
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
- it 'uses factory_girl' do
245
- user = FactoryGirl.create :user
246
- post = FactoryGirl.create :post, user: user
247
- assert post.valid?
248
- end
249
- "
250
- output =
251
- "
252
- it 'uses factory_girl' do
253
- user = create :user
254
- post = create :post, user: user
255
- assert post.valid?
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.41.2
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-06 00:00:00.000000000 Z
11
+ date: 2021-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport