rubinius-melbourne 2.0.0.19 → 2.0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +14 -0
  4. data/Gemfile +4 -0
  5. data/Rakefile +31 -0
  6. data/ext/rubinius/melbourne/extconf.rb +9 -2
  7. data/lib/rubinius/melbourne.rb +1 -1
  8. data/lib/rubinius/melbourne/version.rb +1 -1
  9. data/rubinius-melbourne.gemspec +5 -3
  10. data/spec/alias_spec.rb +40 -0
  11. data/spec/and_spec.rb +19 -0
  12. data/spec/array_spec.rb +81 -0
  13. data/spec/attrasgn_spec.rb +112 -0
  14. data/spec/back_ref_spec.rb +11 -0
  15. data/spec/call_spec.rb +298 -0
  16. data/spec/case_spec.rb +234 -0
  17. data/spec/cdecl_spec.rb +45 -0
  18. data/spec/class_spec.rb +83 -0
  19. data/spec/colon2_spec.rb +7 -0
  20. data/spec/colon3_spec.rb +7 -0
  21. data/spec/const_spec.rb +7 -0
  22. data/spec/custom/matchers/parse_as.rb +27 -0
  23. data/spec/custom/runner/relates.rb +83 -0
  24. data/spec/cvar_spec.rb +29 -0
  25. data/spec/cvasgn_spec.rb +30 -0
  26. data/spec/cvdecl_spec.rb +12 -0
  27. data/spec/default.mspec +4 -0
  28. data/spec/defined_spec.rb +117 -0
  29. data/spec/defn_spec.rb +554 -0
  30. data/spec/defs_spec.rb +81 -0
  31. data/spec/dot2_spec.rb +7 -0
  32. data/spec/dot3_spec.rb +7 -0
  33. data/spec/dregx_spec.rb +52 -0
  34. data/spec/dstr_spec.rb +169 -0
  35. data/spec/dsym_spec.rb +10 -0
  36. data/spec/dxstr_spec.rb +11 -0
  37. data/spec/ensure_spec.rb +117 -0
  38. data/spec/false_spec.rb +7 -0
  39. data/spec/flip2_spec.rb +43 -0
  40. data/spec/flip3_spec.rb +27 -0
  41. data/spec/for_spec.rb +61 -0
  42. data/spec/gasgn_spec.rb +13 -0
  43. data/spec/gvar_spec.rb +25 -0
  44. data/spec/hash_spec.rb +31 -0
  45. data/spec/iasgn_spec.rb +25 -0
  46. data/spec/if_spec.rb +131 -0
  47. data/spec/iter_spec.rb +613 -0
  48. data/spec/lasgn_spec.rb +377 -0
  49. data/spec/lit_spec.rb +61 -0
  50. data/spec/masgn_spec.rb +406 -0
  51. data/spec/match2_spec.rb +19 -0
  52. data/spec/match3_spec.rb +24 -0
  53. data/spec/match_spec.rb +7 -0
  54. data/spec/module_spec.rb +47 -0
  55. data/spec/nil_spec.rb +7 -0
  56. data/spec/not_spec.rb +17 -0
  57. data/spec/nth_ref_spec.rb +7 -0
  58. data/spec/op_asgn_spec.rb +246 -0
  59. data/spec/or_spec.rb +35 -0
  60. data/spec/postexe_spec.rb +7 -0
  61. data/spec/regex_spec.rb +28 -0
  62. data/spec/rescue_spec.rb +359 -0
  63. data/spec/return_spec.rb +57 -0
  64. data/spec/sclass_spec.rb +55 -0
  65. data/spec/str_spec.rb +97 -0
  66. data/spec/super_spec.rb +93 -0
  67. data/spec/true_spec.rb +7 -0
  68. data/spec/undef_spec.rb +98 -0
  69. data/spec/until_spec.rb +140 -0
  70. data/spec/valias_spec.rb +7 -0
  71. data/spec/while_spec.rb +192 -0
  72. data/spec/xstr_spec.rb +7 -0
  73. data/spec/yield_spec.rb +65 -0
  74. data/spec/zsuper_spec.rb +45 -0
  75. metadata +171 -13
