Newer
Older
require "../../spec_helper"
describe "Code gen: or" do
it "codegens or with bool false and false" do
run("false || false").to_b.should be_false
end
it "codegens or with bool false and true" do
run("false || true").to_b.should be_true
end
it "codegens or with bool true and true" do
run("true || true").to_b.should be_true
end
it "codegens or with bool true and false" do
run("true || false").to_b.should be_true
end
it "codegens or with bool and int 1" do
Ary Borenszweig
committed
run("struct Bool; def to_i; 0; end; end; (false || 2).to_i").to_i.should eq(2)
end
it "codegens or with bool and int 2" do
Ary Borenszweig
committed
run("struct Bool; def to_i; 0; end; end; (true || 2).to_i").to_i.should eq(0)
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
77
78
79
80
81
82
83
84
85
86
end
it "codegens or with primitive type other than bool" do
run("1 || 2").to_i.should eq(1)
end
it "codegens or with primitive type other than bool with union" do
run("(1 || 1.5).to_f").to_f64.should eq(1)
end
it "codegens or with primitive type other than bool" do
run("require \"nil\"; (nil || 2).to_i").to_i.should eq(2)
end
it "codegens or with nilable as left node 1" do
run("
require \"nil\"
class Object; def to_i; -1; end; end
a = Reference.new
a = nil
(a || 2).to_i
").to_i.should eq(2)
end
it "codegens or with nilable as left node 2" do
run("
class Object; def to_i; -1; end; end
a = nil
a = Reference.new
(a || 2).to_i
").to_i.should eq(-1)
end
it "codegens or with non-false union as left node" do
run("
a = 1.5
a = 1
(a || 2).to_i
").to_i.should eq(1)
end
it "codegens or with nil union as left node 1" do
run("
require \"nil\"
a = nil
a = 1
(a || 2).to_i
").to_i.should eq(1)
end
it "codegens or with nil union as left node 2" do
run("
require \"nil\"
a = 1
a = nil
(a || 2).to_i
").to_i.should eq(2)
end
it "codegens or with bool union as left node 1" do
run("
Ary Borenszweig
committed
struct Bool; def to_i; 0; end; end
a = false
a = 1
(a || 2).to_i
").to_i.should eq(1)
end
it "codegens or with bool union as left node 2" do
run("
Ary Borenszweig
committed
struct Bool; def to_i; 0; end; end
a = 1
a = false
(a || 2).to_i
").to_i.should eq(2)
end
it "codegens or with bool union as left node 3" do
run("
Ary Borenszweig
committed
struct Bool; def to_i; 0; end; end
a = 1
a = true
(a || 2).to_i
").to_i.should eq(0)
end
it "codegens or with bool union as left node 1" do
run("
require \"nil\"
Ary Borenszweig
committed
struct Bool; def to_i; 1; end; end
a = false
a = nil
a = 2
(a || 3).to_i
").to_i.should eq(2)
end
it "codegens or with bool union as left node 2" do
run("
require \"nil\"
Ary Borenszweig
committed
struct Bool; def to_i; 1; end; end
a = nil
a = 2
a = false
(a || 3).to_i
").to_i.should eq(3)
end
it "codegens or with bool union as left node 3" do
run("
require \"nil\"
Ary Borenszweig
committed
struct Bool; def to_i; 1; end; end
a = nil
a = 2
a = true
(a || 3).to_i
").to_i.should eq(1)
end
it "codegens or with bool union as left node 4" do
run("
require \"nil\"
Ary Borenszweig
committed
struct Bool; def to_i; 1; end; end
a = 2
a = true
a = nil
(a || 3).to_i
").to_i.should eq(3)
end
end