ripper_ruby_parser 1.7.2 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +50 -0
  3. data/README.md +4 -4
  4. data/lib/ripper_ruby_parser/commenting_ripper_parser.rb +24 -12
  5. data/lib/ripper_ruby_parser/sexp_handlers/assignment.rb +2 -2
  6. data/lib/ripper_ruby_parser/sexp_handlers/blocks.rb +47 -53
  7. data/lib/ripper_ruby_parser/sexp_handlers/conditionals.rb +17 -19
  8. data/lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb +34 -1
  9. data/lib/ripper_ruby_parser/sexp_handlers/literals.rb +1 -1
  10. data/lib/ripper_ruby_parser/sexp_handlers/method_calls.rb +9 -5
  11. data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +17 -15
  12. data/lib/ripper_ruby_parser/sexp_handlers/operators.rb +3 -3
  13. data/lib/ripper_ruby_parser/sexp_handlers/string_literals.rb +24 -28
  14. data/lib/ripper_ruby_parser/sexp_processor.rb +5 -18
  15. data/lib/ripper_ruby_parser/unescape.rb +63 -22
  16. data/lib/ripper_ruby_parser/version.rb +1 -1
  17. metadata +140 -79
  18. data/Rakefile +0 -33
  19. data/test/end_to_end/comments_test.rb +0 -59
  20. data/test/end_to_end/comparison_test.rb +0 -104
  21. data/test/end_to_end/lib_comparison_test.rb +0 -18
  22. data/test/end_to_end/line_numbering_test.rb +0 -31
  23. data/test/end_to_end/samples_comparison_test.rb +0 -13
  24. data/test/end_to_end/test_comparison_test.rb +0 -18
  25. data/test/pt_testcase/pt_test.rb +0 -44
  26. data/test/ripper_ruby_parser/commenting_ripper_parser_test.rb +0 -200
  27. data/test/ripper_ruby_parser/parser_test.rb +0 -576
  28. data/test/ripper_ruby_parser/sexp_handlers/assignment_test.rb +0 -597
  29. data/test/ripper_ruby_parser/sexp_handlers/blocks_test.rb +0 -717
  30. data/test/ripper_ruby_parser/sexp_handlers/conditionals_test.rb +0 -536
  31. data/test/ripper_ruby_parser/sexp_handlers/literals_test.rb +0 -165
  32. data/test/ripper_ruby_parser/sexp_handlers/loops_test.rb +0 -209
  33. data/test/ripper_ruby_parser/sexp_handlers/method_calls_test.rb +0 -237
  34. data/test/ripper_ruby_parser/sexp_handlers/methods_test.rb +0 -429
  35. data/test/ripper_ruby_parser/sexp_handlers/operators_test.rb +0 -405
  36. data/test/ripper_ruby_parser/sexp_handlers/string_literals_test.rb +0 -973
  37. data/test/ripper_ruby_parser/sexp_processor_test.rb +0 -327
  38. data/test/ripper_ruby_parser/version_test.rb +0 -7
  39. data/test/samples/assignment.rb +0 -22
  40. data/test/samples/comments.rb +0 -13
  41. data/test/samples/conditionals.rb +0 -23
  42. data/test/samples/lambdas.rb +0 -5
  43. data/test/samples/loops.rb +0 -36
  44. data/test/samples/misc.rb +0 -285
  45. data/test/samples/number.rb +0 -9
  46. data/test/samples/operators.rb +0 -18
  47. data/test/samples/strings.rb +0 -147
  48. data/test/test_helper.rb +0 -111
@@ -11,8 +11,7 @@ module RipperRubyParser
11
11
  class SexpProcessor < ::SexpProcessor
12
12
  include Unescape
13
13
 
14
- attr_reader :filename
15
- attr_reader :extra_compatible
14
+ attr_reader :filename, :extra_compatible
16
15
 
17
16
  def initialize(filename: nil, extra_compatible: nil)
18
17
  super()
@@ -68,15 +67,7 @@ module RipperRubyParser
68
67
  statements = map_unwrap_begin_list map_process_list statements
69
68
  line = statements.first.line
70
69
  statements = reject_void_stmt statements