data/spec/case_spec.rb ADDED
@@ -0,0 +1,234 @@
1
+ describe "A Case node" do
2
+ relates <<-ruby do
3
+ var = 2
4
+ result = ""
5
+ case var
6
+ when 1 then
7
+ puts("something")
8
+ result = "red"
9
+ when 2, 3 then
10
+ result = "yellow"
11
+ when 4 then
12
+ # do nothing
13
+ else
14
+ result = "green"
15
+ end
16
+ case result
17
+ when "red" then
18
+ var = 1
19
+ when "yellow" then
20
+ var = 2
21
+ when "green" then
22
+ var = 3
23
+ else
24
+ # do nothing
25
+ end
26
+ ruby
27
+
28
+ parse do
29
+ [:block,
30
+ [:lasgn, :var, [:lit, 2]],
31
+ [:lasgn, :result, [:str, ""]],
32
+ [:case,
33
+ [:lvar, :var],
34
+ [:when,
35
+ [:array, [:lit, 1]],
36
+ [:block,
37
+ [:call, nil, :puts, [:arglist, [:str, "something"]]],
38
+ [:lasgn, :result, [:str, "red"]]]],
39
+ [:when,
40
+ [:array, [:lit, 2], [:lit, 3]],
41
+ [:lasgn, :result, [:str, "yellow"]]],
42
+ [:when, [:array, [:lit, 4]], nil],
43
+ [:lasgn, :result, [:str, "green"]]],
44
+ [:case,
45
+ [:lvar, :result],
46
+ [:when, [:array, [:str, "red"]], [:lasgn, :var, [:lit, 1]]],
47
+ [:when, [:array, [:str, "yellow"]], [:lasgn, :var, [:lit, 2]]],
48
+ [:when, [:array, [:str, "green"]], [:lasgn, :var, [:lit, 3]]],
49
+ nil]]
50
+ end
51
+ end
52
+
53
+ relates <<-ruby do
54
+ case a
55
+ when b then
56
+ case
57
+ when (d and e) then
58
+ f
59
+ else
60
+ # do nothing
61
+ end
62
+ else
63
+ # do nothing
64
+ end
65
+ ruby
66
+
67
+ parse do
68
+ [:case,
69
+ [:call, nil, :a, [:arglist]],
70
+ [:when,
71
+ [:array, [:call, nil, :b, [:arglist]]],
72
+ [:case,
73
+ nil,
74
+ [:when,
75
+ [:array,
76
+ [:and,
77
+ [:call, nil, :d, [:arglist]],
78
+ [:call, nil, :e, [:arglist]]]],
79
+ [:call, nil, :f, [:arglist]]],
80
+ nil]],
81
+ nil]
82
+ end
83
+ end
84
+
85
+ relates <<-ruby do
86
+ var1 = 1
87
+ var2 = 2
88
+ result = nil
89
+ case var1
90
+ when 1 then
91
+ case var2
92
+ when 1 then
93
+ result = 1
94
+ when 2 then
95
+ result = 2
96
+ else
97
+ result = 3
98
+ end
99
+ when 2 then
100
+ case var2
101
+ when 1 then
102
+ result = 4
103
+ when 2 then
104
+ result = 5
105
+ else
106
+ result = 6
107
+ end
108
+ else
109
+ result = 7
110
+ end
111
+ ruby
112
+
113
+ parse do
114
+ [:block,
115
+ [:lasgn, :var1, [:lit, 1]],
116
+ [:lasgn, :var2, [:lit, 2]],
117
+ [:lasgn, :result, [:nil]],
118
+ [:case,
119
+ [:lvar, :var1],
120
+ [:when,
121
+ [:array, [:lit, 1]],
122
+ [:case,
123
+ [:lvar, :var2],
124
+ [:when, [:array, [:lit, 1]], [:lasgn, :result, [:lit, 1]]],
125
+ [:when, [:array, [:lit, 2]], [:lasgn, :result, [:lit, 2]]],
126
+ [:lasgn, :result, [:lit, 3]]]],
127
+ [:when,
128
+ [:array, [:lit, 2]],
129
+ [:case,
130
+ [:lvar, :var2],
131
+ [:when, [:array, [:lit, 1]], [:lasgn, :result, [:lit, 4]]],
132
+ [:when, [:array, [:lit, 2]], [:lasgn, :result, [:lit, 5]]],
133
+ [:lasgn, :result, [:lit, 6]]]],
134
+ [:lasgn, :result, [:lit, 7]]]]
135
+ end
136
+ end
137
+
138
+ relates <<-ruby do
139
+ case
140
+ when (a == 1) then
141
+ :a
142
+ when (a == 2) then
143
+ :b
144
+ else
145
+ :c
146
+ end
147
+ ruby
148
+
149
+ parse do
150
+ [:case,
151
+ nil,
152
+ [:when,
153
+ [:array,
154
+ [:call, [:call, nil, :a, [:arglist]], :==, [:arglist, [:lit, 1]]]],
155
+ [:lit, :a]],
156
+ [:when,
157
+ [:array,
158
+ [:call, [:call, nil, :a, [:arglist]], :==, [:arglist, [:lit, 2]]]],
159
+ [:lit, :b]],
160
+ [:lit, :c]]
161
+ end
162
+ end
163
+
164
+ relates <<-ruby do
165
+ case a
166
+ when :b, *c then
167
+ d
168
+ else
169
+ e
170
+ end
171
+ ruby
172
+
173
+ parse do
174
+ [:case,
175
+ [:call, nil, :a, [:arglist]],
176
+ [:when,
177
+ [:array, [:lit, :b], [:when, [:call, nil, :c, [:arglist]], nil]],
178
+ [:call, nil, :d, [:arglist]]],
179
+ [:call, nil, :e, [:arglist]]]
180
+ end
181
+ end
182
+
183
+ relates <<-ruby do
184
+ case true
185
+ when String, *%w(foo bar baz) then
186
+ 12
187
+ end
188
+ ruby
189
+
190
+ parse do
191
+ [:case,
192
+ [:true],
193
+ [:when,
194
+ [:array,
195
+ [:const, :String],
196
+ [:when, [:array, [:str, "foo"], [:str, "bar"], [:str, "baz"]], nil]],
197
+ [:lit, 12]],
198
+ nil]
199
+ end
200
+ end
201
+
202
+ relates <<-ruby do
203
+ case ()
204
+ when a
205
+ 1
206
+ end
207
+ ruby
208
+
209
+ parse do
210
+ [:case,
211
+ [:nil],
212
+ [:when, [:array, [:call, nil, :a, [:arglist]]], [:lit, 1]],
213
+ nil]
214
+ end
215
+ end
216
+
217
+ relates <<-ruby do
218
+ x = 1
219
+ case a
220
+ when x
221
+ 2
222
+ end
223
+ ruby
224
+
225
+ parse do
226
+ [:block,
227
+ [:lasgn, :x, [:lit, 1]],
228
+ [:case,
229
+ [:call, nil, :a, [:arglist]],
230
+ [:when, [:array, [:lvar, :x]], [:lit, 2]],
231
+ nil]]
232
+ end
233
+ end
234
+ end
@@ -0,0 +1,45 @@
1
+ describe "A Cdecl node" do
2
+ relates "X = 42" do
3
+ parse do
4
+ [:cdecl, :X, [:lit, 42]]
5
+ end
6
+ end
7
+
8
+ relates "::X = 1" do
9
+ parse do
10
+ [:cdecl, [:colon3, :X], [:lit, 1]]
11
+ end
12
+ end
13
+
14
+ relates "X::Y = 1" do
15
+ parse do
16
+ [:cdecl, [:colon2, [:const, :X], :Y], [:lit, 1]]
17
+ end
18
+ end
19
+
20
+ relates "X::Y::Z = a" do
21
+ parse do
22
+ [:cdecl,
23
+ [:colon2, [:colon2, [:const, :X], :Y], :Z],
24
+ [:call, nil, :a, [:arglist]]]
25
+ end
26
+ end
27
+
28
+ relates "a::A = 1" do
29
+ parse do
30
+ [:cdecl, [:colon2, [:call, nil, :a, [:arglist]], :A], [:lit, 1]]
31
+ end
32
+ end
33
+
34
+ relates <<-ruby do
35
+ a = Object
36
+ a::B = b
37
+ ruby
38
+
39
+ parse do
40
+ [:block,
41
+ [:lasgn, :a, [:const, :Object]],
42
+ [:cdecl, [:colon2, [:lvar, :a], :B], [:call, nil, :b, [:arglist]]]]
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,83 @@
1
+ describe "A Class node" do
2
+ relates <<-ruby do
3
+ class X
4
+ puts((1 + 1))
5
+ def blah
6
+ puts("hello")
7
+ end
8
+ end
9
+ ruby
10
+
11
+ parse do
12
+ [:class,
13
+ :X,
14
+ nil,
15
+ [:scope,
16
+ [:block,
17
+ [:call,
18
+ nil,
19
+ :puts,
20
+ [:arglist, [:call, [:lit, 1], :+, [:arglist, [:lit, 1]]]]],
21
+ [:defn,
22
+ :blah,
23
+ [:args],
24
+ [:scope,
25
+ [:block, [:call, nil, :puts, [:arglist, [:str, "hello"]]]]]]]]]
26
+ end
27
+ end
28
+
29
+ relates <<-ruby do
30
+ class ::Y
31
+ c
32
+ end
33
+ ruby
34
+
35
+ parse do
36
+ [:class, [:colon3, :Y], nil, [:scope, [:call, nil, :c, [:arglist]]]]
37
+ end
38
+ end
39
+
40
+ relates <<-ruby do
41
+ class X::Y
42
+ c
43
+ end
44
+ ruby
45
+
46
+ parse do
47
+ [:class,
48
+ [:colon2, [:const, :X], :Y],
49
+ nil,
50
+ [:scope, [:call, nil, :c, [:arglist]]]]
51
+ end
52
+ end
53
+
54
+ relates <<-ruby do
55
+ class X < Array
56
+ end
57
+ ruby
58
+
59
+ parse do
60
+ [:class, :X, [:const, :Array], [:scope]]
61
+ end
62
+ end
63
+
64
+ relates <<-ruby do
65
+ class X < expr
66
+ end
67
+ ruby
68
+
69
+ parse do
70
+ [:class, :X, [:call, nil, :expr, [:arglist]], [:scope]]
71
+ end
72
+ end
73
+
74
+ relates <<-ruby do
75
+ class X < Object
76
+ end
77
+ ruby
78
+
79
+ parse do
80
+ [:class, :X, [:const, :Object], [:scope]]
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,7 @@
1
+ describe "A Colon2 node" do
2
+ relates "X::Y" do
3
+ parse do
4
+ [:colon2, [:const, :X], :Y]
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ describe "A Colon3 node" do
2
+ relates "::X" do
3
+ parse do
4
+ [:colon3, :X]
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ describe "A Const node" do
2
+ relates "X" do
3
+ parse do
4
+ [:const, :X]
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,27 @@
1
+ # The ParseAsMatcher wraps the logic for checking that a string of Ruby code
2
+ # is converted to the expected s-expression. It is combined with the #parse_as
3
+ # spec helper and enables specs of the form:
4
+ #
5
+ # "a = 1".should parse_as([:lasgn, :a, [:lit, 1]])
6
+ #
7
+ class ParseAsMatcher
8
+ def initialize(expected)
9
+ @expected = expected
10
+ end
11
+
12
+ def matches?(actual)
13
+ @actual = actual.to_sexp.to_a
14
+ @actual == @expected
15
+ end
16
+
17
+ def failure_message
18
+ ["Expected:\n#{@actual.pretty_inspect}\n",
19
+ "to equal:\n#{@expected.pretty_inspect}"]
20
+ end
21
+ end
22
+
23
+ class Object
24
+ def parse_as(sexp)
25
+ ParseAsMatcher.new sexp
26
+ end
27
+ end
@@ -0,0 +1,83 @@
1
+ # SpecDataRelation enables concise specs that involve several different forms
2
+ # of the same data. This is specifically useful for the parser and compiler
3
+ # specs where the output of each stage is essentially related to the input
4
+ # Ruby source. Together with the #relates spec method, it enables specs like:
5
+ #
6
+ # describe "An If node" do
7
+ # relates "a if b" do
8
+ # parse do
9
+ # # return the expected sexp
10
+ # end
11
+ #
12
+ # compile do |g|
13
+ # # return the expected bytecode
14
+ # end
15
+ #
16
+ # jit do |as|
17
+ # # return the expected asm/machine code
18
+ # end
19
+ # end
20
+ #
21
+ # relates "if a; b; end" do
22
+ # # ...
23
+ # end
24
+ # end
25
+
26
+ class SpecDataRelation
27
+ # Provides a simple configurability so that any one or more of the possible
28
+ # processes can be run. See the custom options in custom/utils/options.rb.
29
+ def self.enable(process)
30
+ @processors ||= []
31
+ @processors << process
32
+ end
33
+
34
+ # Returns true if no process is specifically set or if +process+ is in the
35
+ # list of enabled processes. In other words, all processes are enabled by
36
+ # default, or any combination of them may be enabled.
37
+ def self.enabled?(process)
38
+ @processors.nil? or @processors.include?(process)
39
+ end
40
+
41
+ def initialize(ruby)
42
+ @ruby = ruby
43
+ end
44
+
45
+ # Formats the Ruby source code for reabable output in the -fs formatter
46
+ # option. If the source contains no newline characters, wraps the source in
47
+ # single quotes to set if off from the rest of the description string. If
48
+ # the source does contain newline characters, sets the indent level to four
49
+ # characters.
50
+ def format(ruby)
51
+ if /\n/ =~ ruby
52
+ lines = ruby.rstrip.lines
53
+ if /( *)/ =~ lines.first
54
+ if $1.size > 4
55
+ dedent = $1.size - 4
56
+ ruby = lines.map { |l| l[dedent..-1] }.join
57
+ else
58
+ indent = " " * (4 - $1.size)
59
+ ruby = lines.map { |l| "#{indent}#{l}" }.join
60
+ end
61
+ end
62
+ "\n#{ruby}"
63
+ else
64
+ "'#{ruby}'"
65
+ end
66
+ end
67
+
68
+ # Creates spec example blocks if the parse process is enabled.
69
+ def parse(&block)
70
+ return unless self.class.enabled? :parser
71
+
72
+ ruby = @ruby
73
+ it "is parsed from #{format ruby}" do
74
+ ruby.should parse_as(block.call)
75
+ end
76
+ end
77
+ end
78
+
79
+ class Object
80
+ def relates(str, &block)
81
+ SpecDataRelation.new(str).instance_eval(&block)
82
+ end
83
+ end