RSpec.describe AST::Conditional do it 'evaluates a true if statement' do expect( AST::Conditional.new( [ AST::Branch.new( AST::Binary.new( AST::Operators::GREATER_THAN, AST::Number.new(5.0), AST::Number.new(4.0), ), AST::Block.new( [ AST::String.new("5 is greater than 4") ] ) ) ] ).execute(Environment.new) ).to eq("5 is greater than 4") end it 'evaluates an else statement' do expect( AST::Conditional.new( [ AST::Branch.new( AST::Binary.new( AST::Operators::GREATER_THAN, AST::Number.new(3.0), AST::Number.new(4.0), ), AST::Block.new( [ AST::String.new("3 is greater than 4") ] ) ), AST::Branch.new( AST::Boolean.new(true), AST::Block.new( [ AST::String.new("3 is _not_ greater than 4") ] ) ) ] ).execute(Environment.new) ).to eq("3 is _not_ greater than 4") end it 'evaluates an else if statement' do expect( AST::Conditional.new( [ AST::Branch.new( AST::Binary.new( AST::Operators::GREATER_THAN, AST::Number.new(3.0), AST::Number.new(4.0), ), AST::Block.new( [ AST::String.new("3 is greater than 4") ] ) ), AST::Branch.new( AST::Binary.new( AST::Operators::GREATER_THAN, AST::Number.new(3.0), AST::Number.new(2.0), ), AST::Block.new( [ AST::String.new("3 is greater than 2") ] ) ), AST::Branch.new( AST::Boolean.new(true), AST::Block.new( [ AST::String.new("3 is _not_ greater than 4") ] ) ) ] ).execute(Environment.new) ).to eq("3 is greater than 2") end end