1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- 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
|