Skip to content

Commit

Permalink
Add compiler specs for case/when forms weakly covered elsewhere.
Browse files Browse the repository at this point in the history
See #2423.
  • Loading branch information
headius committed Jan 5, 2015
1 parent 8a84610 commit 4e96624
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions spec/compiler/general_spec.rb
Expand Up @@ -962,5 +962,30 @@ def foo(str: "bar", num: 45, **opts)
]
end
end

it "handles dynamic case/when elements" do
# These use a global so IR does not inline it from a local var
run('$case_str = "z"; case "xyz"; when /#{$case_str}/; true; else; false; end') do |x|
expect(x).to eq(true)
end
run('$case_str = "xyz"; case "xyz"; when "#{$case_str}"; true; else; false; end') do |x|
expect(x).to eq(true)
end
run('$case_str = "xyz"; case :xyz; when :"#{$case_str}"; true; else; false; end') do |x|
expect(x).to eq(true)
end
end

it "handles lists of conditions in case/when" do
run('$case_str = "z"; case "xyz"; when /#{$$}/, /#{$case_str}/; true; else; false; end') do |x|
expect(x).to eq(true)
end
end

it "handles literal arrays in case/when" do
run('$case_ary = [1,2,3]; case $case_ary; when [1,2,3]; true; else; false; end') do |x|
expect(x).to eq(true)
end
end
end
end

0 comments on commit 4e96624

Please sign in to comment.