Newer
Older
CodeGenCEnumString = "lib LibFoo; enum Bar; X, Y, Z = 10, W; end end"
Ary Borenszweig
committed
describe "Code gen: c enum" do
run("#{CodeGenCEnumString}; LibFoo::Bar::X").to_i.should eq(0)
run("#{CodeGenCEnumString}; LibFoo::Bar::Y").to_i.should eq(1)
run("#{CodeGenCEnumString}; LibFoo::Bar::Z").to_i.should eq(10)
run("#{CodeGenCEnumString}; LibFoo::Bar::W").to_i.should eq(11)
[
{"1 + 2", 3},
{"3 - 2", 1},
{"3 * 2", 6},
{"10 / 2", 5},
{"1 << 3", 8},
{"100 >> 3", 12},
{"10 & 3", 2},
{"10 | 3", 11},
{"(1 + 2) * 3", 9},
{"10 % 3", 1},
].each do |test_case|
it "codegens enum with #{test_case[0]} " do
run("
enum Bar
X = #{test_case[0]}
end
end
").to_i.should eq(test_case[1])
end
end
Ary Borenszweig
committed
it "codegens enum that refers to another enum constant" do
run("
Ary Borenszweig
committed
enum Bar
A = 1
B = A + 1
C = B + 1
end
end
Ary Borenszweig
committed
").to_i.should eq(3)
end
it "codegens enum that refers to another constant" do
run("
Ary Borenszweig
committed
X = 10
enum Bar
A = X
B = A + 1
C = B + 1
end
end
Ary Borenszweig
committed
").to_i.should eq(12)
end