synvert-core 0.45.2 → 0.46.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 425514bc071364c9908b0eff57e626c19fecf611ce3504dd51875af747969aea
4
- data.tar.gz: 2120c05146eab24a6f6c36c9213fcce70ed3102862b1f572d2ba208659b8053a
3
+ metadata.gz: 5251fd7b7ac886ba35aeb23c94e8d25bf2d26e2124db5d454d8994bdc5cecff3
4
+ data.tar.gz: 5b8395085acf698b7715a3cd48e3d22539308cc81e1731081c3b48dd00210ba7
5
5
  SHA512:
6
- metadata.gz: 65ff93235c9c5a437017f59a4e63fc6ef0a569b4b4f9de6cf23cbb0bf8203c796ea8cdd564ee4a434b87fb4346b0569140f4b75e94ebacfea1dc3cb3e54168f2
7
- data.tar.gz: 5902bcfda3dfe77f362df46e1e8dcad4c269ff5057827936279ebfb8dcd82b19fe6b01e6e52db190d1a7b8d40233a8b15b03864191070e8ef2da8deeb0161ca3
6
+ metadata.gz: 65e5e5a87c8bbe7d5d824d216c02764042f4b585705887a1a1c69469e389273b8e5ccfc00c3af2dc1003b660d49751c6365ff176980a72f6d663bfc1df60c31b
7
+ data.tar.gz: 9c47b80c577c5595c665658bf824c0f0f635c7bc09ceee6b0e865c636b4445d28fd449087e8eededc51d9d34eb2ab9fcd19899af676a228850ae630e3c10a726
data/CHANGELOG.md CHANGED
@@ -1,11 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 0.45.2 (2021-07-24)
3
+ ## 0.46.0 (2021-07-25)
4
4
 
5
+ * Add `strip_curly_braces` and `wrap_curly_braces` for `hash` node
5
6
  * Simplify symbol `match_value?`
6
-
7
- ## 0.45.1 (2021-07-24)
8
-
9
7
  * Unwrap quote when matching string value
10
8
 
11
9
  ## 0.45.0 (2021-07-22)
@@ -490,6 +490,20 @@ module Parser::AST
490
490
  end
491
491
  end
492
492
 
493
+ # strip curly braces for hash
494
+ def strip_curly_braces
495
+ return to_source unless type == :hash
496
+
497
+ to_source.sub(/^{(.*)}$/) { Regexp.last_match(1).strip }
498
+ end
499
+
500
+ # wrap curly braces for hash
501
+ def wrap_curly_braces
502
+ return to_source unless type == :hash
503
+
504
+ "{ #{to_source} }"
505
+ end
506
+
493
507
  private
494
508
 
495
509
  # Compare actual value with expected value.
@@ -66,7 +66,7 @@ module Synvert::Core
66
66
  # strip_brackets("(1..100)") #=> "1..100"
67
67
  def strip_brackets(code)
68
68
  code.sub(/^\((.*)\)$/) { Regexp.last_match(1) }.sub(/^\[(.*)\]$/) { Regexp.last_match(1) }.sub(/^{(.*)}$/) {
69
- Regexp.last_match(1)
69
+ Regexp.last_match(1).strip
70
70
  }
71
71
  end
72
72
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '0.45.2'
5
+ VERSION = '0.46.0'
6
6
  end
7
7
  end
@@ -679,4 +679,37 @@ describe Parser::AST::Node do
679
679
  EOS
680
680
  end
681
681
  end
682
+
683
+ describe '#strip_curly_braces' do
684
+ context 'hash node' do
685
+ it 'removes curly braces' do
686
+ node = parse("{ foo: 'bar' }")
687
+ expect(node.strip_curly_braces).to eq("foo: 'bar'")
688
+ end
689
+ end
690
+
691
+ context 'other node' do
692
+ it 'do nothing' do
693
+ node = parse("'foobar'")
694
+ expect(node.strip_curly_braces).to eq("'foobar'")
695
+ end
696
+ end
697
+ end
698
+
699
+ describe '#wrap_curly_braces' do
700
+ context 'hash node' do
701
+ it 'adds curly braces' do
702
+ node = parse("test(foo: 'bar')").arguments.first
703
+ expect(node.to_source).to eq("foo: 'bar'")
704
+ expect(node.wrap_curly_braces).to eq("{ foo: 'bar' }")
705
+ end
706
+ end
707
+
708
+ context 'other node' do
709
+ it 'do nothing' do
710
+ node = parse("'foobar'")
711
+ expect(node.wrap_curly_braces).to eq("'foobar'")
712
+ end
713
+ end
714
+ end
682
715
  end
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.45.2
4
+ version: 0.46.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-24 00:00:00.000000000 Z
11
+ date: 2021-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport