rpl.rb/spec/language_branch_spec.rb

43 lines
1.6 KiB
Ruby
Raw Normal View History

2021-11-24 16:34:13 +01:00
# coding: utf-8
# frozen_string_literal: true
require 'test/unit'
require_relative '../language'
2021-11-24 16:34:13 +01:00
class TestLanguageBranch < Test::Unit::TestCase
def test_ifte
stack, _dictionary = Rpl::Lang::Core.ifte( [{ type: :boolean, value: true },
{ type: :program, value: '« 2 3 + »' },
{ type: :program, value: '« 2 3 - »' }],
Rpl::Lang::Dictionary.new )
2021-11-24 16:34:13 +01:00
assert_equal [{ value: 5, type: :numeric, base: 10 }],
stack
stack, _dictionary = Rpl::Lang::Core.ifte( [{ type: :boolean, value: false },
{ type: :program, value: '« 2 3 + »' },
{ type: :program, value: '« 2 3 - »' }],
Rpl::Lang::Dictionary.new )
2021-11-24 16:34:13 +01:00
assert_equal [{ value: -1, type: :numeric, base: 10 }],
stack
end
2021-12-08 13:14:09 +01:00
def test_ift
stack, _dictionary = Rpl::Lang::Core.ift( [{ type: :boolean, value: true },
{ type: :program, value: '« 2 3 + »' }],
Rpl::Lang::Dictionary.new )
assert_equal [{ value: 5, type: :numeric, base: 10 }],
stack
stack, _dictionary = Rpl::Lang::Core.ift( [{ type: :boolean, value: false },
{ type: :program, value: '« 2 3 + »' }],
Rpl::Lang::Dictionary.new )
assert_equal [],
stack
end
2021-11-24 16:34:13 +01:00
end