unparser 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/Changelog.md +6 -0
- data/Gemfile +0 -2
- data/Gemfile.lock +166 -0
- data/README.md +9 -3
- data/Rakefile +10 -9
- data/config/devtools.yml +1 -1
- data/config/flay.yml +1 -1
- data/config/rubocop.yml +18 -0
- data/lib/unparser.rb +0 -1
- data/lib/unparser/ast.rb +1 -0
- data/lib/unparser/cli.rb +4 -3
- data/lib/unparser/cli/color.rb +2 -3
- data/lib/unparser/cli/differ.rb +45 -45
- data/lib/unparser/cli/source.rb +4 -5
- data/lib/unparser/comments.rb +3 -3
- data/lib/unparser/constants.rb +6 -0
- data/lib/unparser/emitter.rb +2 -2
- data/lib/unparser/emitter/argument.rb +1 -1
- data/lib/unparser/emitter/assignment.rb +1 -1
- data/lib/unparser/emitter/begin.rb +2 -3
- data/lib/unparser/emitter/empty.rb +1 -2
- data/lib/unparser/emitter/flow_modifier.rb +2 -2
- data/lib/unparser/emitter/literal/primitive.rb +15 -6
- data/lib/unparser/emitter/repetition.rb +3 -1
- data/lib/unparser/emitter/send/index.rb +3 -5
- data/lib/unparser/emitter/send/unary.rb +0 -3
- data/spec/integration/unparser/corpus_spec.rb +12 -11
- data/spec/integrations.yml +54 -8
- data/spec/unit/unparser_spec.rb +16 -1
- data/unparser.gemspec +3 -3
- metadata +16 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c3058b3246021ca8bbd7bc5aa6f8619b4fe66245
|
|
4
|
+
data.tar.gz: ef701ba495d7cb5805ebc64ec6021f6ccc4d76cc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 500cad862ca383cc943c2b4d2be2a46513013ee8874406b01e024fff47c1744bba91a7062a9cd28b8e10729549d4c24e68e42105cef336e756d8fe018fce542e
|
|
7
|
+
data.tar.gz: 585157bea807a765757e04d2fd0fb7bda10bf7467bff75a9569a36d0f3aa8c1bb1e8f34cac12ff14925b21a3bab00c8d435d18293f0a1267816ec40e7ff85946
|
data/.gitignore
CHANGED
data/Changelog.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
unparser (0.2.5)
|
|
5
|
+
abstract_type (~> 0.0.7)
|
|
6
|
+
adamantium (~> 0.2.0)
|
|
7
|
+
concord (~> 0.1.5)
|
|
8
|
+
diff-lcs (~> 1.3)
|
|
9
|
+
equalizer (~> 0.0.9)
|
|
10
|
+
parser (>= 2.3.1.2, < 2.5)
|
|
11
|
+
procto (~> 0.0.2)
|
|
12
|
+
|
|
13
|
+
GEM
|
|
14
|
+
remote: https://rubygems.org/
|
|
15
|
+
specs:
|
|
16
|
+
abstract_type (0.0.7)
|
|
17
|
+
adamantium (0.2.0)
|
|
18
|
+
ice_nine (~> 0.11.0)
|
|
19
|
+
memoizable (~> 0.4.0)
|
|
20
|
+
anima (0.3.0)
|
|
21
|
+
abstract_type (~> 0.0.7)
|
|
22
|
+
adamantium (~> 0.2)
|
|
23
|
+
equalizer (~> 0.0.11)
|
|
24
|
+
ast (2.3.0)
|
|
25
|
+
axiom-types (0.1.1)
|
|
26
|
+
descendants_tracker (~> 0.0.4)
|
|
27
|
+
ice_nine (~> 0.11.0)
|
|
28
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
|
29
|
+
codeclimate-engine-rb (0.4.0)
|
|
30
|
+
virtus (~> 1.0)
|
|
31
|
+
coercible (1.0.0)
|
|
32
|
+
descendants_tracker (~> 0.0.1)
|
|
33
|
+
concord (0.1.5)
|
|
34
|
+
adamantium (~> 0.2.0)
|
|
35
|
+
equalizer (~> 0.0.9)
|
|
36
|
+
descendants_tracker (0.0.4)
|
|
37
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
|
38
|
+
devtools (0.1.16)
|
|
39
|
+
adamantium (~> 0.2.0)
|
|
40
|
+
anima (~> 0.3.0)
|
|
41
|
+
concord (~> 0.1.5)
|
|
42
|
+
flay (~> 2.8.1)
|
|
43
|
+
flog (~> 4.4.0)
|
|
44
|
+
mutant (~> 0.8.11)
|
|
45
|
+
mutant-rspec (~> 0.8.11)
|
|
46
|
+
procto (~> 0.0.3)
|
|
47
|
+
rake (~> 11.3.0)
|
|
48
|
+
reek (~> 4.5.0)
|
|
49
|
+
rspec (~> 3.5.0)
|
|
50
|
+
rspec-core (~> 3.5.4)
|
|
51
|
+
rspec-its (~> 1.2.0)
|
|
52
|
+
rubocop (~> 0.47.0)
|
|
53
|
+
simplecov (~> 0.12.0)
|
|
54
|
+
yard (~> 0.9.1)
|
|
55
|
+
yardstick (~> 0.9.9)
|
|
56
|
+
diff-lcs (1.3)
|
|
57
|
+
docile (1.1.5)
|
|
58
|
+
equalizer (0.0.11)
|
|
59
|
+
erubis (2.7.0)
|
|
60
|
+
flay (2.8.1)
|
|
61
|
+
erubis (~> 2.7.0)
|
|
62
|
+
path_expander (~> 1.0)
|
|
63
|
+
ruby_parser (~> 3.0)
|
|
64
|
+
sexp_processor (~> 4.0)
|
|
65
|
+
flog (4.4.1)
|
|
66
|
+
path_expander (~> 1.0)
|
|
67
|
+
ruby_parser (~> 3.1, > 3.1.0)
|
|
68
|
+
sexp_processor (~> 4.4)
|
|
69
|
+
ice_nine (0.11.2)
|
|
70
|
+
json (2.0.3)
|
|
71
|
+
memoizable (0.4.2)
|
|
72
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
|
73
|
+
morpher (0.2.6)
|
|
74
|
+
abstract_type (~> 0.0.7)
|
|
75
|
+
adamantium (~> 0.2.0)
|
|
76
|
+
anima (~> 0.3.0)
|
|
77
|
+
ast (~> 2.2)
|
|
78
|
+
concord (~> 0.1.5)
|
|
79
|
+
equalizer (~> 0.0.9)
|
|
80
|
+
ice_nine (~> 0.11.0)
|
|
81
|
+
procto (~> 0.0.2)
|
|
82
|
+
mutant (0.8.12)
|
|
83
|
+
abstract_type (~> 0.0.7)
|
|
84
|
+
adamantium (~> 0.2.0)
|
|
85
|
+
anima (~> 0.3.0)
|
|
86
|
+
ast (~> 2.2)
|
|
87
|
+
concord (~> 0.1.5)
|
|
88
|
+
diff-lcs (~> 1.2)
|
|
89
|
+
equalizer (~> 0.0.9)
|
|
90
|
+
ice_nine (~> 0.11.1)
|
|
91
|
+
memoizable (~> 0.4.2)
|
|
92
|
+
morpher (~> 0.2.6)
|
|
93
|
+
parallel (~> 1.3)
|
|
94
|
+
parser (~> 2.3.1, >= 2.3.1.4)
|
|
95
|
+
procto (~> 0.0.2)
|
|
96
|
+
regexp_parser (~> 0.3.6)
|
|
97
|
+
unparser (~> 0.2.5)
|
|
98
|
+
mutant-rspec (0.8.11)
|
|
99
|
+
mutant (~> 0.8.11)
|
|
100
|
+
rspec-core (>= 3.4.0, < 3.6.0)
|
|
101
|
+
parallel (1.10.0)
|
|
102
|
+
parser (2.3.3.1)
|
|
103
|
+
ast (~> 2.2)
|
|
104
|
+
path_expander (1.0.1)
|
|
105
|
+
powerpack (0.1.1)
|
|
106
|
+
procto (0.0.3)
|
|
107
|
+
rainbow (2.2.1)
|
|
108
|
+
rake (11.3.0)
|
|
109
|
+
reek (4.5.4)
|
|
110
|
+
codeclimate-engine-rb (~> 0.4.0)
|
|
111
|
+
parser (~> 2.3.1, >= 2.3.1.2)
|
|
112
|
+
rainbow (~> 2.0)
|
|
113
|
+
regexp_parser (0.3.6)
|
|
114
|
+
rspec (3.5.0)
|
|
115
|
+
rspec-core (~> 3.5.0)
|
|
116
|
+
rspec-expectations (~> 3.5.0)
|
|
117
|
+
rspec-mocks (~> 3.5.0)
|
|
118
|
+
rspec-core (3.5.4)
|
|
119
|
+
rspec-support (~> 3.5.0)
|
|
120
|
+
rspec-expectations (3.5.0)
|
|
121
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
122
|
+
rspec-support (~> 3.5.0)
|
|
123
|
+
rspec-its (1.2.0)
|
|
124
|
+
rspec-core (>= 3.0.0)
|
|
125
|
+
rspec-expectations (>= 3.0.0)
|
|
126
|
+
rspec-mocks (3.5.0)
|
|
127
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
128
|
+
rspec-support (~> 3.5.0)
|
|
129
|
+
rspec-support (3.5.0)
|
|
130
|
+
rubocop (0.47.1)
|
|
131
|
+
parser (>= 2.3.3.1, < 3.0)
|
|
132
|
+
powerpack (~> 0.1)
|
|
133
|
+
rainbow (>= 1.99.1, < 3.0)
|
|
134
|
+
ruby-progressbar (~> 1.7)
|
|
135
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
|
136
|
+
ruby-progressbar (1.8.1)
|
|
137
|
+
ruby_parser (3.8.4)
|
|
138
|
+
sexp_processor (~> 4.1)
|
|
139
|
+
sexp_processor (4.7.0)
|
|
140
|
+
simplecov (0.12.0)
|
|
141
|
+
docile (~> 1.1.0)
|
|
142
|
+
json (>= 1.8, < 3)
|
|
143
|
+
simplecov-html (~> 0.10.0)
|
|
144
|
+
simplecov-html (0.10.0)
|
|
145
|
+
thread_safe (0.3.5)
|
|
146
|
+
unicode-display_width (1.1.3)
|
|
147
|
+
virtus (1.0.5)
|
|
148
|
+
axiom-types (~> 0.1)
|
|
149
|
+
coercible (~> 1.0)
|
|
150
|
+
descendants_tracker (~> 0.0, >= 0.0.3)
|
|
151
|
+
equalizer (~> 0.0, >= 0.0.9)
|
|
152
|
+
yard (0.9.8)
|
|
153
|
+
yardstick (0.9.9)
|
|
154
|
+
yard (~> 0.8, >= 0.8.7.2)
|
|
155
|
+
|
|
156
|
+
PLATFORMS
|
|
157
|
+
ruby
|
|
158
|
+
|
|
159
|
+
DEPENDENCIES
|
|
160
|
+
anima (~> 0.3.0)
|
|
161
|
+
devtools (~> 0.1.3)
|
|
162
|
+
morpher (~> 0.2.6)
|
|
163
|
+
unparser!
|
|
164
|
+
|
|
165
|
+
BUNDLED WITH
|
|
166
|
+
1.13.7
|
data/README.md
CHANGED
|
@@ -9,14 +9,20 @@ unparser
|
|
|
9
9
|
Generate equivalent source for ASTs from whitequarks [parser](https://github.com/whitequark/parser).
|
|
10
10
|
Excluding the macruby extensions the parser gem implemnents on top of ruby syntax.
|
|
11
11
|
|
|
12
|
-
Excluding the MacRuby / RubyMotion extensions the parser gem implemenents on top of MRI
|
|
13
|
-
If you feel the need to get them supported, contact me.
|
|
12
|
+
Excluding the MacRuby / RubyMotion extensions the parser gem implemenents on top of MRI Ruby
|
|
13
|
+
syntax starting with parser release 2.3. If you feel the need to get them supported, contact me.
|
|
14
14
|
|
|
15
|
-
This library is able to reproduce 100% of
|
|
15
|
+
This library is able to reproduce 100% of Ruby 2.1 - 2.3 syntax. Including its own source code.
|
|
16
16
|
|
|
17
17
|
It serves well for [mutant](https://github.com/mbj/mutant) mutators and the in-memory vendoring for self hosting,
|
|
18
18
|
and other tooling.
|
|
19
19
|
|
|
20
|
+
Public API:
|
|
21
|
+
-----------
|
|
22
|
+
|
|
23
|
+
While unparser is in the `0.x` versions its public API can change any moment. I recommend to use `~> 0.x.y` style
|
|
24
|
+
version constraints that should give the best mileage.
|
|
25
|
+
|
|
20
26
|
Usage
|
|
21
27
|
-----
|
|
22
28
|
|
data/Rakefile
CHANGED
|
@@ -6,15 +6,16 @@ task('metrics:mutant').clear
|
|
|
6
6
|
|
|
7
7
|
namespace :metrics do
|
|
8
8
|
task mutant: :coverage do
|
|
9
|
-
|
|
9
|
+
args = %w[
|
|
10
10
|
bundle exec mutant
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
--include lib
|
|
12
|
+
--require unparser
|
|
13
|
+
--use rspec
|
|
14
|
+
--zombie
|
|
15
|
+
--since HEAD~1
|
|
16
|
+
]
|
|
17
|
+
args.concat(%w[--jobs 4]) if ENV.key?('CIRCLECI')
|
|
18
|
+
|
|
19
|
+
system(*args.concat(%w[-- Unparser*])) or fail "Mutant task failed"
|
|
19
20
|
end
|
|
20
21
|
end
|
data/config/devtools.yml
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
---
|
|
2
|
-
unit_test_timeout:
|
|
2
|
+
unit_test_timeout: 0.1
|
data/config/flay.yml
CHANGED
data/config/rubocop.yml
CHANGED
|
@@ -5,6 +5,7 @@ AllCops:
|
|
|
5
5
|
- '**/*.rake'
|
|
6
6
|
- 'Gemfile'
|
|
7
7
|
- 'Gemfile.triage'
|
|
8
|
+
TargetRubyVersion: 2.1
|
|
8
9
|
|
|
9
10
|
# Avoid parameter lists longer than five parameters.
|
|
10
11
|
ParameterLists:
|
|
@@ -37,6 +38,23 @@ LineLength:
|
|
|
37
38
|
ClassLength:
|
|
38
39
|
Max: 204
|
|
39
40
|
|
|
41
|
+
# Prefer modifiers and explicit if statements over returning early for small methods
|
|
42
|
+
GuardClause:
|
|
43
|
+
Enabled: false
|
|
44
|
+
|
|
45
|
+
Metrics/BlockLength:
|
|
46
|
+
Exclude:
|
|
47
|
+
# Ignore RSpec DSL
|
|
48
|
+
- spec/**/*
|
|
49
|
+
|
|
50
|
+
# Flags freezes for singletons that could still be mutated like Regexps
|
|
51
|
+
RedundantFreeze:
|
|
52
|
+
Enabled: false
|
|
53
|
+
|
|
54
|
+
# Allow Fixnum and Bignum. This Gem supports versions before 2.4
|
|
55
|
+
UnifiedInteger:
|
|
56
|
+
Enabled: false
|
|
57
|
+
|
|
40
58
|
# Disabled because of indenting with private keyword in class bodies.
|
|
41
59
|
IndentationWidth:
|
|
42
60
|
Enabled: false
|
data/lib/unparser.rb
CHANGED
data/lib/unparser/ast.rb
CHANGED
data/lib/unparser/cli.rb
CHANGED
|
@@ -9,6 +9,8 @@ require 'unparser/cli/color'
|
|
|
9
9
|
|
|
10
10
|
module Unparser
|
|
11
11
|
# Unparser CLI implementation
|
|
12
|
+
#
|
|
13
|
+
# :reek:InstanceVariableAssumption
|
|
12
14
|
class CLI
|
|
13
15
|
|
|
14
16
|
EXIT_SUCCESS = 0
|
|
@@ -148,10 +150,9 @@ module Unparser
|
|
|
148
150
|
#
|
|
149
151
|
def sources(file_name)
|
|
150
152
|
files =
|
|
151
|
-
|
|
152
|
-
when File.directory?(file_name)
|
|
153
|
+
if File.directory?(file_name)
|
|
153
154
|
Dir.glob(File.join(file_name, '**/*.rb')).sort
|
|
154
|
-
|
|
155
|
+
elsif File.file?(file_name)
|
|
155
156
|
[file_name]
|
|
156
157
|
else
|
|
157
158
|
Dir.glob(file_name).sort
|
data/lib/unparser/cli/color.rb
CHANGED
|
@@ -12,7 +12,7 @@ module Unparser
|
|
|
12
12
|
# @api private
|
|
13
13
|
#
|
|
14
14
|
def format(text)
|
|
15
|
-
"\e[#{
|
|
15
|
+
"\e[#{code}m#{text}\e[0m"
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
NONE = Class.new(self) do
|
|
@@ -38,8 +38,7 @@ module Unparser
|
|
|
38
38
|
#
|
|
39
39
|
# @api private
|
|
40
40
|
#
|
|
41
|
-
def initialize
|
|
42
|
-
end
|
|
41
|
+
def initialize; end
|
|
43
42
|
|
|
44
43
|
end.new
|
|
45
44
|
|
data/lib/unparser/cli/differ.rb
CHANGED
|
@@ -6,6 +6,51 @@ module Unparser
|
|
|
6
6
|
|
|
7
7
|
CONTEXT_LINES = 5
|
|
8
8
|
|
|
9
|
+
# Return new object
|
|
10
|
+
#
|
|
11
|
+
# @param [String] old
|
|
12
|
+
# @param [String] new
|
|
13
|
+
#
|
|
14
|
+
# @return [Differ]
|
|
15
|
+
#
|
|
16
|
+
# @api private
|
|
17
|
+
#
|
|
18
|
+
def self.build(old, new)
|
|
19
|
+
new(lines(old), lines(new))
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Return colorized diff line
|
|
23
|
+
#
|
|
24
|
+
# @param [String] line
|
|
25
|
+
#
|
|
26
|
+
# @return [String]
|
|
27
|
+
#
|
|
28
|
+
# @api private
|
|
29
|
+
#
|
|
30
|
+
def self.colorize_line(line)
|
|
31
|
+
case line[0]
|
|
32
|
+
when '+'
|
|
33
|
+
Color::GREEN
|
|
34
|
+
when '-'
|
|
35
|
+
Color::RED
|
|
36
|
+
else
|
|
37
|
+
Color::NONE
|
|
38
|
+
end.format(line)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Break up source into lines
|
|
42
|
+
#
|
|
43
|
+
# @param [String] source
|
|
44
|
+
#
|
|
45
|
+
# @return [Array<String>]
|
|
46
|
+
#
|
|
47
|
+
# @api private
|
|
48
|
+
#
|
|
49
|
+
def self.lines(source)
|
|
50
|
+
source.lines.map(&:chomp)
|
|
51
|
+
end
|
|
52
|
+
private_class_method :lines
|
|
53
|
+
|
|
9
54
|
# Return hunks
|
|
10
55
|
#
|
|
11
56
|
# @return [Array<Diff::LCS::Hunk>]
|
|
@@ -77,32 +122,6 @@ module Unparser
|
|
|
77
122
|
end
|
|
78
123
|
memoize :colorized_diff
|
|
79
124
|
|
|
80
|
-
# Return new object
|
|
81
|
-
#
|
|
82
|
-
# @param [String] old
|
|
83
|
-
# @param [String] new
|
|
84
|
-
#
|
|
85
|
-
# @return [Differ]
|
|
86
|
-
#
|
|
87
|
-
# @api private
|
|
88
|
-
#
|
|
89
|
-
def self.build(old, new)
|
|
90
|
-
new(lines(old), lines(new))
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
# Break up source into lines
|
|
94
|
-
#
|
|
95
|
-
# @param [String] source
|
|
96
|
-
#
|
|
97
|
-
# @return [Array<String>]
|
|
98
|
-
#
|
|
99
|
-
# @api private
|
|
100
|
-
#
|
|
101
|
-
def self.lines(source)
|
|
102
|
-
source.lines.map(&:chomp)
|
|
103
|
-
end
|
|
104
|
-
private_class_method :lines
|
|
105
|
-
|
|
106
125
|
private
|
|
107
126
|
|
|
108
127
|
# Return diffs
|
|
@@ -126,25 +145,6 @@ module Unparser
|
|
|
126
145
|
[old, new].map(&:length).max
|
|
127
146
|
end
|
|
128
147
|
|
|
129
|
-
# Return colorized diff line
|
|
130
|
-
#
|
|
131
|
-
# @param [String] line
|
|
132
|
-
#
|
|
133
|
-
# @return [String]
|
|
134
|
-
#
|
|
135
|
-
# @api private
|
|
136
|
-
#
|
|
137
|
-
def self.colorize_line(line)
|
|
138
|
-
case line[0]
|
|
139
|
-
when '+'
|
|
140
|
-
Color::GREEN
|
|
141
|
-
when '-'
|
|
142
|
-
Color::RED
|
|
143
|
-
else
|
|
144
|
-
Color::NONE
|
|
145
|
-
end.format(line)
|
|
146
|
-
end
|
|
147
|
-
|
|
148
148
|
end # CLI
|
|
149
149
|
end # Differ
|
|
150
150
|
end # Unparser
|
data/lib/unparser/cli/source.rb
CHANGED
|
@@ -49,14 +49,13 @@ module Unparser
|
|
|
49
49
|
# @api private
|
|
50
50
|
#
|
|
51
51
|
def report
|
|
52
|
-
|
|
53
|
-
when original_ast && generated_ast
|
|
52
|
+
if original_ast && generated_ast
|
|
54
53
|
report_with_ast_diff
|
|
55
|
-
|
|
54
|
+
elsif !original_ast
|
|
56
55
|
report_original
|
|
57
|
-
|
|
56
|
+
elsif !generated.success?
|
|
58
57
|
report_unparser
|
|
59
|
-
|
|
58
|
+
elsif !generated_ast
|
|
60
59
|
report_generated
|
|
61
60
|
else
|
|
62
61
|
raise
|
data/lib/unparser/comments.rb
CHANGED
|
@@ -99,11 +99,11 @@ module Unparser
|
|
|
99
99
|
#
|
|
100
100
|
# @api private
|
|
101
101
|
#
|
|
102
|
+
# :reek:ManualDispatch
|
|
103
|
+
#
|
|
102
104
|
def self.source_range(node, part)
|
|
103
105
|
location = node.location
|
|
104
|
-
|
|
105
|
-
location.public_send(part)
|
|
106
|
-
end
|
|
106
|
+
location.public_send(part) if location.respond_to?(part)
|
|
107
107
|
end
|
|
108
108
|
|
|
109
109
|
private
|
data/lib/unparser/constants.rb
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
module Unparser
|
|
2
2
|
# All unparser constants maybe included in other libraries.
|
|
3
|
+
#
|
|
4
|
+
# rubocop:disable MutableConstant
|
|
5
|
+
# False positive since constants are frozen dynamically
|
|
6
|
+
# to avoid duplication of `.freeze` calls
|
|
7
|
+
#
|
|
8
|
+
# :reek:TooManyConstants
|
|
3
9
|
module Constants
|
|
4
10
|
|
|
5
11
|
# Return frozen symbol set from enumerable
|
data/lib/unparser/emitter.rb
CHANGED
|
@@ -10,7 +10,7 @@ module Unparser
|
|
|
10
10
|
extend DSL
|
|
11
11
|
|
|
12
12
|
# Registry for node emitters
|
|
13
|
-
REGISTRY = {}
|
|
13
|
+
REGISTRY = {} # rubocop:disable MutableConstant
|
|
14
14
|
|
|
15
15
|
NOINDENT = [:rescue, :ensure].to_set.freeze
|
|
16
16
|
|
|
@@ -428,7 +428,7 @@ module Unparser
|
|
|
428
428
|
#
|
|
429
429
|
# False positive:
|
|
430
430
|
#
|
|
431
|
-
# rubocop:disable
|
|
431
|
+
# rubocop:disable MethodCallWithoutArgsParentheses
|
|
432
432
|
#
|
|
433
433
|
def indented
|
|
434
434
|
buffer = buffer()
|
|
@@ -7,7 +7,7 @@ module Unparser
|
|
|
7
7
|
return: K_RETURN,
|
|
8
8
|
next: K_NEXT,
|
|
9
9
|
break: K_BREAK
|
|
10
|
-
}
|
|
10
|
+
}.freeze
|
|
11
11
|
|
|
12
12
|
handle(*MAP.keys)
|
|
13
13
|
|
|
@@ -26,7 +26,7 @@ module Unparser
|
|
|
26
26
|
def dispatch
|
|
27
27
|
write(MAP.fetch(node.type))
|
|
28
28
|
case children.length
|
|
29
|
-
when 0
|
|
29
|
+
when 0 # rubocop:disable Lint/EmptyWhen
|
|
30
30
|
when 1
|
|
31
31
|
emit_single_argument
|
|
32
32
|
else
|
|
@@ -33,12 +33,21 @@ module Unparser
|
|
|
33
33
|
|
|
34
34
|
RATIONAL_FORMAT = 'i'.freeze
|
|
35
35
|
|
|
36
|
-
MAP =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
MAP =
|
|
37
|
+
if 0.class.equal?(Integer)
|
|
38
|
+
IceNine.deep_freeze(
|
|
39
|
+
Float => :float,
|
|
40
|
+
Rational => :rational,
|
|
41
|
+
Integer => :int
|
|
42
|
+
)
|
|
43
|
+
else
|
|
44
|
+
IceNine.deep_freeze(
|
|
45
|
+
Float => :float,
|
|
46
|
+
Rational => :rational,
|
|
47
|
+
Fixnum => :int,
|
|
48
|
+
Bignum => :int
|
|
49
|
+
)
|
|
50
|
+
end
|
|
42
51
|
|
|
43
52
|
private
|
|
44
53
|
|
|
@@ -74,12 +74,10 @@ module Unparser
|
|
|
74
74
|
def emit_operation
|
|
75
75
|
if arguments.empty?
|
|
76
76
|
emit_regular_with_empty_args
|
|
77
|
+
elsif mlhs?
|
|
78
|
+
emit_mlhs_operation
|
|
77
79
|
else
|
|
78
|
-
|
|
79
|
-
emit_mlhs_operation
|
|
80
|
-
else
|
|
81
|
-
emit_normal_operation
|
|
82
|
-
end
|
|
80
|
+
emit_normal_operation
|
|
83
81
|
end
|
|
84
82
|
end
|
|
85
83
|
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
# rubocop:disable ClosingParenthesisIndentation
|
|
4
2
|
describe 'Unparser on ruby corpus', mutant: false do
|
|
5
3
|
ROOT = Pathname.new(__FILE__).parent.parent.parent.parent
|
|
6
4
|
|
|
7
5
|
TMP = ROOT.join('tmp')
|
|
8
6
|
|
|
9
7
|
class Project
|
|
10
|
-
include Anima.new(:name, :repo_uri, :exclude)
|
|
8
|
+
include Anima.new(:name, :repo_uri, :repo_ref, :exclude)
|
|
11
9
|
|
|
12
10
|
# Perform verification via unparser cli
|
|
13
11
|
#
|
|
@@ -45,6 +43,13 @@ describe 'Unparser on ruby corpus', mutant: false do
|
|
|
45
43
|
else
|
|
46
44
|
system(%W(git clone #{repo_uri} #{repo_path}))
|
|
47
45
|
end
|
|
46
|
+
|
|
47
|
+
Dir.chdir(repo_path) do
|
|
48
|
+
system(%W(git checkout #{repo_ref}))
|
|
49
|
+
system(%w(git reset --hard))
|
|
50
|
+
system(%w(git clean -f -d -x))
|
|
51
|
+
end
|
|
52
|
+
|
|
48
53
|
self
|
|
49
54
|
end
|
|
50
55
|
|
|
@@ -84,19 +89,15 @@ describe 'Unparser on ruby corpus', mutant: false do
|
|
|
84
89
|
s(:guard, s(:primitive, Hash)),
|
|
85
90
|
s(:hash_transform,
|
|
86
91
|
s(:key_symbolize, :repo_uri, s(:guard, s(:primitive, String))),
|
|
92
|
+
s(:key_symbolize, :repo_ref, s(:guard, s(:primitive, String))),
|
|
87
93
|
s(:key_symbolize, :name, s(:guard, s(:primitive, String))),
|
|
88
|
-
s(:key_symbolize, :exclude, s(:map, s(:guard, s(:primitive, String))))
|
|
89
|
-
),
|
|
94
|
+
s(:key_symbolize, :exclude, s(:map, s(:guard, s(:primitive, String))))),
|
|
90
95
|
s(:load_attribute_hash,
|
|
91
96
|
# NOTE: The domain param has no DSL currently!
|
|
92
97
|
Morpher::Evaluator::Transformer::Domain::Param.new(
|
|
93
98
|
Project,
|
|
94
|
-
[:repo_uri, :name, :exclude]
|
|
95
|
-
)
|
|
96
|
-
)
|
|
97
|
-
)
|
|
98
|
-
)
|
|
99
|
-
)
|
|
99
|
+
[:repo_uri, :repo_ref, :name, :exclude]
|
|
100
|
+
)))))
|
|
100
101
|
end
|
|
101
102
|
|
|
102
103
|
ALL = LOADER.call(YAML.load_file(ROOT.join('spec', 'integrations.yml')))
|
data/spec/integrations.yml
CHANGED
|
@@ -1,36 +1,82 @@
|
|
|
1
1
|
---
|
|
2
2
|
- name: anima
|
|
3
3
|
repo_uri: 'https://github.com/mbj/anima.git'
|
|
4
|
+
repo_ref: 'origin/master'
|
|
4
5
|
exclude: []
|
|
5
6
|
- name: mutant
|
|
6
7
|
repo_uri: 'https://github.com/mbj/mutant.git'
|
|
8
|
+
repo_ref: 'origin/master'
|
|
7
9
|
exclude: []
|
|
8
10
|
- name: yaks
|
|
9
11
|
repo_uri: 'https://github.com/plexus/yaks.git'
|
|
12
|
+
repo_ref: 'origin/master'
|
|
10
13
|
exclude: []
|
|
11
14
|
- name: chassis
|
|
12
15
|
repo_uri: 'https://github.com/ahawkins/chassis.git'
|
|
16
|
+
repo_ref: 'origin/master'
|
|
13
17
|
exclude: []
|
|
14
18
|
- name: rubyspec
|
|
15
19
|
repo_uri: 'https://github.com/ruby/spec.git'
|
|
20
|
+
# Revision of rubyspec on the last CI build of unparser that passed
|
|
21
|
+
repo_ref: 'origin/master'
|
|
16
22
|
exclude:
|
|
17
|
-
|
|
18
|
-
- core/array/pack/{b,c,h,m,u,w}_spec.rb
|
|
23
|
+
- command_line/fixtures/bad_syntax.rb
|
|
19
24
|
- core/array/pack/shared/float.rb
|
|
20
25
|
- core/array/pack/shared/integer.rb
|
|
26
|
+
- core/array/pack/shared/string.rb
|
|
27
|
+
- core/array/pack/{b,c,h,m}_spec.rb
|
|
28
|
+
- core/array/pack/{u,w}_spec.rb
|
|
21
29
|
- core/encoding/compatible_spec.rb
|
|
30
|
+
- core/encoding/converter/convert_spec.rb
|
|
31
|
+
- core/encoding/converter/last_error_spec.rb
|
|
32
|
+
- core/encoding/converter/primitive_convert_spec.rb
|
|
33
|
+
- core/encoding/converter/primitive_errinfo_spec.rb
|
|
34
|
+
- core/encoding/converter/putback_spec.rb
|
|
35
|
+
- core/encoding/fixtures/classes.rb
|
|
36
|
+
- core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb
|
|
37
|
+
- core/encoding/invalid_byte_sequence_error/incomplete_input_spec.rb
|
|
38
|
+
- core/encoding/invalid_byte_sequence_error/readagain_bytes_spec.rb
|
|
39
|
+
- core/encoding/replicate_spec.rb
|
|
22
40
|
- core/env/element_reference_spec.rb
|
|
23
41
|
- core/io/readpartial_spec.rb
|
|
42
|
+
- core/io/shared/gets_ascii.rb
|
|
43
|
+
- core/marshal/dump_spec.rb
|
|
44
|
+
- core/marshal/fixtures/marshal_data.rb
|
|
45
|
+
- core/marshal/shared/load.rb
|
|
46
|
+
- core/random/bytes_spec.rb
|
|
47
|
+
- core/regexp/shared/new_ascii.rb
|
|
24
48
|
- core/regexp/shared/new_ascii_8bit.rb
|
|
25
49
|
- core/regexp/shared/quote.rb
|
|
50
|
+
- core/string/byteslice_spec.rb
|
|
26
51
|
- core/string/casecmp_spec.rb
|
|
27
|
-
- core/string/
|
|
52
|
+
- core/string/codepoints_spec.rb
|
|
53
|
+
- core/string/count_spec.rb
|
|
54
|
+
- core/string/shared/codepoints.rb
|
|
55
|
+
- core/string/shared/each_codepoint_without_block.rb
|
|
56
|
+
- core/string/shared/eql.rb
|
|
57
|
+
- core/string/shared/succ.rb
|
|
58
|
+
- core/string/squeeze_spec.rb
|
|
59
|
+
- core/string/unpack/{b,c,h,m}_spec.rb
|
|
28
60
|
- core/string/unpack/shared/float.rb
|
|
29
61
|
- core/string/unpack/shared/integer.rb
|
|
30
|
-
-
|
|
31
|
-
- optional/capi/integer_spec.rb
|
|
32
|
-
# parser crashes
|
|
62
|
+
- core/string/unpack/{u,w}_spec.rb
|
|
33
63
|
- core/symbol/casecmp_spec.rb
|
|
64
|
+
- core/time/_dump_spec.rb
|
|
65
|
+
- core/time/_load_spec.rb
|
|
66
|
+
- language/fixtures/squiggly_heredoc.rb
|
|
67
|
+
- language/regexp/encoding_spec.rb
|
|
34
68
|
- language/regexp/escapes_spec.rb
|
|
35
|
-
-
|
|
36
|
-
- library/
|
|
69
|
+
- language/string_spec.rb
|
|
70
|
+
- library/digest/md5/shared/constants.rb
|
|
71
|
+
- library/digest/md5/shared/sample.rb
|
|
72
|
+
- library/digest/sha1/shared/constants.rb
|
|
73
|
+
- library/digest/sha256/shared/constants.rb
|
|
74
|
+
- library/digest/sha384/shared/constants.rb
|
|
75
|
+
- library/digest/sha512/shared/constants.rb
|
|
76
|
+
- library/openssl/shared/constants.rb
|
|
77
|
+
- library/socket/basicsocket/recv_spec.rb
|
|
78
|
+
- library/socket/socket/gethostbyname_spec.rb
|
|
79
|
+
- library/stringscanner/getch_spec.rb
|
|
80
|
+
- library/stringscanner/shared/get_byte.rb
|
|
81
|
+
- library/zlib/inflate/set_dictionary_spec.rb
|
|
82
|
+
- optional/capi/integer_spec.rb
|
data/spec/unit/unparser_spec.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
|
+
require 'parser/all'
|
|
2
3
|
|
|
3
4
|
describe Unparser, mutant_expression: 'Unparser::Emitter*' do
|
|
4
5
|
describe '.unparse' do
|
|
@@ -376,7 +377,7 @@ describe Unparser, mutant_expression: 'Unparser::Emitter*' do
|
|
|
376
377
|
%w(next return break).each do |keyword|
|
|
377
378
|
|
|
378
379
|
context keyword do
|
|
379
|
-
assert_terminated
|
|
380
|
+
assert_terminated keyword.to_s
|
|
380
381
|
assert_unterminated "#{keyword} 1"
|
|
381
382
|
assert_unterminated "#{keyword} 2, 3"
|
|
382
383
|
assert_unterminated "#{keyword} *nil"
|
|
@@ -1541,6 +1542,13 @@ describe Unparser, mutant_expression: 'Unparser::Emitter*' do
|
|
|
1541
1542
|
3
|
|
1542
1543
|
end
|
|
1543
1544
|
RUBY
|
|
1545
|
+
|
|
1546
|
+
assert_source <<-'RUBY'
|
|
1547
|
+
while (foo do
|
|
1548
|
+
end)
|
|
1549
|
+
:body
|
|
1550
|
+
end
|
|
1551
|
+
RUBY
|
|
1544
1552
|
end
|
|
1545
1553
|
|
|
1546
1554
|
context 'until' do
|
|
@@ -1554,6 +1562,13 @@ describe Unparser, mutant_expression: 'Unparser::Emitter*' do
|
|
|
1554
1562
|
3
|
|
1555
1563
|
end
|
|
1556
1564
|
RUBY
|
|
1565
|
+
|
|
1566
|
+
assert_source <<-'RUBY'
|
|
1567
|
+
until (foo do
|
|
1568
|
+
end)
|
|
1569
|
+
:body
|
|
1570
|
+
end
|
|
1571
|
+
RUBY
|
|
1557
1572
|
end
|
|
1558
1573
|
|
|
1559
1574
|
assert_source <<-'RUBY'
|
data/unparser.gemspec
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Gem::Specification.new do |gem|
|
|
2
2
|
gem.name = 'unparser'
|
|
3
|
-
gem.version = '0.2.
|
|
3
|
+
gem.version = '0.2.6'
|
|
4
4
|
|
|
5
5
|
gem.authors = ['Markus Schirp']
|
|
6
6
|
gem.email = 'mbj@schirp-dso.com'
|
|
@@ -21,9 +21,9 @@ Gem::Specification.new do |gem|
|
|
|
21
21
|
gem.add_dependency('abstract_type', '~> 0.0.7')
|
|
22
22
|
gem.add_dependency('adamantium', '~> 0.2.0')
|
|
23
23
|
gem.add_dependency('equalizer', '~> 0.0.9')
|
|
24
|
-
gem.add_dependency('diff-lcs', '~> 1.
|
|
24
|
+
gem.add_dependency('diff-lcs', '~> 1.3')
|
|
25
25
|
gem.add_dependency('concord', '~> 0.1.5')
|
|
26
|
-
gem.add_dependency('parser', '
|
|
26
|
+
gem.add_dependency('parser', '>= 2.3.1.2', '< 2.5')
|
|
27
27
|
gem.add_dependency('procto', '~> 0.0.2')
|
|
28
28
|
|
|
29
29
|
gem.add_development_dependency('anima', '~> 0.3.0')
|
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.2.
|
|
4
|
+
version: 0.2.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Markus Schirp
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2017-06-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: abstract_type
|
|
@@ -58,14 +58,14 @@ dependencies:
|
|
|
58
58
|
requirements:
|
|
59
59
|
- - "~>"
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: 1.
|
|
61
|
+
version: '1.3'
|
|
62
62
|
type: :runtime
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
66
|
- - "~>"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: 1.
|
|
68
|
+
version: '1.3'
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
70
70
|
name: concord
|
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -84,16 +84,22 @@ dependencies:
|
|
|
84
84
|
name: parser
|
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
|
86
86
|
requirements:
|
|
87
|
-
- - "
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: 2.3.1.2
|
|
90
|
+
- - "<"
|
|
88
91
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: 2.
|
|
92
|
+
version: '2.5'
|
|
90
93
|
type: :runtime
|
|
91
94
|
prerelease: false
|
|
92
95
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
96
|
requirements:
|
|
94
|
-
- - "
|
|
97
|
+
- - ">="
|
|
98
|
+
- !ruby/object:Gem::Version
|
|
99
|
+
version: 2.3.1.2
|
|
100
|
+
- - "<"
|
|
95
101
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: 2.
|
|
102
|
+
version: '2.5'
|
|
97
103
|
- !ruby/object:Gem::Dependency
|
|
98
104
|
name: procto
|
|
99
105
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -163,6 +169,7 @@ files:
|
|
|
163
169
|
- ".rubocop.yml"
|
|
164
170
|
- Changelog.md
|
|
165
171
|
- Gemfile
|
|
172
|
+
- Gemfile.lock
|
|
166
173
|
- LICENSE
|
|
167
174
|
- README.md
|
|
168
175
|
- Rakefile
|
|
@@ -278,7 +285,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
278
285
|
version: '0'
|
|
279
286
|
requirements: []
|
|
280
287
|
rubyforge_project:
|
|
281
|
-
rubygems_version: 2.
|
|
288
|
+
rubygems_version: 2.6.11
|
|
282
289
|
signing_key:
|
|
283
290
|
specification_version: 4
|
|
284
291
|
summary: Generate equivalent source for parser gem AST nodes
|
|
@@ -300,4 +307,3 @@ test_files:
|
|
|
300
307
|
- spec/unit/unparser/comments/take_eol_comments_spec.rb
|
|
301
308
|
- spec/unit/unparser/emitter/class_methods/handle_spec.rb
|
|
302
309
|
- spec/unit/unparser_spec.rb
|
|
303
|
-
has_rdoc:
|