71
- case statements.count
72
- when 0
73
- s(:void_stmt).line(line)
74
- when 1
75
- statements.first
76
- else
77
- first = statements.shift
78
- s(:block, *unwrap_block(first), *statements)
79
- end
70
+ wrap_in_block(statements, line)
80
71
  end
81
72
 
82
73
  def process_var_ref(exp)
@@ -125,11 +116,7 @@ module RipperRubyParser
125
116
  def process_paren(exp)
126
117
  _, body = exp.shift 2
127
118
  result = process body
128
- if result.sexp_type == :void_stmt
129
- s(:nil)
130
- else
131
- result
132
- end
119
+ convert_void_stmt_to_nil_symbol result
133
120
  end
134
121
 
135
122
  def process_comment(exp)
@@ -208,7 +195,7 @@ module RipperRubyParser
208
195
 
209
196
  def process_at_backref(exp)
210
197
  _, str, pos = exp.shift 3
211
- name = str[1..-1]
198
+ name = str[1..]
212
199
  with_position pos do
213
200
  if /[0-9]/.match?(name)
214
201
  s(:nth_ref, name.to_i)
@@ -234,7 +221,7 @@ module RipperRubyParser
234
221
  def class_or_module_body(exp)
235
222
  body = process(exp)
236
223
 
237
- return body if body.empty?
224
+ return [] if body.sexp_type == :void_stmt
238
225
 
239
226
  unwrap_block body
240
227
  end
@@ -37,25 +37,34 @@ module RipperRubyParser
37
37
  SINGLE_LETTER_ESCAPES_REGEXP =
38
38
  Regexp.new("^[#{SINGLE_LETTER_ESCAPES.keys.join}]$")
39
39
 
40
- def simple_unescape(string)
40
+ DELIMITER_PAIRS = {
41
+ "(" => "()",
42
+ "<" => "<>",
43
+ "[" => "[]",
44
+ "{" => "{}"
45
+ }.freeze
46
+
47
+ def simple_unescape(string, delimiter)
48
+ delimiters = delimiter_regexp_pattern(delimiter)
41
49
  string.gsub(/
42
50
  \\ # a backslash
43
51
  ( # followed by a
44
- ' | # single quote or
45
- \\ # backslash
52
+ #{delimiters} | # delimiter or
53
+ \\ # backslash
46
54
  )/x) do
47
55
  Regexp.last_match[1]
48
56
  end
49
57
  end
50
58
 
51
- def simple_unescape_wordlist_word(string)
59
+ def simple_unescape_wordlist_word(string, delimiter)
60
+ delimiters = delimiter_regexp_pattern(delimiter)
52
61
  string.gsub(/
53
62
  \\ # a backslash
54
63
  ( # followed by a
55
- ' | # single quote or
56
- \\ | # backslash or
57
- [ ] | # space or
58
- \n # newline
64
+ #{delimiters} | # delimiter or
65
+ \\ | # backslash or
66
+ [ ] | # space or
67
+ \n # newline
59
68
  )
60
69
  /x) do
61
70
  Regexp.last_match[1]
@@ -63,12 +72,14 @@ module RipperRubyParser
63
72
  end
64
73
 
65
74
  def unescape(string)
75
+ string = string.dup if string.frozen?
76
+ string.force_encoding("ASCII-8BIT")
66
77
  string.gsub(ESCAPE_SEQUENCE_REGEXP) do
67
78
  bare = Regexp.last_match[1]
68
79
  if bare == "\n"
69
80
  ""
70
81
  else
71
- unescaped_value(bare)
82
+ unescaped_value(bare).force_encoding("ASCII-8BIT")
72
83
  end
73
84
  end
74
85
  end
@@ -95,7 +106,7 @@ module RipperRubyParser
95
106
  when "\n"
96
107
  ""
97
108
  else
98
- '\\\\'
109
+ "\\\\"
99
110
  end
100
111
  end
101
112
  end
@@ -105,26 +116,50 @@ module RipperRubyParser
105
116
  def unescaped_value(bare)
106
117
  case bare
107
118
  when SINGLE_LETTER_ESCAPES_REGEXP
108
- SINGLE_LETTER_ESCAPES[bare]
119
+ SINGLE_LETTER_ESCAPES[bare].dup
109
120
  when /^x/
