synvert-core 0.61.0 → 0.61.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/synvert/core/rewriter/action/append_action.rb +1 -1
- data/lib/synvert/core/rewriter/action/prepend_action.rb +5 -1
- data/lib/synvert/core/version.rb +1 -1
- data/spec/synvert/core/rewriter/action/append_action_spec.rb +21 -0
- data/spec/synvert/core/rewriter/action/prepend_action_spec.rb +84 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2496379cf2e2ab4bfd7df1466e0780965830a34601ce0e4dce0a8d23975e9a9
|
4
|
+
data.tar.gz: a59a23e473d98e05415aeb053202a4334e0527c6055b9f5f32415c0e29b3224c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90a027ececec24e20efd6f9e35517e1557393f2f3d1831da52cac012cc953d1f387ab1cdbba779f559f48e73643d8774013b418da40d3c3ae5f33b8a361d4edc
|
7
|
+
data.tar.gz: ffa1b43ec24296c9fd3f0b684b25f80de7459f0007dd3fb157df899ecc6610b4f22a83624ad2fc5da964a685bcaef3c697e28dade547587816b4d1b010b05149
|
data/CHANGELOG.md
CHANGED
@@ -17,7 +17,7 @@ module Synvert::Core
|
|
17
17
|
# @param node [Parser::AST::Node]
|
18
18
|
# @return [String] n times whitesphace
|
19
19
|
def indent(node)
|
20
|
-
if %i[block class].include? node.type
|
20
|
+
if %i[block class def defs].include? node.type
|
21
21
|
' ' * (node.column + DEFAULT_INDENT)
|
22
22
|
else
|
23
23
|
' ' * node.column
|
@@ -16,6 +16,10 @@ module Synvert::Core
|
|
16
16
|
end
|
17
17
|
when :class
|
18
18
|
@node.children[1] ? @node.children[1].loc.expression.end_pos : @node.children[0].loc.expression.end_pos
|
19
|
+
when :def
|
20
|
+
@node.children[1].empty? ? @node.loc.name.end_pos : @node.children[1].loc.expression.end_pos
|
21
|
+
when :defs
|
22
|
+
@node.children[2].empty? ? @node.loc.name.end_pos : @node.children[2].loc.expression.end_pos
|
19
23
|
else
|
20
24
|
@node.children.last.loc.expression.end_pos
|
21
25
|
end
|
@@ -29,7 +33,7 @@ module Synvert::Core
|
|
29
33
|
# @param node [Parser::AST::Node]
|
30
34
|
# @return [String] n times whitesphace
|
31
35
|
def indent(node)
|
32
|
-
if %i[block class].include?
|
36
|
+
if %i[block class def defs].include?(node.type)
|
33
37
|
' ' * (node.column + DEFAULT_INDENT)
|
34
38
|
else
|
35
39
|
' ' * node.column
|
data/lib/synvert/core/version.rb
CHANGED
@@ -45,5 +45,26 @@ module Synvert::Core
|
|
45
45
|
expect(subject.rewritten_code).to eq "\ngem 'twitter'"
|
46
46
|
end
|
47
47
|
end
|
48
|
+
|
49
|
+
describe 'def node' do
|
50
|
+
subject do
|
51
|
+
source = "def teardown\n do_something\nend"
|
52
|
+
class_node = Parser::CurrentRuby.parse(source)
|
53
|
+
instance = double(current_node: class_node)
|
54
|
+
Rewriter::AppendAction.new(instance, 'super').process
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'gets begin_pos' do
|
58
|
+
expect(subject.begin_pos).to eq "def teardown\n do_something".length
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'gets end_pos' do
|
62
|
+
expect(subject.end_pos).to eq "def teardown\n do_something".length
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'gets rewritten_code' do
|
66
|
+
expect(subject.rewritten_code).to eq "\n super"
|
67
|
+
end
|
68
|
+
end
|
48
69
|
end
|
49
70
|
end
|
@@ -87,5 +87,89 @@ module Synvert::Core
|
|
87
87
|
expect(subject.rewritten_code).to eq "\n include Deletable"
|
88
88
|
end
|
89
89
|
end
|
90
|
+
|
91
|
+
describe 'def node without args' do
|
92
|
+
subject do
|
93
|
+
source = "def setup\n do_something\nend"
|
94
|
+
def_node = Parser::CurrentRuby.parse(source)
|
95
|
+
instance = double(current_node: def_node)
|
96
|
+
Rewriter::PrependAction.new(instance, 'super').process
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'gets begin_pos' do
|
100
|
+
expect(subject.begin_pos).to eq 'def setup'.length
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'gets end_pos' do
|
104
|
+
expect(subject.end_pos).to eq 'def setup'.length
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'gets rewritten_code' do
|
108
|
+
expect(subject.rewritten_code).to eq "\n super"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe 'def node with args' do
|
113
|
+
subject do
|
114
|
+
source = "def setup(foobar)\n do_something\nend"
|
115
|
+
def_node = Parser::CurrentRuby.parse(source)
|
116
|
+
instance = double(current_node: def_node)
|
117
|
+
Rewriter::PrependAction.new(instance, 'super').process
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'gets begin_pos' do
|
121
|
+
expect(subject.begin_pos).to eq 'def setup(foobar)'.length
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'gets end_pos' do
|
125
|
+
expect(subject.end_pos).to eq 'def setup(foobar)'.length
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'gets rewritten_code' do
|
129
|
+
expect(subject.rewritten_code).to eq "\n super"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe 'defs node without args' do
|
134
|
+
subject do
|
135
|
+
source = "def self.foo\n do_something\nend"
|
136
|
+
def_node = Parser::CurrentRuby.parse(source)
|
137
|
+
instance = double(current_node: def_node)
|
138
|
+
Rewriter::PrependAction.new(instance, 'do_something_first').process
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'gets begin_pos' do
|
142
|
+
expect(subject.begin_pos).to eq 'def self.foo'.length
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'gets end_pos' do
|
146
|
+
expect(subject.end_pos).to eq 'def self.foo'.length
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'gets rewritten_code' do
|
150
|
+
expect(subject.rewritten_code).to eq "\n do_something_first"
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe 'defs node with args' do
|
155
|
+
subject do
|
156
|
+
source = "def self.foo(bar)\n do_something\nend"
|
157
|
+
def_node = Parser::CurrentRuby.parse(source)
|
158
|
+
instance = double(current_node: def_node)
|
159
|
+
Rewriter::PrependAction.new(instance, 'do_something_first').process
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'gets begin_pos' do
|
163
|
+
expect(subject.begin_pos).to eq 'def self.foo(bar)'.length
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'gets end_pos' do
|
167
|
+
expect(subject.end_pos).to eq 'def self.foo(bar)'.length
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'gets rewritten_code' do
|
171
|
+
expect(subject.rewritten_code).to eq "\n do_something_first"
|
172
|
+
end
|
173
|
+
end
|
90
174
|
end
|
91
175
|
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.61.
|
4
|
+
version: 0.61.1
|
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-12-
|
11
|
+
date: 2021-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|