rpl.rb/spec/core_spec.rb

34 lines
1 KiB
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
2021-11-23 21:03:17 +01:00
def test_stack_extract
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new( [{ value: 1, type: :numeric },
{ value: 2, type: :numeric }] )
2022-02-10 14:33:09 +01:00
args = interpreter.stack_extract [:any]
2021-11-23 21:03:17 +01:00
assert_equal [{ value: 1, type: :numeric }],
2022-02-10 14:33:09 +01:00
interpreter.stack
2021-11-23 21:03:17 +01:00
assert_equal [{ value: 2, type: :numeric }],
args
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new( [{ value: 'test', type: :string },
{ value: 2, type: :numeric }] )
2022-02-10 14:33:09 +01:00
args = interpreter.stack_extract [[:numeric], :any]
2021-11-23 21:03:17 +01:00
assert_equal [],
2022-02-10 14:33:09 +01:00
interpreter.stack
2021-11-24 13:52:32 +01:00
assert_equal [{ value: 2, type: :numeric },
2021-11-24 13:53:41 +01:00
{ value: 'test', type: :string }],
2021-11-23 21:03:17 +01:00
args
end
2022-02-09 16:35:17 +01:00
def test_stringify
assert_equal '∞',
2022-02-10 14:50:59 +01:00
Rpl.new.stringify( { value: Float::INFINITY,
base: 10,
type: :numeric } )
2022-02-09 16:35:17 +01:00
end
2021-11-23 21:03:17 +01:00
end