unparser 0.4.7 → 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
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'unparser'
3
- gem.version = '0.4.7'
3
+ gem.version = '0.4.8'
4
4
 
5
5
  gem.authors = ['Markus Schirp']
6
6
  gem.email = 'mbj@schirp-dso.com'
@@ -18,15 +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')
23
+ gem.add_dependency('diff-lcs', '~> 1.3')
24
+ gem.add_dependency('equalizer', '~> 0.0.9')
25
+ gem.add_dependency('mprelude', '~> 0.1.0')
24
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')
30
- gem.add_development_dependency('mutant', '~> 0.9.4')
31
- gem.add_development_dependency('mutant-rspec', '~> 0.9.4')
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')
32
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.7
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: 2020-01-04 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,19 +81,33 @@ 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
97
+ - !ruby/object:Gem::Dependency
98
+ name: mprelude
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.1.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.1.0
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: parser
85
113
  requirement: !ruby/object:Gem::Requirement
@@ -109,75 +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
125
153
  - !ruby/object:Gem::Dependency
126
- name: devtools
154
+ name: mutant-rspec
127
155
  requirement: !ruby/object:Gem::Requirement
128
156
  requirements:
129
157
  - - "~>"
130
158
  - !ruby/object:Gem::Version
131
- version: 0.1.23
159
+ version: 0.9.9
132
160
  type: :development
133
161
  prerelease: false
134
162
  version_requirements: !ruby/object:Gem::Requirement
135
163
  requirements:
136
164
  - - "~>"
137
165
  - !ruby/object:Gem::Version
138
- version: 0.1.23
166
+ version: 0.9.9
139
167
  - !ruby/object:Gem::Dependency
140
- name: morpher
168
+ name: rspec
141
169
  requirement: !ruby/object:Gem::Requirement
142
170
  requirements:
143
171
  - - "~>"
144
172
  - !ruby/object:Gem::Version
145
- version: 0.2.6
173
+ version: '3.9'
146
174
  type: :development
147
175
  prerelease: false
148
176
  version_requirements: !ruby/object:Gem::Requirement
149
177
  requirements:
150
178
  - - "~>"
151
179
  - !ruby/object:Gem::Version
152
- version: 0.2.6
180
+ version: '3.9'
153
181
  - !ruby/object:Gem::Dependency
154
- name: mutant
182
+ name: rspec-core
155
183
  requirement: !ruby/object:Gem::Requirement
156
184
  requirements:
157
185
  - - "~>"
158
186
  - !ruby/object:Gem::Version
159
- version: 0.9.4
187
+ version: '3.9'
160
188
  type: :development
161
189
  prerelease: false
162
190
  version_requirements: !ruby/object:Gem::Requirement
163
191
  requirements:
164
192
  - - "~>"
165
193
  - !ruby/object:Gem::Version
166
- version: 0.9.4
194
+ version: '3.9'
167
195
  - !ruby/object:Gem::Dependency
168
- name: mutant-rspec
196
+ name: rspec-its
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: 1.2.0
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: 1.2.0
209
+ - !ruby/object:Gem::Dependency
210
+ name: rubocop
169
211
  requirement: !ruby/object:Gem::Requirement
170
212
  requirements:
171
213
  - - "~>"
172
214
  - !ruby/object:Gem::Version
173
- version: 0.9.4
215
+ version: 0.79.0
174
216
  type: :development
175
217
  prerelease: false
176
218
  version_requirements: !ruby/object:Gem::Requirement
177
219
  requirements:
178
220
  - - "~>"
179
221
  - !ruby/object:Gem::Version
180
- version: 0.9.4
222
+ version: 0.79.0
181
223
  description: Generate equivalent source for parser gem AST nodes
182
224
  email: mbj@schirp-dso.com
183
225
  executables:
@@ -186,7 +228,7 @@ extensions: []
186
228
  extra_rdoc_files:
187
229
  - README.md
188
230
  files:
189
- - ".circleci/config.yml"
231
+ - ".github/workflows/ci.yml"
190
232
  - ".gitignore"
191
233
  - ".rspec"
192
234
  - ".rubocop.yml"
@@ -202,18 +244,16 @@ files:
202
244
  - config/flog.yml
203
245
  - config/mutant.yml
204
246
  - config/reek.yml
