Sha256: 01f5c1f89b22773e694e73045b615adfb6b52ab1152775b9552d6a973cc602f7

Contents?: true

Size: 876 Bytes

Versions: 4

Compression:

Stored size: 876 Bytes

Contents

require 'spec_helper'
require 'dentaku/ast/combinators'

require 'dentaku/token'

describe Dentaku::AST::And do
  let(:t) { Dentaku::AST::Logical.new Dentaku::Token.new(:logical, true)  }
  let(:f) { Dentaku::AST::Logical.new Dentaku::Token.new(:logical, false) }

  let(:five) { Dentaku::AST::Numeric.new Dentaku::Token.new(:numeric, 5) }

  it 'performs logical AND' do
    node = described_class.new(t, f)
    expect(node.value).to eq false
  end

  it 'requires logical operands' do
    expect {
      described_class.new(t, five)
    }.to raise_error(RuntimeError, /requires logical operands/)

    expression = Dentaku::AST::LessThanOrEqual.new(five, five)
    expect {
      described_class.new(t, expression)
    }.not_to raise_error

    expression = Dentaku::AST::Or.new(t, f)
    expect {
      described_class.new(t, expression)
    }.not_to raise_error
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dentaku-2.0.6 spec/ast/and_spec.rb
dentaku-2.0.5 spec/ast/and_spec.rb
dentaku-2.0.4 spec/ast/and_spec.rb
dentaku-2.0.3 spec/ast/and_spec.rb