synvert-core 0.47.0 → 0.50.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: c9673a5aa5ad59322786e09e99a527e7f7a7e05c7067200c9baed0602c7c1fe2
4
- data.tar.gz: e946fa740f8678faa4f1cb856c2d6a54b4b0c09ed10084110bb78648da1a7497
3
+ metadata.gz: 88e62c155c2171dfeda2631d99c88992f6ffbc9e0f50341d9db79262ef636ad2
4
+ data.tar.gz: 4dfec29835aa657065eb5aa35f16a804971674d81215f1b3c860dbe9b3db06fc
5
5
  SHA512:
6
- metadata.gz: cebcaad6d3a1162b0ceb8354ae2d598f18e70474e068b8a91cdea8440c83f02280afae97adb8c923a5dbe7750138f02e5b73a633f4b7dbd9dfa9b0c90962c14a
7
- data.tar.gz: b482a97216175c0a16492bdb23294acc33727493202c088d44a94fb73f15df6263d1addf2df5e2ef53cecc7147ff475e67c12e2eb9f3451b6c92b4b47eee42d4
6
+ metadata.gz: a95b38e7f84022599442040b6717e4551b7333cb28cf4337f1d0ab47610ea6ea7cec761490871579a57e25928758e8fd8f3973b56291f3198b5074f5633b0af5
7
+ data.tar.gz: e841587f4b654b76e0790f1272f1ff8fa2bdb2c747d1aae9126d51c4c22978ab12b393725e03118b104f6d573bfb7f63bdd2fa9eab36032a56db75958f4b7ac1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.50.0 (2021-08-11)
4
+
5
+ * Support `:module` in `body`
6
+ * Fix symbol match
7
+
8
+ ## 0.49.0 (2021-08-04)
9
+
10
+ * Support :erange in to_value
11
+ * Do not use to_value in match_value?
12
+
13
+ ## 0.48.0 (2021-08-01)
14
+
15
+ * Force to read file as utf-8
16
+ * Add logo
17
+
3
18
  ## 0.47.0 (2021-07-28)
4
19
 
5
20
  * Add `to_single_quote` to `str` node
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Synvert::Core
2
2
 
