rpl.rb/spec/language_program_spec.rb

33 lines
802 B
Ruby
Raw Normal View History

2021-11-18 12:00:02 +01:00
# frozen_string_literal: true
2022-02-17 15:09:29 +01:00
require 'minitest/autorun'
2021-11-18 12:00:02 +01:00
2022-02-15 17:06:19 +01:00
require 'rpl'
2021-11-18 12:00:02 +01:00
2022-02-17 15:09:29 +01:00
class TestLanguageProgram < MiniTest::Test
2021-11-18 12:00:02 +01:00
def test_eval
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
interpreter.run '« 2 dup * dup » eval'
2021-11-18 12:11:19 +01:00
assert_equal [{ value: 4, type: :numeric, base: 10 },
{ value: 4, type: :numeric, base: 10 }],
interpreter.stack
2021-11-18 14:23:56 +01:00
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
interpreter.run '4 \'dup\' eval'
2021-11-18 14:23:56 +01:00
2022-02-22 14:58:17 +01:00
assert_equal [{ value: 4, type: :numeric, base: 10 },
{ value: 4, type: :numeric, base: 10 }],
interpreter.stack
interpreter = Rpl.new
interpreter.run '4
\'dup\'
eval'
assert_equal [{ value: 4, type: :numeric, base: 10 },
{ value: 4, type: :numeric, base: 10 }],
interpreter.stack
2021-11-18 12:00:02 +01:00
end
end