Newer
Older
Ary Borenszweig
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
require "../../spec_helper"
describe "Codegen: special vars" do
["$~", "$?"].each do |name|
it "codegens #{name}" do
run(%(
class Object; def not_nil!; self; end; end
def foo(z)
#{name} = "hey"
end
foo(2)
#{name}
)).to_string.should eq("hey")
end
it "codegens #{name} with nilable (1)" do
run(%(
require "prelude"
def foo
if 1 == 2
#{name} = "foo"
end
end
foo
begin
#{name}
rescue ex
"ouch"
end
)).to_string.should eq("ouch")
end
it "codegens #{name} with nilable (2)" do
run(%(
require "prelude"
def foo
if 1 == 1
#{name} = "foo"
end
end
foo
begin
#{name}
rescue ex
"ouch"
end
)).to_string.should eq("foo")
end
end
it "codegens $~ two levels" do
run(%(
class Object; def not_nil!; self; end; end
def foo
$? = "hey"
end
def bar
$? = foo
$?
end
bar
$?
)).to_string.should eq("hey")
end
end