rpl.rb/spec/core_spec.rb

29 lines
728 B
Ruby
Raw Normal View History

2021-11-23 21:03:17 +01:00
# frozen_string_literal: true
2022-02-17 15:09:29 +01:00
require 'minitest/autorun'
2021-11-23 21:03:17 +01:00
2022-02-15 17:06:19 +01:00
require 'rpl'
2021-11-23 21:03:17 +01:00
2022-02-17 15:09:29 +01:00
class TestParser < MiniTest::Test
2022-02-26 18:53:39 +01:00
include Types
2021-11-23 21:03:17 +01:00
def test_stack_extract
2022-02-26 18:53:39 +01:00
interpreter = Rpl.new
interpreter.run '1 2'
2022-02-10 14:33:09 +01:00
args = interpreter.stack_extract [:any]
2022-02-28 11:40:47 +01:00
assert_equal [Types.new_object( RplNumeric, 1 )],
2022-02-10 14:33:09 +01:00
interpreter.stack
2022-02-28 11:40:47 +01:00
assert_equal [Types.new_object( RplNumeric, 2 )],
2021-11-23 21:03:17 +01:00
args
2022-02-26 18:53:39 +01:00
interpreter = Rpl.new
interpreter.run '"test" 2'
args = interpreter.stack_extract [[RplNumeric], :any]
2021-11-23 21:03:17 +01:00
assert_equal [],
2022-02-10 14:33:09 +01:00
interpreter.stack
2022-02-28 11:40:47 +01:00
assert_equal [Types.new_object( RplNumeric, 2 ),
Types.new_object( RplString, '"test"' )],
2021-11-23 21:03:17 +01:00
args
end
end