synvert-core 1.30.3 → 1.31.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: 2c2557aab985fb34048581b6b768d40c012a8f4e2403987a43350c837890d991
4
- data.tar.gz: 2f9d14d1c0632282d9d5d259dc21a25db4f245b4aa44302baabfa63e14a4f25a
3
+ metadata.gz: 3346883848c81ac9a130e077d0aae4eec34df1fcc365c95b9971b558b346f1a9
4
+ data.tar.gz: 15f5f83ef0d59c08edcf2cd076a36d0e057e94fee8d0435ca679c1a3e094dd01
5
5
  SHA512:
6
- metadata.gz: dbe85c0e46b4eff9be065c257105a4d22f15d1ee14ebacb0a3b6a638c8727862f984358e4204b3551ea567323eab784f35e1274f50c9ab8b2cad3417cbcdc299
7
- data.tar.gz: 0a8ffa195df715505e6fdd5e7aa2694b9a34aba1ea4ba0e34256fca5763a4d9a722fdb16e2a417a28eb9fa197e3b3e597708103bb2bc9989773dfe2d9f15ca89
6
+ metadata.gz: a24728c75868284ed17baa5cdc9b9ab1d0961ba560ea00f7a71eaf0fe4bf3a01f322435002a9911e934d87a51a744f77b1c21b54bb8126739d31e0a50a9a991c
7
+ data.tar.gz: 65505c1d4f55b82d789f119463d535a67c11c85f18cbcbb0d7311d572f23e42085b44477d7d70c14e4019511cf5db7c502ac2e7278f0481720aaf64da7031e1f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.31.0 (2024-01-14)
4
+
5
+ * Support `Configuration.test_result` in `add_file` and `remove_file` dsl
6
+ * Get new source in `Rewriter#test`
7
+
3
8
  ## 1.30.3 (2024-01-13)
4
9
 
5
10
  * Add `Configuration.test_result` option
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- synvert-core (1.30.3)
4
+ synvert-core (1.31.0)
5
5
  activesupport (< 7.0.0)
6
6
  node_mutation (>= 1.21.6)
7
7
  node_query (>= 1.13.12)
@@ -149,22 +149,26 @@ module Synvert::Core
149
149
  if !@affected_files.empty? && @redo_until_no_change # redo
150
150
  test
151
151
  end
152
- @test_results.map do |filename, test_results|
153
- new_actions = test_results.map(&:actions).flatten.sort_by(&:end)
154
- last_start = -1
155
- conflicted =
156
- new_actions.any? do |action|
157
- if last_start > action.end
158
- true
159
- else
160
- last_start = action.start
161
- false
152
+ if Configuration.test_result == 'new_source'
153
+ @test_results.values.flatten
154
+ else
155
+ @test_results.map do |filename, test_results|
156
+ new_actions = test_results.map(&:actions).flatten.sort_by(&:end)
157
+ last_start = -1
158
+ conflicted =
159
+ new_actions.any? do |action|
160
+ if last_start > action.end
161
+ true
162
+ else
163
+ last_start = action.start
164
+ false
165
+ end
162
166
  end
163
- end
164
- result = NodeMutation::Result.new(affected: true, conflicted: conflicted)
165
- result.actions = new_actions
166
- result.file_path = filename
167
- result
167
+ result = NodeMutation::Result.new(affected: true, conflicted: conflicted)
168
+ result.actions = new_actions
169
+ result.file_path = filename
170
+ result
171
+ end
168
172
  end
169
173
  end
170
174
 
@@ -289,7 +293,11 @@ module Synvert::Core
289
293
 
290
294
  unless @options[:write_to_file]
291
295
  result = NodeMutation::Result.new(affected: true, conflicted: false)
292
- result.actions = [NodeMutation::Struct::Action.new(:add_file, 0, 0, content)]
296
+ if Configuration.test_result == 'new_source'
297
+ result.new_source = content
298
+ else
299
+ result.actions = [NodeMutation::Struct::Action.new(:add_file, 0, 0, content)]
300
+ end
293
301
  result.file_path = filename
294
302
  merge_test_result(result)
295
303
  return
@@ -316,7 +324,11 @@ module Synvert::Core
316
324
 
317
325
  unless @options[:write_to_file]
318
326
  result = NodeMutation::Result.new(affected: true, conflicted: false)
319
- result.actions = [NodeMutation::Struct::Action.new(:remove_file, 0, -1)]
327
+ if Configuration.test_result == 'new_source'
328
+ result.new_source = nil
329
+ else
330
+ result.actions = [NodeMutation::Struct::Action.new(:remove_file, 0, -1)]
331
+ end
320
332
  result.file_path = filename
321
333
  merge_test_result(result)
322
334
  return
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Synvert
4
4
  module Core
5
- VERSION = '1.30.3'
5
+ VERSION = '1.31.0'
6
6
  end
7
7
  end
@@ -456,7 +456,7 @@ module Synvert::Core
456
456
  before { Configuration.test_result = 'new_source' }
457
457
  after { Configuration.test_result = nil }
458
458
 
459
- it 'gets new_source if Configuration.test_result is new_source' do
459
+ it 'gets new_source' do
460
460
  instance =
461
461
  Rewriter::Instance.new rewriter, 'spec/models/post_spec.rb' do
462
462
  with_node type: 'send', receiver: 'FactoryGirl', message: 'create' do
@@ -100,6 +100,31 @@ module Synvert::Core
100
100
  expect(results[0].actions).to eq [NodeMutation::Struct::Action.new(:replace, 6, 12, 'Synvert')]
101
101
  end
102
102
  end
103
+
104
+ context 'Configuration.test_result is new_source' do
105
+ before { Configuration.test_result = 'new_source' }
106
+ after { Configuration.test_result = nil }
107
+
108
+ it 'gets test results with new_source' do
109
+ rewriter =
110
+ Rewriter.new('group', 'name') do
111
+ within_files '**/*.rb' do
112
+ with_node node_type: 'class', name: 'Foobar' do
113
+ replace :name, with: 'Synvert'
114
+ end
115
+ end
116
+ end
117
+ input = "class Foobar\nend"
118
+ FakeFS do
119
+ File.write("code.rb", input)
120
+ results = rewriter.test
121
+ expect(results[0].file_path).to eq '/code.rb'
122
+ expect(results[0].affected?).to be_truthy
123
+ expect(results[0].conflicted?).to be_falsey
124
+ expect(results[0].new_source).to eq "class Synvert\nend"
125
+ end
126
+ end
127
+ end
103
128
  end
104
129
 
105
130
  describe 'parses within_file' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synvert-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.30.3
4
+ version: 1.31.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang