spec/calculator_spec.rb in dentaku-2.0.9 vs spec/calculator_spec.rb in dentaku-2.0.10

- old
+ new

@@ -64,10 +64,16 @@ describe 'dependencies' do it "finds dependencies in a generic statement" do expect(calculator.dependencies("bob + dole / 3")).to eq(['bob', 'dole']) end + it "finds dependencies in formula arguments" do + allow(Dentaku).to receive(:cache_ast?) { true } + + expect(calculator.dependencies("CONCAT(bob, dole)")).to eq(['bob', 'dole']) + end + it "doesn't consider variables in memory as dependencies" do expect(with_memory.dependencies("apples + oranges")).to eq(['oranges']) end end @@ -376,9 +382,37 @@ formula, type: 'organic', quantity: 10, fruit: 'banana') expect(value).to eq(5) + end + + it 'handles multiple nested case statements' do + formula = <<-FORMULA + CASE fruit + WHEN 'apple' + THEN + CASE quantity + WHEN 2 THEN 3 + END + WHEN 'banana' + THEN + CASE quantity + WHEN 1 THEN 2 + END + END + FORMULA + value = calculator.evaluate( + formula, + quantity: 1, + fruit: 'banana') + expect(value).to eq(2) + + value = calculator.evaluate( + formula, + quantity: 2, + fruit: 'apple') + expect(value).to eq(3) end end describe 'math functions' do Math.methods(false).each do |method|