synvert-core 1.24.0 → 1.26.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/Gemfile.lock +3 -3
- data/README.md +2 -1
- data/lib/synvert/core/engine/elegant.rb +5 -5
- data/lib/synvert/core/engine/erb.rb +2 -2
- data/lib/synvert/core/engine/haml.rb +1 -1
- data/lib/synvert/core/engine/slim.rb +7 -11
- data/lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb +1 -0
- data/lib/synvert/core/rewriter/instance.rb +21 -5
- data/lib/synvert/core/rewriter.rb +16 -0
- data/lib/synvert/core/version.rb +1 -1
- data/spec/synvert/core/engine/erb_spec.rb +4 -0
- data/spec/synvert/core/engine/haml_spec.rb +3 -3
- data/spec/synvert/core/engine/slim_spec.rb +3 -3
- data/spec/synvert/core/rewriter/instance_spec.rb +22 -8
- data/spec/synvert/core/rewriter_spec.rb +28 -1
- data/synvert-core-ruby.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 831aba295c622cf2e70df84432e246864f630adbdb1c3f4e13ac2e143e3f1c3e
|
4
|
+
data.tar.gz: 33c848691dfd2d638ac09e1f158d83c29d81c1a0ee025b79762cf6a28ebc62ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b92cc018fcf12791a0cc93d5f82bb2248188557c6f81ab706c444d82462086e1e0a53f77b3617ffd2be8edd0c14b4818e44285dd1aee8b3f89b506fb397e54e7
|
7
|
+
data.tar.gz: 855fa232ceed49e06dffc0a0f66d925383c67b18172cc99257e710f955c439fd0bdd0fd4d47111cb6bc4e0a3392481e6733951a9c2be1f28bdf990ac1e6182cd
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## 1.26.0 (2023-04-18)
|
4
|
+
|
5
|
+
* `add_file` and `remove_file` work for test
|
6
|
+
* Add `indent` dsl
|
7
|
+
* Add `type` to Action
|
8
|
+
* Update `node_mutation` to 1.15.3
|
9
|
+
|
10
|
+
## 1.25.0 (2023-04-17)
|
11
|
+
|
12
|
+
* Update `wrap` dsl
|
13
|
+
* Update `node_mutation` to 1.15.1
|
14
|
+
* Fix `erb` encoded source
|
15
|
+
|
3
16
|
## 1.24.0 (2023-04-16)
|
4
17
|
|
5
18
|
* Add `Slim` engine
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
synvert-core (1.
|
4
|
+
synvert-core (1.26.0)
|
5
5
|
activesupport (< 7.0.0)
|
6
|
-
node_mutation (>= 1.
|
6
|
+
node_mutation (>= 1.15.3)
|
7
7
|
node_query (>= 1.12.1)
|
8
8
|
parallel
|
9
9
|
parser
|
@@ -48,7 +48,7 @@ GEM
|
|
48
48
|
method_source (1.0.0)
|
49
49
|
minitest (5.18.0)
|
50
50
|
nenv (0.3.0)
|
51
|
-
node_mutation (1.
|
51
|
+
node_mutation (1.15.3)
|
52
52
|
node_query (1.12.1)
|
53
53
|
notiffany (0.1.3)
|
54
54
|
nenv (~> 0.1)
|
data/README.md
CHANGED
@@ -88,13 +88,14 @@ Actions:
|
|
88
88
|
|
89
89
|
* [append](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#append-instance_method) - append the code to the bottom of current node body
|
90
90
|
* [prepend](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#prepend-instance_method) - prepend the code to the bottom of current node body
|
91
|
+
* [indent](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#indent-instance_method) - indent code
|
91
92
|
* [insert](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#insert-instance_method) - insert code
|
92
93
|
* [insert_after](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#insert_after-instance_method) - insert the code next to the current node
|
93
94
|
* [insert_before](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#insert_before-instance_method) - insert the code previous to the current node
|
94
95
|
* [replace](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#replace-instance_method) - replace the code of specified child nodes
|
95
96
|
* [delete](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#delete-instance_method) - delete the code in specified child nodes
|
96
97
|
* [remove](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#remove-instance_method) - remove the whole code of current node
|
97
|
-
* [wrap](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#wrap-instance_method) - wrap the current node with code
|
98
|
+
* [wrap](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#wrap-instance_method) - wrap the current node with prefix and suffix code
|
98
99
|
* [replace_with](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#replace_with-instance_method) - replace the whole code of current node
|
99
100
|
* [warn](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#warn-instance_method) - warn message
|
100
101
|
* [replace_erb_stmt_with_expr](https://xinminlabs.github.io/synvert-core-ruby/Synvert/Core/Rewriter/Instance.html#replace_erb_stmt_with_expr-instance_method) - replace erb stmt code to expr code
|
@@ -94,14 +94,14 @@ module Synvert::Core
|
|
94
94
|
new_code << END_LINE
|
95
95
|
end
|
96
96
|
while scanner.scan(/(.*?)(\\*)#\{/) # it matches interpolation " #{current_user.login}"
|
97
|
-
new_code << WHITESPACE * scanner.matched.size
|
97
|
+
new_code << (WHITESPACE * scanner.matched.size)
|
98
98
|
unless scanner.matched[-3] == '\\'
|
99
99
|
count = 1
|
100
100
|
while scanner.scan(/.*?([\{\}])/)
|
101
101
|
if scanner.matched[-1] == '}'
|
102
102
|
count -= 1
|
103
103
|
if count == 0
|
104
|
-
new_code << scanner.matched[0..-2] + ';'
|
104
|
+
new_code << (scanner.matched[0..-2] + ';')
|
105
105
|
break
|
106
106
|
else
|
107
107
|
new_code << scanner.matched
|
@@ -114,12 +114,12 @@ module Synvert::Core
|
|
114
114
|
end
|
115
115
|
end
|
116
116
|
if scanner.scan(/.*?\z/)
|
117
|
-
new_code << WHITESPACE * scanner.matched.size
|
117
|
+
new_code << (WHITESPACE * scanner.matched.size)
|
118
118
|
end
|
119
119
|
if scanner.scan(/.*?\n/)
|
120
|
-
new_code << WHITESPACE * (scanner.matched.size - 1) + "\n"
|
120
|
+
new_code << ((WHITESPACE * (scanner.matched.size - 1)) + "\n")
|
121
121
|
end
|
122
122
|
end
|
123
123
|
end
|
124
124
|
end
|
125
|
-
end
|
125
|
+
end
|
@@ -9,9 +9,9 @@ module Synvert::Core
|
|
9
9
|
# @param source [String] erb code.
|
10
10
|
# @return [String] encoded ruby code.
|
11
11
|
def encode(source)
|
12
|
-
source.gsub(/%>.*?<%=?/m) { |str| replace_all_code_but_white_space_characters(str) }
|
12
|
+
source.gsub(/%>.*?<%=?/m) { |str| ';' + replace_all_code_but_white_space_characters(str[1..-1]) }
|
13
13
|
.sub(/^.*?<%=?/m) { |str| replace_all_code_but_white_space_characters(str) }
|
14
|
-
.sub(/%>.*?$/m) { |str| replace_all_code_but_white_space_characters(str) }
|
14
|
+
.sub(/%>.*?$/m) { |str| ';' + replace_all_code_but_white_space_characters(str[1..-1]) }
|
15
15
|
end
|
16
16
|
|
17
17
|
# Generate an empty proc.
|
@@ -25,7 +25,7 @@ module Synvert::Core
|
|
25
25
|
new_code << WHITESPACE
|
26
26
|
scan_ruby_expression(scanner, new_code, leading_spaces_counts, leading_spaces_count)
|
27
27
|
elsif scanner.scan(/[%#\.][a-zA-Z0-9\-_%#\.]+/) # it matches element, id and class " %span.user"
|
28
|
-
new_code << WHITESPACE * scanner.matched.size
|
28
|
+
new_code << (WHITESPACE * scanner.matched.size)
|
29
29
|
scan_matching_wrapper(scanner, new_code, '{', '}')
|
30
30
|
if scanner.scan('=')
|
31
31
|
new_code << WHITESPACE
|
@@ -6,11 +6,7 @@ module Synvert::Core
|
|
6
6
|
class << self
|
7
7
|
include Elegant
|
8
8
|
|
9
|
-
ATTRIBUTES_PAIR = {
|
10
|
-
'{' => '}',
|
11
|
-
'[' => ']',
|
12
|
-
'(' => ')'
|
13
|
-
}
|
9
|
+
ATTRIBUTES_PAIR = { '{' => '}', '[' => ']', '(' => ')' }
|
14
10
|
|
15
11
|
# Encode haml string, leave only ruby code, replace other haml code with whitespace.
|
16
12
|
# And insert `end\n` for each if, unless, begin, case to make it a valid ruby code.
|
@@ -28,16 +24,16 @@ module Synvert::Core
|
|
28
24
|
new_code << WHITESPACE
|
29
25
|
scan_ruby_statement(scanner, new_code, leading_spaces_counts, leading_spaces_count)
|
30
26
|
elsif scanner.scan(/==?/) # it matches ruby expression " = current_user.login"
|
31
|
-
new_code << WHITESPACE * scanner.matched.size
|
27
|
+
new_code << (WHITESPACE * scanner.matched.size)
|
32
28
|
scan_ruby_expression(scanner, new_code, leading_spaces_counts, leading_spaces_count)
|
33
29
|
elsif scanner.scan(/[a-z#\.][a-zA-Z0-9\-_%#\.]*/) # it matches element, id and class " span.user"
|
34
|
-
new_code << WHITESPACE * scanner.matched.size
|
30
|
+
new_code << (WHITESPACE * scanner.matched.size)
|
35
31
|
ATTRIBUTES_PAIR.each do |start, ending| # it matches attributes in brackets " span[ class='user' ]"
|
36
32
|
scan_matching_wrapper(scanner, new_code, start, ending)
|
37
33
|
end
|
38
34
|
scan_attributes_between_whitespace(scanner, new_code)
|
39
35
|
if scanner.scan(/ ?==?/) # it matches ruby expression " span= current_user.login"
|
40
|
-
new_code << WHITESPACE * scanner.matched.size
|
36
|
+
new_code << (WHITESPACE * scanner.matched.size)
|
41
37
|
scan_ruby_expression(scanner, new_code, leading_spaces_counts, leading_spaces_count)
|
42
38
|
else
|
43
39
|
scan_ruby_interpolation_and_plain_text(scanner, new_code, leading_spaces_counts, leading_spaces_count)
|
@@ -64,7 +60,7 @@ module Synvert::Core
|
|
64
60
|
while scanner.scan(/.*?[#{Regexp.quote(start)}#{Regexp.quote(ending)}]/m)
|
65
61
|
matched = scanner.matched.gsub(/(\A| ).*?=/) { |key| WHITESPACE * key.size }
|
66
62
|
if scanner.matched[-1] == ending
|
67
|
-
new_code << matched[0..-2] + ';'
|
63
|
+
new_code << (matched[0..-2] + ';')
|
68
64
|
count -= 1
|
69
65
|
break if count == 0
|
70
66
|
else
|
@@ -77,7 +73,7 @@ module Synvert::Core
|
|
77
73
|
|
78
74
|
def scan_attributes_between_whitespace(scanner, new_code)
|
79
75
|
while scanner.scan(/ ?[\w\-_]+==?/) # it matches attributes split by space " span class='user'"
|
80
|
-
new_code << WHITESPACE * scanner.matched.size
|
76
|
+
new_code << (WHITESPACE * scanner.matched.size)
|
81
77
|
stack = []
|
82
78
|
while scanner.scan(/(.*?['"\(\)\[\]\{\}]|.+?\b)/)
|
83
79
|
matched = scanner.matched
|
@@ -86,7 +82,7 @@ module Synvert::Core
|
|
86
82
|
stack << matched[-1]
|
87
83
|
elsif [')', ']', '}'].include?(matched[-1])
|
88
84
|
stack.pop
|
89
|
-
elsif %w['
|
85
|
+
elsif %w[' "].include?(matched[-1])
|
90
86
|
stack.last == matched[-1] ? stack.pop : stack << matched[-1]
|
91
87
|
end
|
92
88
|
break if stack.empty?
|
@@ -362,7 +362,7 @@ module Synvert::Core
|
|
362
362
|
@current_mutation.delete(@current_node, *selectors, and_comma: and_comma)
|
363
363
|
end
|
364
364
|
|
365
|
-
# It wraps current node with code.
|
365
|
+
# It wraps current node with prefix and suffix code.
|
366
366
|
# @example
|
367
367
|
# # class Foobar
|
368
368
|
# # end
|
@@ -372,11 +372,27 @@ module Synvert::Core
|
|
372
372
|
# # end
|
373
373
|
# # end
|
374
374
|
# within_node type: 'class' do
|
375
|
-
# wrap with: 'module Synvert'
|
375
|
+
# wrap with: 'module Synvert', and: 'end', newline: true
|
376
376
|
# end
|
377
|
-
# @param
|
378
|
-
|
379
|
-
|
377
|
+
# @param prefix [String] prefix code need to be wrapped with.
|
378
|
+
# @param suffix [String] suffix code need to be wrapped with.
|
379
|
+
# @param newline [Boolean] if wrap code in newline, default is false
|
380
|
+
def wrap(prefix:, suffix:, newline: false)
|
381
|
+
@current_mutation.wrap(@current_node, prefix: prefix, suffix: suffix, newline: newline)
|
382
|
+
end
|
383
|
+
|
384
|
+
# It indent the code of current node.
|
385
|
+
# @example
|
386
|
+
# # class Foobar
|
387
|
+
# # end
|
388
|
+
# # =>
|
389
|
+
# # class Foobar
|
390
|
+
# # end
|
391
|
+
# within_node type: 'class' do
|
392
|
+
# indent
|
393
|
+
# end
|
394
|
+
def indent(tab_size: 1)
|
395
|
+
@current_mutation.indent(@current_node, tab_size: tab_size)
|
380
396
|
end
|
381
397
|
|
382
398
|
# No operation.
|
@@ -264,6 +264,14 @@ module Synvert::Core
|
|
264
264
|
def add_file(filename, content)
|
265
265
|
return unless @options[:run_instance]
|
266
266
|
|
267
|
+
unless @options[:write_to_file]
|
268
|
+
result = NodeMutation::Result.new(affected: true, conflicted: false)
|
269
|
+
result.actions = [NodeMutation::Struct::Action.new(:add_file, 0, 0, content)]
|
270
|
+
result.file_path = filename
|
271
|
+
@test_results << result
|
272
|
+
return
|
273
|
+
end
|
274
|
+
|
267
275
|
filepath = File.join(Configuration.root_path, filename)
|
268
276
|
if File.exist?(filepath)
|
269
277
|
puts "File #{filepath} already exists."
|
@@ -283,6 +291,14 @@ module Synvert::Core
|
|
283
291
|
def remove_file(filename)
|
284
292
|
return unless @options[:run_instance]
|
285
293
|
|
294
|
+
unless @options[:write_to_file]
|
295
|
+
result = NodeMutation::Result.new(affected: true, conflicted: false)
|
296
|
+
result.actions = [NodeMutation::Struct::Action.new(:remove_file, 0, -1)]
|
297
|
+
result.file_path = filename
|
298
|
+
@test_results << result
|
299
|
+
return
|
300
|
+
end
|
301
|
+
|
286
302
|
file_path = File.join(Configuration.root_path, filename)
|
287
303
|
File.delete(file_path) if File.exist?(file_path)
|
288
304
|
end
|
data/lib/synvert/core/version.rb
CHANGED
@@ -20,6 +20,8 @@ module Synvert::Core
|
|
20
20
|
bar = 'foo'
|
21
21
|
%>
|
22
22
|
|
23
|
+
<%= user.first_name %> <%= user.last_name %>
|
24
|
+
|
23
25
|
<% if User.current &&
|
24
26
|
User.current.admin %>
|
25
27
|
<%= rounded_content("page") do %>
|
@@ -40,6 +42,8 @@ module Synvert::Core
|
|
40
42
|
expect(encoded_source).to be_include 'post = Post.find(:first)'
|
41
43
|
expect(encoded_source).to be_include "link_to_function 'test', \"confirm('test');\""
|
42
44
|
expect(encoded_source).to be_include 'end'
|
45
|
+
expect(encoded_source).to be_include 'user.first_name ;'
|
46
|
+
expect(encoded_source).to be_include 'user.last_name ;'
|
43
47
|
expect(encoded_source).not_to be_include 'style'
|
44
48
|
expect(encoded_source).not_to be_include 'div'
|
45
49
|
end
|
@@ -217,11 +217,11 @@ module Synvert::Core
|
|
217
217
|
EOS
|
218
218
|
proc = Engine::Haml.generate_transform_proc(encoded_source)
|
219
219
|
actions = [
|
220
|
-
NodeMutation::Struct::Action.new(50, 55, ''),
|
220
|
+
NodeMutation::Struct::Action.new(:delete, 50, 55, ''),
|
221
221
|
# first end position is 69
|
222
|
-
NodeMutation::Struct::Action.new(100, 105, ''),
|
222
|
+
NodeMutation::Struct::Action.new(:delete, 100, 105, ''),
|
223
223
|
# second end position is 111
|
224
|
-
NodeMutation::Struct::Action.new(120, 125, '')
|
224
|
+
NodeMutation::Struct::Action.new(:delete, 120, 125, '')
|
225
225
|
]
|
226
226
|
proc.call(actions)
|
227
227
|
expect(actions.first.start).to eq 50
|
@@ -204,11 +204,11 @@ module Synvert::Core
|
|
204
204
|
EOS
|
205
205
|
proc = Engine::Slim.generate_transform_proc(encoded_source)
|
206
206
|
actions = [
|
207
|
-
NodeMutation::Struct::Action.new(50, 55, ''),
|
207
|
+
NodeMutation::Struct::Action.new(:delete, 50, 55, ''),
|
208
208
|
# first end position is 69
|
209
|
-
NodeMutation::Struct::Action.new(100, 105, ''),
|
209
|
+
NodeMutation::Struct::Action.new(:delete, 100, 105, ''),
|
210
210
|
# second end position is 111
|
211
|
-
NodeMutation::Struct::Action.new(120, 125, '')
|
211
|
+
NodeMutation::Struct::Action.new(:delete, 120, 125, '')
|
212
212
|
]
|
213
213
|
proc.call(actions)
|
214
214
|
expect(actions.first.start).to eq 50
|
@@ -233,14 +233,26 @@ module Synvert::Core
|
|
233
233
|
instance.delete :dot, :message, and_comma: true
|
234
234
|
end
|
235
235
|
|
236
|
-
it 'parses wrap
|
236
|
+
it 'parses wrap' do
|
237
237
|
instance.instance_variable_set(:@current_mutation, double)
|
238
238
|
instance.current_node = double
|
239
239
|
expect(instance.instance_variable_get(:@current_mutation)).to receive(:wrap).with(
|
240
240
|
instance.current_node,
|
241
|
-
|
241
|
+
prefix: 'module Foobar',
|
242
|
+
suffix: 'end',
|
243
|
+
newline: true
|
242
244
|
)
|
243
|
-
instance.wrap
|
245
|
+
instance.wrap prefix: 'module Foobar', suffix: 'end', newline: true
|
246
|
+
end
|
247
|
+
|
248
|
+
it 'parses indent' do
|
249
|
+
instance.instance_variable_set(:@current_mutation, double)
|
250
|
+
instance.current_node = double
|
251
|
+
expect(instance.instance_variable_get(:@current_mutation)).to receive(:indent).with(
|
252
|
+
instance.current_node,
|
253
|
+
tab_size: 1
|
254
|
+
)
|
255
|
+
instance.indent
|
244
256
|
end
|
245
257
|
|
246
258
|
it 'parses noop' do
|
@@ -428,8 +440,8 @@ module Synvert::Core
|
|
428
440
|
results = instance.test
|
429
441
|
expect(results.file_path).to eq 'spec/models/post_spec.rb'
|
430
442
|
expect(results.actions).to eq [
|
431
|
-
NodeMutation::Struct::Action.new(35, 59, 'create :user'),
|
432
|
-
NodeMutation::Struct::Action.new(69, 105, 'create :post, user: user')
|
443
|
+
NodeMutation::Struct::Action.new(:replace, 35, 59, 'create :user'),
|
444
|
+
NodeMutation::Struct::Action.new(:replace, 69, 105, 'create :post, user: user')
|
433
445
|
]
|
434
446
|
end
|
435
447
|
|
@@ -467,7 +479,7 @@ module Synvert::Core
|
|
467
479
|
allow(File).to receive(:read).with('./app/views/posts/_form.html.erb', encoding: 'UTF-8').and_return(input)
|
468
480
|
result = instance.test
|
469
481
|
expect(result.file_path).to eq 'app/views/posts/_form.html.erb'
|
470
|
-
expect(result.actions).to eq [NodeMutation::Struct::Action.new(2, 2, '=')]
|
482
|
+
expect(result.actions).to eq [NodeMutation::Struct::Action.new(:insert, 2, 2, '=')]
|
471
483
|
end
|
472
484
|
|
473
485
|
it 'updates haml file' do
|
@@ -489,8 +501,9 @@ module Synvert::Core
|
|
489
501
|
result = instance.test
|
490
502
|
expect(result.file_path).to eq 'app/views/posts/_form.html.haml'
|
491
503
|
expect(result.actions).to eq [
|
492
|
-
NodeMutation::Struct::Action.new("= form_for ".length, "= form_for @post".length, 'post'),
|
504
|
+
NodeMutation::Struct::Action.new(:replace, "= form_for ".length, "= form_for @post".length, 'post'),
|
493
505
|
NodeMutation::Struct::Action.new(
|
506
|
+
:replace,
|
494
507
|
"= form_for @post do |f|\n= form_for ".length,
|
495
508
|
"= form_for @post do |f|\n= form_for @post".length,
|
496
509
|
'post'
|
@@ -517,8 +530,9 @@ module Synvert::Core
|
|
517
530
|
result = instance.test
|
518
531
|
expect(result.file_path).to eq 'app/views/posts/_form.html.slim'
|
519
532
|
expect(result.actions).to eq [
|
520
|
-
NodeMutation::Struct::Action.new("= form_for ".length, "= form_for @post".length, 'post'),
|
533
|
+
NodeMutation::Struct::Action.new(:replace, "= form_for ".length, "= form_for @post".length, 'post'),
|
521
534
|
NodeMutation::Struct::Action.new(
|
535
|
+
:replace,
|
522
536
|
"= form_for @post do |f|\n= form_for ".length,
|
523
537
|
"= form_for @post do |f|\n= form_for @post".length,
|
524
538
|
'post'
|
@@ -68,7 +68,7 @@ module Synvert::Core
|
|
68
68
|
expect(results[0].file_path).to eq '/code.rb'
|
69
69
|
expect(results[0].affected?).to be_truthy
|
70
70
|
expect(results[0].conflicted?).to be_falsey
|
71
|
-
expect(results[0].actions).to eq [NodeMutation::Struct::Action.new(6, 12, 'Synvert')]
|
71
|
+
expect(results[0].actions).to eq [NodeMutation::Struct::Action.new(:replace, 6, 12, 'Synvert')]
|
72
72
|
end
|
73
73
|
end
|
74
74
|
end
|
@@ -169,6 +169,18 @@ module Synvert::Core
|
|
169
169
|
rewriter.process_with_sandbox
|
170
170
|
expect(File.exist?('./foo.bar')).to be_falsey
|
171
171
|
end
|
172
|
+
|
173
|
+
it 'returns test result' do
|
174
|
+
rewriter =
|
175
|
+
Rewriter.new 'group', 'rewriter2' do
|
176
|
+
add_file 'foo.bar', 'FooBar'
|
177
|
+
end
|
178
|
+
result = rewriter.test
|
179
|
+
expect(result[0].file_path).to eq 'foo.bar'
|
180
|
+
expect(result[0].affected?).to be_truthy
|
181
|
+
expect(result[0].conflicted?).to be_falsey
|
182
|
+
expect(result[0].actions).to eq [NodeMutation::Struct::Action.new(:add_file, 0, 0, 'FooBar')]
|
183
|
+
end
|
172
184
|
end
|
173
185
|
|
174
186
|
describe 'parses remove_file' do
|
@@ -201,6 +213,21 @@ module Synvert::Core
|
|
201
213
|
expect(File.exist?('./foo.bar')).to be_truthy
|
202
214
|
FileUtils.rm './foo.bar'
|
203
215
|
end
|
216
|
+
|
217
|
+
it 'returns test result' do
|
218
|
+
File.write './foo.bar', 'FooBar'
|
219
|
+
rewriter =
|
220
|
+
Rewriter.new 'group', 'rewriter2' do
|
221
|
+
remove_file 'foo.bar'
|
222
|
+
end
|
223
|
+
result = rewriter.test
|
224
|
+
expect(result[0].file_path).to eq 'foo.bar'
|
225
|
+
expect(result[0].affected?).to be_truthy
|
226
|
+
expect(result[0].conflicted?).to be_falsey
|
227
|
+
expect(result[0].actions).to eq [NodeMutation::Struct::Action.new(:remove_file, 0, -1, nil)]
|
228
|
+
expect(File.exist?('./foo.bar')).to be_truthy
|
229
|
+
FileUtils.rm './foo.bar'
|
230
|
+
end
|
204
231
|
end
|
205
232
|
|
206
233
|
describe 'parses add_snippet' do
|
data/synvert-core-ruby.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.add_runtime_dependency "activesupport", "< 7.0.0"
|
23
23
|
spec.add_runtime_dependency "node_query", ">= 1.12.1"
|
24
|
-
spec.add_runtime_dependency "node_mutation", ">= 1.
|
24
|
+
spec.add_runtime_dependency "node_mutation", ">= 1.15.3"
|
25
25
|
spec.add_runtime_dependency "parser"
|
26
26
|
spec.add_runtime_dependency "parser_node_ext", ">= 1.0.0"
|
27
27
|
spec.add_runtime_dependency "parallel"
|
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: 1.
|
4
|
+
version: 1.26.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: 2023-04-
|
11
|
+
date: 2023-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.
|
47
|
+
version: 1.15.3
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.
|
54
|
+
version: 1.15.3
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: parser
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|