Sha256: 9db279ca887520679cba37797902cf9c23a6cf952ccc65e1a105df99e9c75ace

Contents?: true

Size: 1.04 KB

Versions: 13

Compression:

Stored size: 1.04 KB

Contents

require 'spec_helper'
require 'dentaku'
require 'dentaku/ast/functions/and'

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

  it 'returns false if any of the arguments is false' do
    result = Dentaku('AND(1 = 1, 0 = 1)')
    expect(result).to eq(false)
  end

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

  it 'returns true if all of the arguments are true' do
    result = Dentaku('AND(1 = 1, "2" = "2", true = true, true)')
    expect(result).to eq(true)
  end

  it 'returns true if all nested AND functions return true' do
    result = Dentaku('AND(AND(1 = 1), AND(true != false, AND(true)))')
    expect(result).to eq(true)
  end

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

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

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
dentaku-3.5.4 spec/ast/and_function_spec.rb
dentaku-3.5.3 spec/ast/and_function_spec.rb
dentaku-3.5.2 spec/ast/and_function_spec.rb
dentaku_zevo-3.5.2 spec/ast/and_function_spec.rb
dentaku-3.5.1 spec/ast/and_function_spec.rb
dentaku-3.5.0 spec/ast/and_function_spec.rb
dentaku-3.4.2 spec/ast/and_function_spec.rb
dentaku-3.4.1 spec/ast/and_function_spec.rb
dentaku-3.4.0 spec/ast/and_function_spec.rb
dentaku-3.3.4 spec/ast/and_function_spec.rb
dentaku-3.3.3 spec/ast/and_function_spec.rb
dentaku-3.3.2 spec/ast/and_function_spec.rb
dentaku-3.3.1 spec/ast/and_function_spec.rb