Sha256: 9686719abe1f87e8786e323c42fdb70eae1a1840fb21865e944e891eb8831660

Contents?: true

Size: 825 Bytes

Versions: 3

Compression:

Stored size: 825 Bytes

Contents

require 'spec_helper'
require 'dentaku/ast/arithmetic'

require 'dentaku/token'

describe Dentaku::AST::Negation do
  let(:five) { Dentaku::AST::Logical.new Dentaku::Token.new(:numeric, 5) }
  let(:t)    { Dentaku::AST::Numeric.new Dentaku::Token.new(:logical, true) }

  it 'allows access to its sub-node' do
    node = described_class.new(five)
    expect(node.node).to eq(five)
  end

  it 'performs negation' do
    node = described_class.new(five)
    expect(node.value).to eq(-5)
  end

  it 'requires numeric operands' do
    expect {
      described_class.new(t)
    }.to raise_error(Dentaku::NodeError, /requires numeric operands/)

    expression = Dentaku::AST::Negation.new(five)
    group = Dentaku::AST::Grouping.new(expression)

    expect {
      described_class.new(group)
    }.not_to raise_error
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dentaku-3.3.4 spec/ast/negation_spec.rb
dentaku-3.3.3 spec/ast/negation_spec.rb
dentaku-3.3.2 spec/ast/negation_spec.rb