rpl.rb/spec/language_program_spec.rb

41 lines
1.4 KiB
Ruby
Raw Normal View History

2021-11-18 12:00:02 +01:00
# coding: utf-8
# frozen_string_literal: true
require 'test/unit'
require_relative '../lib/core'
require_relative '../lib/dictionary'
require_relative '../lib/parser'
require_relative '../lib/runner'
2021-11-23 13:00:42 +01:00
class TestLanguageProgram < Test::Unit::TestCase
2021-11-18 12:00:02 +01:00
def test_eval
2021-12-07 15:50:58 +01:00
stack = Rpl::Lang::Core.eval( [{ value: '« 2 dup * dup »', type: :program }], Rpl::Lang::Dictionary.new )
2021-11-18 12:11:19 +01:00
assert_equal [{ value: 4, type: :numeric, base: 10 },
{ value: 4, type: :numeric, base: 10 }],
2021-11-18 12:00:02 +01:00
stack
2021-11-18 14:23:56 +01:00
2021-12-07 15:50:58 +01:00
stack = Rpl::Lang::Core.eval( [{ value: 4, type: :numeric, base: 10 },
{ value: "'dup'", type: :name }], Rpl::Lang::Dictionary.new )
2021-11-18 14:23:56 +01:00
assert_equal [{ value: 4, type: :numeric, base: 10 },
{ value: 4, type: :numeric, base: 10 }],
2021-11-18 14:23:56 +01:00
stack
2021-12-07 15:50:58 +01:00
stack = Rpl::Lang::Core.eval( [{ value: 4, type: :numeric, base: 10 },
{ value: 'dup', type: :word }], Rpl::Lang::Dictionary.new )
2021-11-18 14:23:56 +01:00
assert_equal [{ value: 4, type: :numeric, base: 10 },
{ value: 4, type: :numeric, base: 10 }],
2021-11-18 14:23:56 +01:00
stack
2021-11-18 12:00:02 +01:00
end
2021-12-07 15:50:58 +01:00
def test_sto
stack = Rpl::Lang::Core.sto( [{ value: '« 2 dup »', type: :program },
{ value: "'quatre'", type: :name }], Rpl::Lang::Dictionary.new )
assert_equal [], stack
end
2021-11-18 12:00:02 +01:00
end