3
+ <img src="https://xinminlabs.github.io/synvert/img/logo_96.png" alt="logo" width="32" height="32" />
4
+
3
5
  ![Main workflow](https://github.com/xinminlabs/synvert-core/actions/workflows/main.yml/badge.svg)
4
6
  [![Coverage Status](https://coveralls.io/repos/xinminlabs/synvert-core/badge.png?branch=master)](https://coveralls.io/r/xinminlabs/synvert-core)
5
7
  [![Gem Version](https://badge.fury.io/rb/synvert-core.png)](http://badge.fury.io/rb/synvert-core)
@@ -35,5 +37,5 @@ Or install it yourself as:
35
37
  4. Push to the branch (`git push origin my-new-feature`)
36
38
  5. Create a new Pull Request
37
39
 
38
- [1]: http://xinminlabs.github.io/synvert/
39
- [2]: http://rubydoc.info/github/xinminlabs/synvert-core/master/frames
40
+ [1]: https://xinminlabs.github.io/synvert/
41
+ [2]: https://rubydoc.info/github/xinminlabs/synvert-core/master/frames
@@ -110,7 +110,7 @@ module Parser::AST
110
110
  case type
111
111
  when :begin
112
112
  children
113
- when :def, :block, :class
113
+ when :def, :block, :class, :module
114
114
  return [] if children[2].nil?
115
115
 
116
116
  :begin == children[2].type ? children[2].body : children[2..-1]
@@ -252,6 +252,8 @@ module Parser::AST
252
252
  children.map(&:to_value)
253
253
  when :irange
254
254
  (children.first.to_value..children.last.to_value)
255
+ when :erange
256
+ (children.first.to_value...children.last.to_value)
255
257
  when :begin
256
258
  children.first.to_value
257
259
  else
@@ -548,14 +550,14 @@ module Parser::AST
548
550
  case expected
549
551
  when Symbol
550
552
  if actual.is_a?(Parser::AST::Node)
551
- actual.to_value == expected
553
+ actual.to_source == ":#{expected}" || actual.to_source == expected.to_s
552
554
  else
553
555
  actual.to_sym == expected
554
556
  end
555
557
  when String
556
558
  if actual.is_a?(Parser::AST::Node)
557
- actual.to_source == expected || actual.to_value == expected ||
558
- actual.to_source == unwrap_quote(expected) || actual.to_value == unwrap_quote(expected)
559
+ actual.to_source == expected || actual.to_source == unwrap_quote(expected) ||
560
+ unwrap_quote(actual.to_source) == expected || unwrap_quote(actual.to_source) == unwrap_quote(expected)
559
561
  else
560
562
  actual.to_s == expected || wrap_quote(actual.to_s) == expected
561
563
  end
@@ -17,7 +17,7 @@ module Synvert::Core
17
17
  @file_source ||= {}
18
18
  @file_source[file_path] ||=
19
19
  begin
20
- source = File.read(file_path)
20
+ source = File.read(file_path, encoding: 'UTF-8')
21
21
  source = Engine::ERB.encode(source) if /\.erb$/.match?(file_path)
22
22
  source
23
23
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '0.47.0'
5
+ VERSION = '0.50.0'
6
6
  end
7
7
  end
@@ -151,6 +151,11 @@ describe Parser::AST::Node do
151
151
  expect(node.body).to be_empty
152
152
  end
153
153
 
154
+ it 'gets empty for module node' do
155
+ node = parse('module Admin; end')
156
+ expect(node.body).to be_empty
157
+ end
158
+
154
159
  it 'gets one line for class node' do
155
160
  node = parse('class User; attr_accessor :email; end')
156
161
  expect(node.body).to eq [parse('attr_accessor :email')]
@@ -316,18 +321,23 @@ describe Parser::AST::Node do
316
321
  expect(node.to_value).to eq :str
317
322
  end
318
323
 
319
- it 'get for boolean' do
324
+ it 'gets for boolean' do
320
325
  node = parse('true')
321
326
  expect(node.to_value).to be_truthy
322
327
  node = parse('false')
323
328
  expect(node.to_value).to be_falsey
324
329
  end
325
330
 
326
- it 'get for range' do
331
+ it 'gets for irange' do
327
332
  node = parse('(1..10)')
328
333
  expect(node.to_value).to eq(1..10)
329
334
  end
330
335
 
336
+ it 'gets for erange' do
337
+ node = parse('(1...10)')
338
+ expect(node.to_value).to eq(1...10)
339
+ end
340
+
331
341
  it 'gets for array' do
332
342
  node = parse("['str', :str]")
333
343
  expect(node.to_value).to eq ['str', :str]
@@ -418,6 +428,12 @@ describe Parser::AST::Node do
418
428
  expect(node).to be_match(type: 'send', receiver: 'params', message: '[]', arguments: [:user])
419
429
  end
420
430
 
431
+ it 'matches pair key with symbol' do
432
+ source = '{ type: :model }'
433
+ node = parse(source).children[0]
434
+ expect(node).to be_match(type: 'pair', key: :type)
435
+ end
436
+
421
437
  it 'matches assign number' do
422
438
  source = 'at_least(0)'
423
439
  node = parse(source)
@@ -170,7 +170,7 @@ module Synvert::Core
170
170
  end
171
171
  EOS
172
172
  expect(Dir).to receive(:glob).with('./spec/**/*_spec.rb').and_return(['spec/models/post_spec.rb'])
173
- expect(File).to receive(:read).with('spec/models/post_spec.rb').and_return(input)
173
+ expect(File).to receive(:read).with('spec/models/post_spec.rb', encoding: 'UTF-8').and_return(input)
174
174
  expect(File).to receive(:write).with('spec/models/post_spec.rb', output)
175
175
  instance.process
176
176
  end
@@ -195,7 +195,7 @@ module Synvert::Core
195
195
  end
196
196
  EOS
197
197
  expect(Dir).to receive(:glob).with('./spec/spec_helper.rb').and_return(['spec/spec_helper.rb'])
198
- expect(File).to receive(:read).with('spec/spec_helper.rb').and_return(input)
198
+ expect(File).to receive(:read).with('spec/spec_helper.rb', encoding: 'UTF-8').and_return(input)
199
199
  expect(File).not_to receive(:write).with('spec/spec_helper.rb', output)
200
200
  instance.process
201
201
  end
@@ -220,7 +220,7 @@ module Synvert::Core
220
220
  end
221
221
  EOS
222
222
  expect(Dir).to receive(:glob).with('./spec/spec_helper.rb').and_return(['spec/spec_helper.rb']).twice
223
- expect(File).to receive(:read).with('spec/spec_helper.rb').and_return(input).once
223
+ expect(File).to receive(:read).with('spec/spec_helper.rb', encoding: 'UTF-8').and_return(input).once
224
224
  expect(File).not_to receive(:write).with('spec/spec_helper.rb', output)
225
225
  instance.process
226
226
  instance.process
@@ -248,9 +248,9 @@ module Synvert::Core
248
248
  end
249
249
  EOS
250
250
  expect(Dir).to receive(:glob).with('./spec/**/*_spec.rb').and_return(['spec/models/post_spec.rb']).twice
251
- expect(File).to receive(:read).with('spec/models/post_spec.rb').and_return(input)
251
+ expect(File).to receive(:read).with('spec/models/post_spec.rb', encoding: 'UTF-8').and_return(input)
252
252
  expect(File).to receive(:write).with('spec/models/post_spec.rb', output)
253
- expect(File).to receive(:read).with('spec/models/post_spec.rb').and_return(output)
253
+ expect(File).to receive(:read).with('spec/models/post_spec.rb', encoding: 'UTF-8').and_return(output)
254
254
  instance.process
255
255
  instance.process
256
256
  expect(rewriter.affected_files).to be_include('spec/models/post_spec.rb')
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.47.0
4
+ version: 0.50.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-28 00:00:00.000000000 Z
11
+ date: 2021-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport