unparser 0.4.3 → 0.4.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -57,11 +57,82 @@ describe Unparser, mutant_expression: 'Unparser::Emitter*' do
57
57
 
58
58
  describe '.parse' do
59
59
  def apply
60
- described_class.parse('self[1]=2')
60
+ described_class.parse(source)
61
61
  end
62
62
 
63
- it 'returns expected AST' do
64
- expect(apply).to eql(s(:indexasgn, s(:self), s(:int, 1), s(:int, 2)))
63
+ context 'on present source' do
64
+ let(:source) { 'self[1]=2' }
65
+
66
+ it 'returns expected AST' do
67
+ expect(apply).to eql(s(:indexasgn, s(:self), s(:int, 1), s(:int, 2)))
68
+ end
69
+ end
70
+
71
+ context 'on empty source' do
72
+ let(:source) { '' }
73
+
74
+ it 'returns ni' do
75
+ expect(apply).to be(nil)
76
+ end
77
+ end
78
+
79
+ context 'on syntax error' do
80
+ let(:source) { '[' }
81
+
82
+ it 'raises error' do
83
+ expect { apply }.to raise_error(Parser::SyntaxError)
84
+ end
85
+ end
86
+ end
87
+
88
+ describe '.parse_either' do
89
+ def apply
90
+ described_class.parse_either(source)
91
+ end
92
+
93
+ context 'on present source' do
94
+ let(:source) { 'self[1]=2' }
95
+
96
+ it 'returns right value with expected AST' do
97
+ expect(apply).to eql(MPrelude::Either::Right.new(s(:indexasgn, s(:self), s(:int, 1), s(:int, 2))))
98
+ end
99
+ end
100
+
101
+ context 'on empty source' do
102
+ let(:source) { '' }
103
+
104
+ it 'returns right value with nil' do
105
+ expect(apply).to eql(MPrelude::Either::Right.new(nil))
106
+ end
107
+ end
108
+
109
+ context 'on syntax error' do
110
+ let(:source) { '[' }
111
+
112
+ it 'returns left value with syntax error' do
113
+ result = apply
114
+
115
+ # Syntax errors that compare nicely under #eql? are hard to construct
116
+ expect(result).to be_instance_of(MPrelude::Either::Left)
117
+ expect(result.from_left).to be_instance_of(Parser::SyntaxError)
118
+ end
119
+ end
120
+ end
121
+
122
+ describe '.unparse' do
123
+ context 'on unknown node type' do
124
+ def apply
125
+ Unparser.unparse(node)
126
+ end
127
+
128
+ let(:node) { s(:example_node) }
129
+
130
+ it 'raises UnknownNodeError' do
131
+ expect { apply }.to raise_error(
132
+ Unparser::UnknownNodeError,
133
+ 'Unknown node type: :example_node'
134
+ )
135
+ end
65
136
  end
66
137
  end
67
138
 
@@ -265,6 +336,7 @@ describe Unparser, mutant_expression: 'Unparser::Emitter*' do
265
336
  end
266
337
 
267
338
  context 'irange' do
339
+ assert_unterminated '1..'
268
340
  assert_unterminated '1..2'
269
341
  assert_unterminated '(0.0 / 0.0)..1'
270
342
  assert_unterminated '1..(0.0 / 0.0)'
@@ -272,6 +344,7 @@ describe Unparser, mutant_expression: 'Unparser::Emitter*' do
272
344
  end
273
345
 
274
346
  context 'erange' do
347
+ assert_unterminated '1...'
275
348
  assert_unterminated '1...2'
276
349
  end
277
350
 
@@ -547,12 +620,6 @@ describe Unparser, mutant_expression: 'Unparser::Emitter*' do
547
620
  foo.bar(*args)
548
621
  RUBY
549
622
 
550
- assert_source <<~'RUBY'
551
- foo.bar do |(a)|
552
- d
553
- end
554
- RUBY
555
-
556
623
  assert_source <<~'RUBY'
557
624
  foo.bar do |(a, b), c|
558
625
  d
@@ -574,6 +641,18 @@ describe Unparser, mutant_expression: 'Unparser::Emitter*' do
574
641
  end
575
642
  RUBY
576
643
 
644
+ assert_source <<~'RUBY'
645
+ foo.bar do |*|
646
+ d
647
+ end
648
+ RUBY
649
+
650
+ assert_source <<~'RUBY'
651
+ foo.bar do |(*)|
652
+ d
653
+ end
654
+ RUBY
655
+
577
656
  assert_source <<~'RUBY'
578
657
  foo.bar do |((*))|
579
658
  d
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'unparser'
3
- gem.version = '0.4.3'
3
+ gem.version = '0.4.8'
4
4
 
5
5
  gem.authors = ['Markus Schirp']
6
6
  gem.email = 'mbj@schirp-dso.com'
@@ -18,13 +18,18 @@ Gem::Specification.new do |gem|
18
18
 
19
19
  gem.add_dependency('abstract_type', '~> 0.0.7')
20
20
  gem.add_dependency('adamantium', '~> 0.2.0')
21
- gem.add_dependency('equalizer', '~> 0.0.9')
22
- gem.add_dependency('diff-lcs', '~> 1.3')
21
+ gem.add_dependency('anima', '~> 0.3.1')
23
22
  gem.add_dependency('concord', '~> 0.1.5')
24
- gem.add_dependency('parser', '~> 2.6.0')
23
+ gem.add_dependency('diff-lcs', '~> 1.3')
24
+ gem.add_dependency('equalizer', '~> 0.0.9')
25
+ gem.add_dependency('mprelude', '~> 0.1.0')
26
+ gem.add_dependency('parser', '>= 2.6.5')
25
27
  gem.add_dependency('procto', '~> 0.0.2')
26
28
 
27
- gem.add_development_dependency('anima', '~> 0.3.1')
28
- gem.add_development_dependency('devtools', '~> 0.1.23')
29
- gem.add_development_dependency('morpher', '~> 0.2.6')
29
+ gem.add_development_dependency('mutant', '~> 0.9.9')
30
+ gem.add_development_dependency('mutant-rspec', '~> 0.9.9')
31
+ gem.add_development_dependency('rspec', '~> 3.9')
32
+ gem.add_development_dependency('rspec-core', '~> 3.9')
33
+ gem.add_development_dependency('rspec-its', '~> 1.2.0')
34
+ gem.add_development_dependency('rubocop', '~> 0.79.0')
30
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Markus Schirp
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-24 00:00:00.000000000 Z
11
+ date: 2020-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: abstract_type
@@ -39,19 +39,33 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.2.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: equalizer
42
+ name: anima
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.0.9
47
+ version: 0.3.1
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: 0.0.9
54
+ version: 0.3.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: concord
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.5
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.5
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: diff-lcs
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -67,33 +81,47 @@ dependencies:
67
81
  - !ruby/object:Gem::Version
68
82
  version: '1.3'
69
83
  - !ruby/object:Gem::Dependency
70
- name: concord
84
+ name: equalizer
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: 0.1.5
89
+ version: 0.0.9
76
90
  type: :runtime
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: 0.1.5
96
+ version: 0.0.9
83
97
  - !ruby/object:Gem::Dependency
84
- name: parser
98
+ name: mprelude
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: 2.6.0
103
+ version: 0.1.0
90
104
  type: :runtime
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: 2.6.0
110
+ version: 0.1.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: parser
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 2.6.5
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 2.6.5
97
125
  - !ruby/object:Gem::Dependency
98
126
  name: procto
99
127
  requirement: !ruby/object:Gem::Requirement
@@ -109,47 +137,89 @@ dependencies:
109
137
  - !ruby/object:Gem::Version
110
138
  version: 0.0.2
111
139
  - !ruby/object:Gem::Dependency
112
- name: anima
140
+ name: mutant
113
141
  requirement: !ruby/object:Gem::Requirement
114
142
  requirements:
115
143
  - - "~>"
116
144
  - !ruby/object:Gem::Version
117
- version: 0.3.1
145
+ version: 0.9.9
118
146
  type: :development
119
147
  prerelease: false
120
148
  version_requirements: !ruby/object:Gem::Requirement
121
149
  requirements:
122
150
  - - "~>"
123
151
  - !ruby/object:Gem::Version
124
- version: 0.3.1
152
+ version: 0.9.9
153
+ - !ruby/object:Gem::Dependency
154
+ name: mutant-rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 0.9.9
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 0.9.9
167
+ - !ruby/object:Gem::Dependency
168
+ name: rspec
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '3.9'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '3.9'
181
+ - !ruby/object:Gem::Dependency
182
+ name: rspec-core
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '3.9'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '3.9'
125
195
  - !ruby/object:Gem::Dependency
126
- name: devtools
196
+ name: rspec-its
127
197
  requirement: !ruby/object:Gem::Requirement
128
198
  requirements:
129
199
  - - "~>"
130
200
  - !ruby/object:Gem::Version
131
- version: 0.1.23
201
+ version: 1.2.0
132
202
  type: :development
133
203
  prerelease: false
134
204
  version_requirements: !ruby/object:Gem::Requirement
135
205
  requirements:
136
206
  - - "~>"
137
207
  - !ruby/object:Gem::Version
138
- version: 0.1.23
208
+ version: 1.2.0
139
209
  - !ruby/object:Gem::Dependency
140
- name: morpher
210
+ name: rubocop
141
211
  requirement: !ruby/object:Gem::Requirement
142
212
  requirements:
143
213
  - - "~>"
144
214
  - !ruby/object:Gem::Version
145
- version: 0.2.6
215
+ version: 0.79.0
146
216
  type: :development
147
217
  prerelease: false
148
218
  version_requirements: !ruby/object:Gem::Requirement
149
219
  requirements:
150
220
  - - "~>"
151
221
  - !ruby/object:Gem::Version
152
- version: 0.2.6
222
+ version: 0.79.0
153
223
  description: Generate equivalent source for parser gem AST nodes
154
224
  email: mbj@schirp-dso.com
155
225
  executables:
@@ -158,7 +228,7 @@ extensions: []
158
228
  extra_rdoc_files:
159
229
  - README.md
160
230
  files:
161
- - ".circleci/config.yml"
231
+ - ".github/workflows/ci.yml"
162
232
  - ".gitignore"
163
233
  - ".rspec"
164
234
  - ".rubocop.yml"
@@ -174,18 +244,16 @@ files:
174
244
  - config/flog.yml
175
245
  - config/mutant.yml
176
246
  - config/reek.yml
177
- - config/rubocop.yml
178
247
  - config/yardstick.yml
179
248
  - lib/unparser.rb
180
249
  - lib/unparser/ast.rb
181
250
  - lib/unparser/ast/local_variable_scope.rb
182
251
  - lib/unparser/buffer.rb
183
252
  - lib/unparser/cli.rb
184
- - lib/unparser/cli/color.rb
185
- - lib/unparser/cli/differ.rb
186
- - lib/unparser/cli/source.rb
253
+ - lib/unparser/color.rb
187
254
  - lib/unparser/comments.rb
188
255
  - lib/unparser/constants.rb
256
+ - lib/unparser/diff.rb
189
257
  - lib/unparser/dsl.rb
190
258
  - lib/unparser/emitter.rb
191
259
  - lib/unparser/emitter/alias.rb
@@ -242,6 +310,7 @@ files:
242
310
  - lib/unparser/finalize.rb
243
311
  - lib/unparser/node_helpers.rb
244
312
  - lib/unparser/preprocessor.rb
313
+ - lib/unparser/validation.rb
245
314
  - spec/integration/unparser/corpus_spec.rb
246
315
  - spec/integrations.yml
247
316
  - spec/spec_helper.rb
@@ -253,18 +322,21 @@ files:
253
322
  - spec/unit/unparser/buffer/indent_spec.rb
254
323
  - spec/unit/unparser/buffer/nl_spec.rb
255
324
  - spec/unit/unparser/buffer/unindent_spec.rb
325
+ - spec/unit/unparser/color_spec.rb
256
326
  - spec/unit/unparser/comments/consume_spec.rb
257
327
  - spec/unit/unparser/comments/take_all_spec.rb
258
328
  - spec/unit/unparser/comments/take_before_spec.rb
259
329
  - spec/unit/unparser/comments/take_eol_comments_spec.rb
330
+ - spec/unit/unparser/diff_spec.rb
260
331
  - spec/unit/unparser/emitter/class_methods/handle_spec.rb
332
+ - spec/unit/unparser/validation_spec.rb
261
333
  - spec/unit/unparser_spec.rb
262
334
  - unparser.gemspec
263
335
  homepage: http://github.com/mbj/unparser
264
336
  licenses:
265
337
  - MIT
266
338
  metadata: {}
267
- post_install_message:
339
+ post_install_message:
268
340
  rdoc_options: []
269
341
  require_paths:
270
342
  - lib
@@ -279,8 +351,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
279
351
  - !ruby/object:Gem::Version
280
352
  version: '0'
281
353
  requirements: []
282
- rubygems_version: 3.0.1
283
- signing_key:
354
+ rubygems_version: 3.0.3
355
+ signing_key:
284
356
  specification_version: 4
285
357
  summary: Generate equivalent source for parser gem AST nodes
286
358
  test_files:
@@ -295,9 +367,12 @@ test_files:
295
367
  - spec/unit/unparser/buffer/indent_spec.rb
296
368
  - spec/unit/unparser/buffer/nl_spec.rb
297
369
  - spec/unit/unparser/buffer/unindent_spec.rb
370
+ - spec/unit/unparser/color_spec.rb
298
371
  - spec/unit/unparser/comments/consume_spec.rb
299
372
  - spec/unit/unparser/comments/take_all_spec.rb
300
373
  - spec/unit/unparser/comments/take_before_spec.rb
301
374
  - spec/unit/unparser/comments/take_eol_comments_spec.rb
375
+ - spec/unit/unparser/diff_spec.rb
302
376
  - spec/unit/unparser/emitter/class_methods/handle_spec.rb
377
+ - spec/unit/unparser/validation_spec.rb
303
378
  - spec/unit/unparser_spec.rb