205
- - config/rubocop.yml
206
247
  - config/yardstick.yml
207
248
  - lib/unparser.rb
208
249
  - lib/unparser/ast.rb
209
250
  - lib/unparser/ast/local_variable_scope.rb
210
251
  - lib/unparser/buffer.rb
211
252
  - lib/unparser/cli.rb
212
- - lib/unparser/cli/color.rb
213
- - lib/unparser/cli/differ.rb
214
- - lib/unparser/cli/source.rb
253
+ - lib/unparser/color.rb
215
254
  - lib/unparser/comments.rb
216
255
  - lib/unparser/constants.rb
256
+ - lib/unparser/diff.rb
217
257
  - lib/unparser/dsl.rb
218
258
  - lib/unparser/emitter.rb
219
259
  - lib/unparser/emitter/alias.rb
@@ -270,6 +310,7 @@ files:
270
310
  - lib/unparser/finalize.rb
271
311
  - lib/unparser/node_helpers.rb
272
312
  - lib/unparser/preprocessor.rb
313
+ - lib/unparser/validation.rb
273
314
  - spec/integration/unparser/corpus_spec.rb
274
315
  - spec/integrations.yml
275
316
  - spec/spec_helper.rb
@@ -281,18 +322,21 @@ files:
281
322
  - spec/unit/unparser/buffer/indent_spec.rb
282
323
  - spec/unit/unparser/buffer/nl_spec.rb
283
324
  - spec/unit/unparser/buffer/unindent_spec.rb
325
+ - spec/unit/unparser/color_spec.rb
284
326
  - spec/unit/unparser/comments/consume_spec.rb
285
327
  - spec/unit/unparser/comments/take_all_spec.rb
286
328
  - spec/unit/unparser/comments/take_before_spec.rb
287
329
  - spec/unit/unparser/comments/take_eol_comments_spec.rb
330
+ - spec/unit/unparser/diff_spec.rb
288
331
  - spec/unit/unparser/emitter/class_methods/handle_spec.rb
332
+ - spec/unit/unparser/validation_spec.rb
289
333
  - spec/unit/unparser_spec.rb
290
334
  - unparser.gemspec
291
335
  homepage: http://github.com/mbj/unparser
292
336
  licenses:
293
337
  - MIT
294
338
  metadata: {}
295
- post_install_message:
339
+ post_install_message:
296
340
  rdoc_options: []
297
341
  require_paths:
298
342
  - lib
@@ -308,7 +352,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
308
352
  version: '0'
309
353
  requirements: []
310
354
  rubygems_version: 3.0.3
311
- signing_key:
355
+ signing_key:
312
356
  specification_version: 4
313
357
  summary: Generate equivalent source for parser gem AST nodes
314
358
  test_files:
@@ -323,9 +367,12 @@ test_files:
323
367
  - spec/unit/unparser/buffer/indent_spec.rb
324
368
  - spec/unit/unparser/buffer/nl_spec.rb
325
369
  - spec/unit/unparser/buffer/unindent_spec.rb
370
+ - spec/unit/unparser/color_spec.rb
326
371
  - spec/unit/unparser/comments/consume_spec.rb
327
372
  - spec/unit/unparser/comments/take_all_spec.rb
328
373
  - spec/unit/unparser/comments/take_before_spec.rb
329
374
  - spec/unit/unparser/comments/take_eol_comments_spec.rb
375
+ - spec/unit/unparser/diff_spec.rb
330
376
  - spec/unit/unparser/emitter/class_methods/handle_spec.rb
377
+ - spec/unit/unparser/validation_spec.rb
331
378
  - spec/unit/unparser_spec.rb
