ripper_ruby_parser 1.7.2 → 1.8.0

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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +28 -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/blocks.rb +33 -54
  6. data/lib/ripper_ruby_parser/sexp_handlers/conditionals.rb +17 -19
  7. data/lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb +34 -1
  8. data/lib/ripper_ruby_parser/sexp_handlers/method_calls.rb +1 -1
  9. data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +12 -15
  10. data/lib/ripper_ruby_parser/sexp_handlers/string_literals.rb +21 -15
  11. data/lib/ripper_ruby_parser/sexp_processor.rb +4 -17
  12. data/lib/ripper_ruby_parser/unescape.rb +36 -12
  13. data/lib/ripper_ruby_parser/version.rb +1 -1
  14. metadata +110 -78
  15. data/Rakefile +0 -33
  16. data/test/end_to_end/comments_test.rb +0 -59
  17. data/test/end_to_end/comparison_test.rb +0 -104
  18. data/test/end_to_end/lib_comparison_test.rb +0 -18
  19. data/test/end_to_end/line_numbering_test.rb +0 -31
  20. data/test/end_to_end/samples_comparison_test.rb +0 -13
  21. data/test/end_to_end/test_comparison_test.rb +0 -18
  22. data/test/pt_testcase/pt_test.rb +0 -44
  23. data/test/ripper_ruby_parser/commenting_ripper_parser_test.rb +0 -200
  24. data/test/ripper_ruby_parser/parser_test.rb +0 -576
  25. data/test/ripper_ruby_parser/sexp_handlers/assignment_test.rb +0 -597
  26. data/test/ripper_ruby_parser/sexp_handlers/blocks_test.rb +0 -717
  27. data/test/ripper_ruby_parser/sexp_handlers/conditionals_test.rb +0 -536
  28. data/test/ripper_ruby_parser/sexp_handlers/literals_test.rb +0 -165
  29. data/test/ripper_ruby_parser/sexp_handlers/loops_test.rb +0 -209
  30. data/test/ripper_ruby_parser/sexp_handlers/method_calls_test.rb +0 -237
  31. data/test/ripper_ruby_parser/sexp_handlers/methods_test.rb +0 -429
  32. data/test/ripper_ruby_parser/sexp_handlers/operators_test.rb +0 -405
  33. data/test/ripper_ruby_parser/sexp_handlers/string_literals_test.rb +0 -973
  34. data/test/ripper_ruby_parser/sexp_processor_test.rb +0 -327
  35. data/test/ripper_ruby_parser/version_test.rb +0 -7
  36. data/test/samples/assignment.rb +0 -22
  37. data/test/samples/comments.rb +0 -13
  38. data/test/samples/conditionals.rb +0 -23
  39. data/test/samples/lambdas.rb +0 -5
  40. data/test/samples/loops.rb +0 -36
  41. data/test/samples/misc.rb +0 -285
  42. data/test/samples/number.rb +0 -9
  43. data/test/samples/operators.rb +0 -18
  44. data/test/samples/strings.rb +0 -147
  45. data/test/test_helper.rb +0 -111
