2021-11-18 12:00:02 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'test/unit'
|
|
|
|
|
2021-12-07 16:46:33 +01:00
|
|
|
require_relative '../language'
|
2021-11-18 12:00:02 +01:00
|
|
|
|
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-08 16:08:49 +01:00
|
|
|
lang = Rpl::Language.new
|
|
|
|
lang.run '« 2 dup * dup » eval'
|
2021-11-18 12:11:19 +01:00
|
|
|
|
2021-11-23 16:16:21 +01:00
|
|
|
assert_equal [{ value: 4, type: :numeric, base: 10 },
|
|
|
|
{ value: 4, type: :numeric, base: 10 }],
|
2021-12-08 16:08:49 +01:00
|
|
|
lang.stack
|
2021-11-18 14:23:56 +01:00
|
|
|
|
2021-12-08 16:08:49 +01:00
|
|
|
lang = Rpl::Language.new
|
|
|
|
lang.run '4 \'dup\' eval'
|
2021-11-18 14:23:56 +01:00
|
|
|
|
2021-11-23 16:16:21 +01:00
|
|
|
assert_equal [{ value: 4, type: :numeric, base: 10 },
|
|
|
|
{ value: 4, type: :numeric, base: 10 }],
|
2021-12-08 16:08:49 +01:00
|
|
|
lang.stack
|
2021-11-18 12:00:02 +01:00
|
|
|
end
|
|
|
|
end
|