Sha256: 65542ebdcd5b73ee4f33b93b8f20839dcbeee2430985102dd100fdffb02de8b9

Contents?: true

Size: 1.03 KB

Versions: 8

Compression:

Stored size: 1.03 KB

Contents

require 'spec_helper'
require 'dentaku'
require 'dentaku/ast/functions/or'

describe 'Dentaku::AST::Or' do
  let(:calculator) { Dentaku::Calculator.new }

  it 'returns false if all of the arguments are false' do
    result = Dentaku('OR(1 = "1", 0 = 1)')
    expect(result).to eq(false)
  end

  it 'supports nested expressions' do
    result = Dentaku('OR(y = 1, x = 1)', x: 1, y: 2)
    expect(result).to eq(true)
  end

  it 'returns true if any of the arguments is true' do
    result = Dentaku('OR(1 = "1", "2" = "2", true = false, false)')
    expect(result).to eq(true)
  end

  it 'returns true if any nested OR function returns true' do
    result = Dentaku('OR(OR(1 = 0), OR(true = false, OR(true)))')
    expect(result).to eq(true)
  end

  it 'raises an error if no arguments are passed' do
    expect { calculator.evaluate!('OR()') }.to raise_error(Dentaku::ArgumentError)
  end

  it 'raises an error if a non logical argument is passed' do
    expect { calculator.evaluate!('OR("r")') }.to raise_error(Dentaku::ArgumentError)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dentaku-3.5.0 spec/ast/or_spec.rb
dentaku-3.4.2 spec/ast/or_spec.rb
dentaku-3.4.1 spec/ast/or_spec.rb
dentaku-3.4.0 spec/ast/or_spec.rb
dentaku-3.3.4 spec/ast/or_spec.rb
dentaku-3.3.3 spec/ast/or_spec.rb
dentaku-3.3.2 spec/ast/or_spec.rb
dentaku-3.3.1 spec/ast/or_spec.rb