110
- hex_to_char(bare[1..-1])
111
- when /^u\{/
112
- hex_to_unicode_char(bare[2..-2])
121
+ unescape_hex_char bare
113
122
  when /^u/
114
- hex_to_unicode_char(bare[1..4])
115
- when /^(c|C-).$/
116
- control(bare[-1].ord).chr
117
- when /^M-.$/
118
- meta(bare[-1].ord).chr
119
- when /^(M-\\C-|C-\\M-|M-\\c|c\\M-).$/
120
- meta(control(bare[-1].ord)).chr
123
+ unescape_unicode_char bare
124
+ when /^(c|C-|M-|M-\\C-|C-\\M-|M-\\c|c\\M-).$/
125
+ unescape_meta_control bare
121
126
  when /^[0-7]+/
122
- bare.to_i(8).chr
127
+ unescape_octal bare
123
128
  else
124
129
  bare
125
130
  end
126
131
  end
127
132
 
133
+ def unescape_hex_char(bare)
134
+ hex_to_char(bare[1..])
135
+ end
136
+
137
+ def unescape_unicode_char(bare)
138
+ hex_chars = if bare.start_with? "u{"
139
+ bare[2..-2]
140
+ else
141
+ bare[1..4]
142
+ end
143
+ hex_to_unicode_char(hex_chars)
144
+ end
145
+
146
+ def unescape_meta_control(bare)
147
+ base_value = bare[-1].ord
148
+ value = case bare
149
+ when /^(c|C-).$/
150
+ control(base_value)
151
+ when /^M-.$/
152
+ meta(base_value)
153
+ when /^(M-\\C-|C-\\M-|M-\\c|c\\M-).$/
154
+ meta(control(base_value))
155
+ end
156
+ value.chr
157
+ end
158
+
159
+ def unescape_octal(bare)
160
+ bare.to_i(8).chr
161
+ end
162
+
128
163
  def hex_to_unicode_char(str)
129
164
  str.to_i(16).chr(Encoding::UTF_8)
130
165
  end
@@ -140,5 +175,11 @@ module RipperRubyParser
140
175
  def meta(val)
141
176
  val | 0b1000_0000
142
177
  end
178
+
179
+ def delimiter_regexp_pattern(delimiter)
180
+ delimiter = delimiter[-1]
181
+ delimiters = DELIMITER_PAIRS.fetch(delimiter, delimiter)
182
+ delimiters.each_char.map { |it| Regexp.escape it }.join(" | ")
183
+ end
143
184
  end
144
185
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RipperRubyParser
4
- VERSION = "1.7.2"
4
+ VERSION = "1.10.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ripper_ruby_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.2
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matijs van Zuijlen
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-28 00:00:00.000000000 Z
11
+ date: 2022-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sexp_processor
@@ -38,6 +38,40 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '5.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest-focus
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 1.3.1
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '1.3'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 1.3.1
61
+ - !ruby/object:Gem::Dependency
62
+ name: pry
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.14.0
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.14.0
41
75
  - !ruby/object:Gem::Dependency
42
76
  name: rake
43
77
  requirement: !ruby/object:Gem::Requirement
@@ -52,37 +86,121 @@ dependencies:
52
86
  - - "~>"
53
87
  - !ruby/object:Gem::Version
54
88
  version: '13.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rake-manifest
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 0.2.0
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 0.2.0
103
+ - !ruby/object:Gem::Dependency
104
+ name: rubocop
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '1.25'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '1.25'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rubocop-minitest
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: 0.17.0
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: 0.17.0
131
+ - !ruby/object:Gem::Dependency
132
+ name: rubocop-packaging
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: 0.5.1
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: 0.5.1
145
+ - !ruby/object:Gem::Dependency
146
+ name: rubocop-performance
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '1.13'
152
+ type: :development
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: '1.13'
55
159
  - !ruby/object:Gem::Dependency
56
160
  name: ruby_parser
57
161
  requirement: !ruby/object:Gem::Requirement
58
162
  requirements:
59
163
  - - "~>"
60
164
  - !ruby/object:Gem::Version
61
- version: 3.14.1
165
+ version: '3.18'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - "~>"
171
+ - !ruby/object:Gem::Version
172
+ version: '3.18'
173
+ - !ruby/object:Gem::Dependency
174
+ name: sexp_processor
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - "~>"
178
+ - !ruby/object:Gem::Version
179
+ version: '4.16'
62
180
  type: :development
63
181
  prerelease: false
64
182
  version_requirements: !ruby/object:Gem::Requirement
65
183
  requirements:
66
184
  - - "~>"
67
185
  - !ruby/object:Gem::Version
68
- version: 3.14.1
186
+ version: '4.16'
69
187
  - !ruby/object:Gem::Dependency
70
188
  name: simplecov
71
189
  requirement: !ruby/object:Gem::Requirement
72
190
  requirements:
73
- - - ">="
191
+ - - "~>"
74
192
  - !ruby/object:Gem::Version
75
- version: '0'
193
+ version: 0.21.0
76
194
  type: :development
77
195
  prerelease: false
78
196
  version_requirements: !ruby/object:Gem::Requirement
79
197
  requirements:
80
- - - ">="
198
+ - - "~>"
81
199
  - !ruby/object:Gem::Version
82
- version: '0'
83
- description: |2
84
- RipperRubyParser is a parser for Ruby based on Ripper that aims to be a
85
- drop-in replacement for RubyParser.
200
+ version: 0.21.0
201
+ description: |
202
+ RipperRubyParser is a parser for Ruby based on Ripper that aims to be a
203
+ drop-in replacement for RubyParser.
86
204
  email:
87
205
  - matijs@matijs.net
88
206
  executables: []
@@ -92,7 +210,6 @@ extra_rdoc_files:
92
210
  files:
93
211
  - CHANGELOG.md
94
212
  - README.md
95
- - Rakefile
96
213
  - lib/ripper_ruby_parser.rb
97
214
  - lib/ripper_ruby_parser/commenting_ripper_parser.rb
98
215
  - lib/ripper_ruby_parser/parser.rb
@@ -111,41 +228,15 @@ files:
111
228
  - lib/ripper_ruby_parser/syntax_error.rb
112
229
  - lib/ripper_ruby_parser/unescape.rb
113
230
  - lib/ripper_ruby_parser/version.rb
114
- - test/end_to_end/comments_test.rb
115
- - test/end_to_end/comparison_test.rb
116
- - test/end_to_end/lib_comparison_test.rb
117
- - test/end_to_end/line_numbering_test.rb
118
- - test/end_to_end/samples_comparison_test.rb
119
- - test/end_to_end/test_comparison_test.rb
120
- - test/pt_testcase/pt_test.rb
121
- - test/ripper_ruby_parser/commenting_ripper_parser_test.rb
122
- - test/ripper_ruby_parser/parser_test.rb
123
- - test/ripper_ruby_parser/sexp_handlers/assignment_test.rb
124
- - test/ripper_ruby_parser/sexp_handlers/blocks_test.rb
125
- - test/ripper_ruby_parser/sexp_handlers/conditionals_test.rb
126
- - test/ripper_ruby_parser/sexp_handlers/literals_test.rb
127
- - test/ripper_ruby_parser/sexp_handlers/loops_test.rb
128
- - test/ripper_ruby_parser/sexp_handlers/method_calls_test.rb
129
- - test/ripper_ruby_parser/sexp_handlers/methods_test.rb
130
- - test/ripper_ruby_parser/sexp_handlers/operators_test.rb
131
- - test/ripper_ruby_parser/sexp_handlers/string_literals_test.rb
132
- - test/ripper_ruby_parser/sexp_processor_test.rb
133
- - test/ripper_ruby_parser/version_test.rb
134
- - test/samples/assignment.rb
135
- - test/samples/comments.rb
136
- - test/samples/conditionals.rb
137
- - test/samples/lambdas.rb
138
- - test/samples/loops.rb
139
- - test/samples/misc.rb
140
- - test/samples/number.rb
141
- - test/samples/operators.rb
142
- - test/samples/strings.rb
143
- - test/test_helper.rb
144
231
  homepage: http://www.github.com/mvz/ripper_ruby_parser
145
232
  licenses:
146
233
  - MIT
147
- metadata: {}
148
- post_install_message:
234
+ metadata:
235
+ homepage_uri: http://www.github.com/mvz/ripper_ruby_parser
236
+ source_code_uri: https://github.com/mvz/ripper_ruby_parser
237
+ changelog_uri: https://github.com/mvz/ripper_ruby_parser/blob/master/CHANGELOG.md
238
+ rubygems_mfa_required: 'true'
239
+ post_install_message:
149
240
  rdoc_options:
150
241
  - "--main"
151
242
  - README.md
@@ -155,45 +246,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
246
  requirements:
156
247
  - - ">="
157
248
  - !ruby/object:Gem::Version
158
- version: 2.4.0
249
+ version: 2.6.0
159
250
  required_rubygems_version: !ruby/object:Gem::Requirement
160
251
  requirements:
161
252
  - - ">="
162
253
  - !ruby/object:Gem::Version
163
254
  version: '0'
164
255
  requirements: []
165
- rubygems_version: 3.1.2
166
- signing_key:
256
+ rubygems_version: 3.2.33
257
+ signing_key:
167
258
  specification_version: 4
168
259
  summary: Parse with Ripper, produce sexps that are compatible with RubyParser.
169
- test_files:
170
- - test/end_to_end/comments_test.rb
171
- - test/end_to_end/comparison_test.rb
172
- - test/end_to_end/lib_comparison_test.rb
173
- - test/end_to_end/line_numbering_test.rb
174
- - test/end_to_end/samples_comparison_test.rb
175
- - test/end_to_end/test_comparison_test.rb
176
- - test/pt_testcase/pt_test.rb
177
- - test/ripper_ruby_parser/commenting_ripper_parser_test.rb
178
- - test/ripper_ruby_parser/parser_test.rb
179
- - test/ripper_ruby_parser/sexp_handlers/assignment_test.rb
180
- - test/ripper_ruby_parser/sexp_handlers/blocks_test.rb
181
- - test/ripper_ruby_parser/sexp_handlers/conditionals_test.rb
182
- - test/ripper_ruby_parser/sexp_handlers/literals_test.rb
183
- - test/ripper_ruby_parser/sexp_handlers/loops_test.rb
184
- - test/ripper_ruby_parser/sexp_handlers/method_calls_test.rb
185
- - test/ripper_ruby_parser/sexp_handlers/methods_test.rb
186
- - test/ripper_ruby_parser/sexp_handlers/operators_test.rb
187
- - test/ripper_ruby_parser/sexp_handlers/string_literals_test.rb
188
- - test/ripper_ruby_parser/sexp_processor_test.rb
189
- - test/ripper_ruby_parser/version_test.rb
190
- - test/samples/assignment.rb
191
- - test/samples/comments.rb
192
- - test/samples/conditionals.rb
193
- - test/samples/lambdas.rb
194
- - test/samples/loops.rb
195
- - test/samples/misc.rb
196
- - test/samples/number.rb
197
- - test/samples/operators.rb
198
- - test/samples/strings.rb
199
- - test/test_helper.rb
260
+ test_files: []
data/Rakefile DELETED
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "rake/clean"
4
- require "bundler/gem_tasks"
5
- require "rake/testtask"
6
-
7
- namespace :test do
8
- Rake::TestTask.new(:unit) do |t|
9
- t.libs = ["lib"]
10
- t.test_files = FileList["test/ripper_ruby_parser/**/*_test.rb"]
11
- t.warning = true
12
- end
13
-
14
- Rake::TestTask.new(:end_to_end) do |t|
15
- t.libs = ["lib"]
16
- t.test_files = FileList["test/end_to_end/*_test.rb"]
17
- t.warning = true
18
- end
19
-
20
- Rake::TestTask.new(:pt_testcase) do |t|
21
- t.libs = ["lib"]
22
- t.test_files = FileList["test/pt_testcase/*_test.rb"]
23
- t.warning = true
24
- end
25
-
26
- desc "Run all three test suites"
27
- task run: [:unit, :end_to_end, :pt_testcase]
28
- end
29
-
30
- desc "Alias to test:run"
31
- task test: "test:run"
32
-
33
- task default: :test
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require File.expand_path("../test_helper.rb", File.dirname(__FILE__))
4
- require "ruby_parser"
5
-
6
- describe "Using RipperRubyParser and RubyParser" do
7
- let :newparser do
8
- RipperRubyParser::Parser.new
9
- end
10
-
11
- let :oldparser do
12
- RubyParser.for_current_ruby
13
- end
14
-
15
- describe "for a program with quite some comments" do
16
- let :program do
17
- <<-RUBY
18
- # Foo
19
- class Foo
20
- # The foo
21
- # method
22
- def foo
23
- bar # bar
24
- # internal comment
25
- end
26
-
27
- def bar
28
- baz
29
- end
30
- end
31
- # Quux
32
- module Qux
33
- class Quux
34
- def bar
35
- end
36
- def baz
37
- end
38
- end
39
- end
40
- RUBY
41
- end
42
-
43
- let :original do
44
- oldparser.parse program
45
- end
46
-
47
- let :imitation do
48
- newparser.parse program
49
- end
50
-
51
- it "gives the same result" do
52
- _(imitation).must_equal original
53
- end
54
-
55
- it "gives the same result with comments" do
56
- _(to_comments(imitation)).must_equal to_comments(original)
57
- end
58
- end
59
- end
@@ -1,104 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require File.expand_path("../test_helper.rb", File.dirname(__FILE__))
4
- require "ruby_parser"
5
-
6
- describe "Using RipperRubyParser and RubyParser" do
7
- describe "for a simple well known program" do
8
- let :program do
9
- "puts 'Hello World'"
10
- end
11
-
12
- it "gives the same result with line numbers" do
13
- _(program).must_be_parsed_as_before with_line_numbers: true
14
- end
15
- end
16
-
17
- describe "for a more complex program" do
18
- let :program do
19
- <<-RUBY
20
- module Quux
21
- class Foo
22
- def bar
23
- baz = 3
24
- qux baz
25
- end
26
- def qux it
27
- if it == 3
28
- [1,2,3].map {|i| 2*i}
29
- end
30
- end
31
- end
32
- end
33
-
34
- Quux::Foo.new.bar
35
- RUBY
36
- end
37
-
38
- it "gives the same result with line numbers" do
39
- _(program).must_be_parsed_as_before with_line_numbers: true
40
- end
41
- end
42
-
43
- describe "for an example with yield from Reek" do
44
- let :program do
45
- "def fred() yield(3) if block_given?; end"
46
- end
47
-
48
- it "gives the same result with line numbers" do
49
- _(program).must_be_parsed_as_before with_line_numbers: true
50
- end
51
- end
52
-
53
- describe "for an example with floats from Reek" do
54
- let :program do
55
- <<-RUBY
56
- def total_envy
57
- fred = @item
58
- total = 0
59
- total += fred.price
60
- total += fred.tax
61
- total *= 1.15
62
- end
63
- RUBY
64
- end
65
-
66
- it "gives the same result with line numbers" do
67
- _(program).must_be_parsed_as_before with_line_numbers: true
68
- end
69
- end
70
-
71
- describe "for an example with operators and explicit block parameter from Reek" do
72
- let :program do
73
- <<-RUBY
74
- def parse(arg, argv, &error)
75
- if !(val = arg) and (argv.empty? or /\\A-/ =~ (val = argv[0]))
76
- return nil, block, nil
77
- end
78
- opt = (val = parse_arg(val, &error))[1]
79
- val = conv_arg(*val)
80
- if opt and !arg
81
- argv.shift
82
- else
83
- val[0] = nil
84
- end
85
- val
86
- end
87
- RUBY
88
- end
89
-
90
- it "gives the same result with line numbers" do
91
- _(program).must_be_parsed_as_before with_line_numbers: true
92
- end
93
- end
94
-
95
- describe "for an example of a complex regular expression from Reek" do
96
- let :program do
97
- "/(\#{@types})\\s*(\\w+)\\s*\\(([^)]*)\\)/"
98
- end
99
-
100
- it "gives the same result with line numbers" do
101
- _(program).must_be_parsed_as_before with_line_numbers: true
102
- end
103
- end
104
- end