require 'spec_helper'

describe Calyx::Production::Expression do
  specify 'construct string formatting production' do
    nonterminal = double(:nonterminal)
    allow(nonterminal).to receive(:evaluate).and_return([:atom, 'hello'])
    rule = Calyx::Production::Expression.new(nonterminal, ['upcase'])
    expect(rule.evaluate).to eq([:expression, 'HELLO'])
  end
end

require 'spec_helper'

describe Calyx::Production::Expression do
  let(:production) do
    double(:production)
  end

  it 'evaluates a value' do
    allow(production).to receive(:evaluate).and_return([:atom, 'hello'])

    rule = Calyx::Production::Expression.new(production, [])
    expect(rule.evaluate).to eq([:expression, 'hello'])
  end

  it 'evaluates a value with modifier' do
    allow(production).to receive(:evaluate).and_return([:atom, 'hello'])

    rule = Calyx::Production::Expression.new(production, ['upcase'])
    expect(rule.evaluate).to eq([:expression, 'HELLO'])
  end

  it 'evaluates a value with modifier chain' do
    allow(production).to receive(:evaluate).and_return([:atom, 'hello'])

    rule = Calyx::Production::Expression.new(production, ['upcase', 'squeeze'])
    expect(rule.evaluate).to eq([:expression, 'HELO'])
  end
end

Tidy up expression spec to cover multiple cases
Tidy up expression spec to cover multiple cases