@@ -1,49 +0,0 @@
1
- defaults: &defaults
2
- working_directory: ~/unparser
3
- docker:
4
- - image: circleci/ruby:2.6.5
5
- version: 2
6
- jobs:
7
- unit_specs:
8
- <<: *defaults
9
- steps:
10
- - checkout
11
- - run: bundle install
12
- - run: bundle exec rspec spec/unit
13
- integration_specs:
14
- <<: *defaults
15
- steps:
16
- - checkout
17
- - run: bundle install
18
- - run: bundle exec rspec spec/integration
19
- metrics:
20
- <<: *defaults
21
- steps:
22
- - checkout
23
- - run: bundle install
24
- - run: bundle exec rake metrics:rubocop
25
- - run: bundle exec rake metrics:reek
26
- - run: bundle exec rake metrics:flay
27
- - run: bundle exec rake metrics:flog
28
- mutant:
29
- <<: *defaults
30
- steps:
31
- - checkout
32
- - run: bundle install
33
- - run: |
34
- bundle \
35
- exec \
36
- mutant \
37
- --ignore-subject 'Unparser::AST::LocalVariableScope*' \
38
- --since origin/master \
39
- --zombie \
40
- -- \
41
- 'Unparser*'
42
- workflows:
43
- version: 2
44
- test:
45
- jobs:
46
- - unit_specs
47
- - integration_specs
48
- - metrics
49
- - mutant
@@ -1,122 +0,0 @@
1
- inherit_from: ../.rubocop.yml
2
-
3
- AllCops:
4
- Include:
5
- - 'lib/unparser.rb'
6
- - 'lib/unparser/**/*.rb'
7
- - '**/*.rake'
8
- - 'Gemfile'
9
- - 'Gemfile.triage'
10
-
11
- # Avoid parameter lists longer than five parameters.
12
- ParameterLists:
13
- Max: 3
14
- CountKeywordArgs: true
15
-
16
- MethodLength:
17
- CountComments: false
18
- Max: 17
19
-
20
- AbcSize:
21
- Max: 18
22
-
23
- # Avoid more than `Max` levels of nesting.
24
- BlockNesting:
25
- Max: 3
26
-
27
- # Align with the style guide.
28
- CollectionMethods:
29
- PreferredMethods:
30
- collect: 'map'
31
- inject: 'reduce'
32
- find: 'detect'
33
- find_all: 'select'
34
-
35
- # Limit line length
36
- LineLength:
37
- Max: 113 # TODO: lower to 79 once the rubocop branch in shared/Gemfile is removed
38
-
39
- ClassLength:
40
- Max: 204
41
-
42
- # Prefer modifiers and explicit if statements over returning early for small methods
43
- GuardClause:
44
- Enabled: false
45
-
46
- Metrics/BlockLength:
47
- Exclude:
48
- # Ignore RSpec DSL
49
- - spec/**/*
50
-
51
- # Flags freezes for singletons that could still be mutated like Regexps
52
- RedundantFreeze:
53
- Enabled: false
54
-
55
- # Allow Fixnum and Bignum. This Gem supports versions before 2.4
56
- UnifiedInteger:
57
- Enabled: false
58
-
59
- # Disabled because of indenting with private keyword in class bodies.
60
- IndentationWidth:
61
- Enabled: false
62
-
63
- # I like raise more
64
- SignalException:
65
- Enabled: false
66
-
67
- # False positive in unparser source
68
- OneLineConditional:
69
- Enabled: false
70
-
71
- Documentation:
72
- Enabled: false
73
-
74
- # Disable documentation checking until a class needs to be documented once
75
- Documentation:
76
- Enabled: false
77
-
78
- # Do not favor modifier if/unless usage when you have a single-line body
79
- IfUnlessModifier:
80
- Enabled: false
81
-
82
- # Allow case equality operator (in limited use within the specs)
83
- CaseEquality:
84
- Enabled: false
85
-
86
- # Constants do not always have to use SCREAMING_SNAKE_CASE
87
- ConstantName:
88
- Enabled: false
89
-
90
- # Not all trivial readers/writers can be defined with attr_* methods
91
- TrivialAccessors:
92
- Enabled: false
93
-
94
- # I like to have an empty line before closing the currently opened body
95
- EmptyLinesAroundBlockBody:
96
- Enabled: false
97
-
98
- EmptyLinesAroundClassBody:
99
- Enabled: false
100
-
101
- EmptyLinesAroundModuleBody:
102
- Enabled: false
103
-
104
- # I like my style more
105
- AccessModifierIndentation:
106
- Enabled: false
107
-
108
- Style/CommentedKeyword:
109
- Enabled: false
110
-
111
- Style/MixinGrouping:
112
- Enabled: false
113
-
114
- Lint/BooleanSymbol:
115
- Enabled: false
116
-
117
- Style/AccessModifierDeclarations:
118
- Enabled: false
119
-
120
- Layout/AlignHash:
121
- EnforcedColonStyle: table
122
- EnforcedHashRocketStyle: table