ripper_ruby_parser 1.7.0 → 1.9.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 +76 -0
  3. data/README.md +6 -4
  4. data/lib/ripper_ruby_parser/commenting_ripper_parser.rb +24 -12
  5. data/lib/ripper_ruby_parser/sexp_handlers.rb +2 -0
  6. data/lib/ripper_ruby_parser/sexp_handlers/assignment.rb +9 -4
  7. data/lib/ripper_ruby_parser/sexp_handlers/blocks.rb +40 -52
  8. data/lib/ripper_ruby_parser/sexp_handlers/conditionals.rb +17 -19
  9. data/lib/ripper_ruby_parser/sexp_handlers/helper_methods.rb +35 -2
  10. data/lib/ripper_ruby_parser/sexp_handlers/literals.rb +15 -242
  11. data/lib/ripper_ruby_parser/sexp_handlers/method_calls.rb +9 -5
  12. data/lib/ripper_ruby_parser/sexp_handlers/methods.rb +22 -17
  13. data/lib/ripper_ruby_parser/sexp_handlers/operators.rb +3 -3
  14. data/lib/ripper_ruby_parser/sexp_handlers/string_literals.rb +256 -0
  15. data/lib/ripper_ruby_parser/sexp_processor.rb +12 -56
  16. data/lib/ripper_ruby_parser/unescape.rb +89 -43
  17. data/lib/ripper_ruby_parser/version.rb +1 -1
  18. metadata +125 -76
  19. data/Rakefile +0 -33
  20. data/test/end_to_end/comments_test.rb +0 -59
  21. data/test/end_to_end/comparison_test.rb +0 -104
  22. data/test/end_to_end/lib_comparison_test.rb +0 -29
  23. data/test/end_to_end/line_numbering_test.rb +0 -31
  24. data/test/end_to_end/samples_comparison_test.rb +0 -13
  25. data/test/end_to_end/test_comparison_test.rb +0 -32
  26. data/test/pt_testcase/pt_test.rb +0 -44
  27. data/test/ripper_ruby_parser/commenting_ripper_parser_test.rb +0 -200
  28. data/test/ripper_ruby_parser/parser_test.rb +0 -553
  29. data/test/ripper_ruby_parser/sexp_handlers/assignment_test.rb +0 -613
  30. data/test/ripper_ruby_parser/sexp_handlers/blocks_test.rb +0 -679
  31. data/test/ripper_ruby_parser/sexp_handlers/conditionals_test.rb +0 -536
  32. data/test/ripper_ruby_parser/sexp_handlers/literals_test.rb +0 -1106
  33. data/test/ripper_ruby_parser/sexp_handlers/loops_test.rb +0 -209
  34. data/test/ripper_ruby_parser/sexp_handlers/method_calls_test.rb +0 -267
  35. data/test/ripper_ruby_parser/sexp_handlers/methods_test.rb +0 -421
  36. data/test/ripper_ruby_parser/sexp_handlers/operators_test.rb +0 -399
  37. data/test/ripper_ruby_parser/sexp_processor_test.rb +0 -303
  38. data/test/ripper_ruby_parser/version_test.rb +0 -7
  39. data/test/samples/assignment.rb +0 -17
  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 -281
  45. data/test/samples/number.rb +0 -7
  46. data/test/samples/operators.rb +0 -18
  47. data/test/samples/strings.rb +0 -147
  48. data/test/test_helper.rb +0 -107
@@ -1,7 +0,0 @@
1
- # Samples of number-like literals
2
-
3
- 3.14
4
- 42
5
- 100r
6
- 0700
7
- 0x100
@@ -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
-
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,107 +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, extra_compatible: false, with_line_numbers: false)
77
- parser = RipperRubyParser::Parser.new
78
- parser.extra_compatible = extra_compatible
79
- result = parser.parse code
80
- if sexp.nil?
81
- assert_nil result
82
- else
83
- assert_equal sexp, result
84
- assert_equal(formatted(sexp, with_line_numbers: with_line_numbers),
85
- formatted(result, with_line_numbers: with_line_numbers))
86
- end
87
- end
88
-
89
- def assert_parsed_as_before(code, with_line_numbers: false)
90
- oldparser = RubyParser.for_current_ruby
91
- newparser = RipperRubyParser::Parser.new
92
- newparser.extra_compatible = true
93
- expected = oldparser.parse code.dup
94
- result = newparser.parse code
95
- expected = to_comments fix_lines expected
96
- result = to_comments fix_lines result
97
- assert_equal expected, result
98
- assert_equal(formatted(expected, with_line_numbers: with_line_numbers),
99
- formatted(result, with_line_numbers: with_line_numbers))
100
- end
101
- end
102
-
103
- module Expectations
104
- infect_an_assertion :assert_parsed_as, :must_be_parsed_as
105
- infect_an_assertion :assert_parsed_as_before, :must_be_parsed_as_before, :unary
106
- end
107
- end