2021-11-18 12:00:02 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'test/unit'
|
|
|
|
|
2022-02-09 13:38:32 +01:00
|
|
|
require_relative '../interpreter'
|
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
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter = Rpl::Interpreter.new
|
|
|
|
interpreter.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 }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-11-18 14:23:56 +01:00
|
|
|
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter = Rpl::Interpreter.new
|
|
|
|
interpreter.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 }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-11-18 12:00:02 +01:00
|
|
|
end
|
|
|
|
end
|