@@ -1,9 +0,0 @@
1
- # Samples of number-like literals
2
-
3
- 3.14
4
- 42
5
- 100r
6
- 0700
7
- 0x100
8
- 1+3i
9
- 3.2-4.2i
@@ -1,18 +0,0 @@
1
- # Samples of different operators
2
-
3
- # range operator (..)
4
- 0..4
5
- -1..-3
6
- 'a'..'z'
7
- 0.0..4.0
8
- foo..bar
9
- 0..4.0
10
- 0.0..4
11
-
12
- # exclusive range operator (...)
13
- 0...4
14
- -1...-3
15
- 'a'...'z'
16
- 0.0...4.0
17
- foo...bar
18
- 0...4.0
@@ -1,147 +0,0 @@
1
- # Samples of strings demonstrating handling of escape sequences, encoding and
2
- # line continuations.
3
-
4
- # Escape sequences
5
- %W(foo\nbar baz)
6
- %w(foo\nbar baz)
7
-
8
- "foo\u273bbar"
9
- "foo\a\b\e\f\r\s\t\vbar\nbaz"
10
- "\0"
11
- "foo#{bar}\0"
12
- "foo#{bar}baz\0"
13
- "2\302\275"
14
- "#{foo}2\302\275"
15
- %W(2\302\275)
16
- /2\302\275/
17
- "foo\u{101D1}bar"
18
-
19
- # Encoding
20
- "日本語"
21
- /日本語/
22
- "\xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E" # => "日本語"
23
- "\xAB\xE6\x97\xA5" # Invalid in UTF8
24
-
25
- <<EOS
26
- 日本語
27
- EOS
28
-
29
- <<EOS
30
- \xE6\x97\xA5\xE6\x9C\xAC\xE8\xAA\x9E
31
- EOS
32
-
33
- # Quotes around heredoc names
34
- <<'FOO'
35
- \n
36
- FOO
37
-
38
- <<"FOO"
39
- \n
40
- FOO
41
-
42
- # Escape sequences in heredocs, in particular carriage returns
43
- #
44
- <<FOO
45
- foo\rbar\tbaz\r
46
- FOO
47
-
48
- <<'FOO'
49
- foo\rbar\tbaz\r
50
- FOO
51
-
52
- # Dedented heredocs
53
- foo = <<~BAR
54
- baz
55
- #{qux}
56
- quuz
57
- BAR
58
-
59
- # Line continuation
60
- "foo\
61
- bar"
62
-
63
- 'foo2\
64
- bar'
65
-
66
- /foo3\
67
- bar/
68
-
69
- <<EOS
70
- foo4\
71
- bar
72
- EOS
73
-
74
- <<'EOS'
75
- foo4\
76
- bar
77
- EOS
78
-
79
- <<EOS
80
- #{bar}
81
- baz \
82
- qux
83
- EOS
84
-
85
- <<-EOS
86
- #{bar}
87
- baz \
88
- qux
89
- EOS
90
-
91
- %Q[foo5\
92
- bar]
93
-
94
- %W[fooa\
95
- bar baz]
96
-
97
- %I[foob\
98
- bar baz]
99
-
100
- %q[fooc\
101
- bar]
102
-
103
- %w[food\
104
- bar baz]
105
-
106
- %i[fooe\
107
- bar baz]
108
-
109
- %r[foof\
110
- bar baz]
111
-
112
- # Escaped line continuation
113
- "foo6\\
114
- bar"
115
- 'foo7\\
116
- bar'
117
- /foo8\\
118
- bar/
119
- <<EOS
120
- foo9\\
121
- bar
122
- EOS
123
- %Q[foo10\\
124
- bar]
125
- %W[foog\\
126
- bar baz]
127
- %I[fooh\\
128
- bar baz]
129
- %q[fooi\\
130
- bar]
131
- %w[fooj\\
132
- bar baz]
133
- %i[fook\\
134
- bar baz]
135
- %r[fool\\
136
- bar baz]
137
-
138
- eval(<<FOO, __FILE__, __LINE__)
139
- bar
140
- baz
141
- FOO
142
-
143
- # Interpolation
144
- "foo#{bar}"
145
- "foo#{"bar#{baz}"}"
146
- "foo#{"bar#{"baz#{qux}"}"}"
147
- "foo#{"bar#{baz}"}foo#{"bar#{baz}"}"
data/test/test_helper.rb DELETED
@@ -1,111 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "simplecov"
4
- SimpleCov.start do
5
- add_filter "/test/"
6
- end
7
-
8
- require "minitest/autorun"
9
-
10
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
11
-
12
- require "ripper_ruby_parser"
13
-
14
- module MiniTest
15
- class Spec
16
- def inspect_with_line_numbers(exp)
17
- parts = exp.map do |sub_exp|
18
- if sub_exp.is_a? Sexp
19
- inspect_with_line_numbers(sub_exp)
20
- else
21
- sub_exp.inspect
22
- end
23
- end
24
-
25
- plain = "s(#{parts.join(', ')})"
26
- if exp.line
27
- "#{plain}.line(#{exp.line})"
28
- else
29
- plain
30
- end
31
- end
32
-
33
- def formatted(exp, with_line_numbers: false)
34
- inspection = if with_line_numbers
35
- inspect_with_line_numbers(exp)
36
- else
37
- exp.inspect
38
- end
39
- inspection.gsub(/\), /, "),\n")
40
- end
41
-
42
- def fix_lines(exp)
43
- if exp.sexp_type == :lit && exp.line == exp[1]
44
- return s(:lit, :__LINE__).line(exp.line)
45
- end
46
-
47
- exp.sexp_body = exp.sexp_body.map do |sub_exp|
48
- if sub_exp.is_a? Sexp
49
- fix_lines sub_exp
50
- else
51
- sub_exp
52
- end
53
- end
54
-
55
- exp
56
- end
57
-
58
- def to_comments(exp)
59
- comments = exp.comments.to_s.gsub(/\n\s*\n/, "\n")
60
-
61
- exp.sexp_body = exp.sexp_body.map do |sub_exp|
62
- if sub_exp.is_a? Sexp
63
- to_comments sub_exp
64
- else
65
- sub_exp
66
- end
67
- end
68
-
69
- if comments.empty?
70
- exp
71
- else
72
- s(:comment, comments, exp)
73
- end
74
- end
75
-
76
- def assert_parsed_as(sexp, code, with_line_numbers: false)
77
- parser = RipperRubyParser::Parser.new
78
- result = parser.parse code
79
- if sexp.nil?
80
- assert_nil result
81
- else
82
- assert_equal sexp, result
83
- assert_equal(formatted(sexp, with_line_numbers: with_line_numbers),
84
- formatted(result, with_line_numbers: with_line_numbers))
85
- end
86
- end
87
-
88
- def assert_parsed_as_before(code, with_line_numbers: false)
89
- oldparser = RubyParser.for_current_ruby
90
- newparser = RipperRubyParser::Parser.new
91
- newparser.extra_compatible = true
92
- expected = oldparser.parse code.dup
93
- result = newparser.parse code
94
- expected = to_comments fix_lines expected
95
- result = to_comments fix_lines result
96
- assert_equal expected, result
97
- assert_equal(formatted(expected, with_line_numbers: with_line_numbers),
98
- formatted(result, with_line_numbers: with_line_numbers))
99
- end
100
- end
101
-
102
- Expectation.class_eval do
103
- def must_be_parsed_as(sexp, with_line_numbers: false)
104
- ctx.assert_parsed_as(sexp, target, with_line_numbers: with_line_numbers)
105
- end
106
-
107
- def must_be_parsed_as_before(with_line_numbers: false)
108
- ctx.assert_parsed_as_before(target, with_line_numbers: with_line_numbers)
109
- end
110
- end
111
- end