fix eval'ing :string

This commit is contained in:
Gwenhael Le Moine 2022-02-22 14:58:17 +01:00
parent eb7c3a3d73
commit dec32d7f9b
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
3 changed files with 12 additions and 9 deletions

View file

@ -12,7 +12,7 @@ module RplLang
proc do
args = stack_extract( [:any] )
if %i[list string numeric boolean].include?( args[0][:type] )
if %i[list numeric boolean].include?( args[0][:type] )
@stack << args[0] # these types evaluate to themselves
else
run( args[0][:value].to_s )

View file

@ -8,15 +8,9 @@ require 'rpl'
class TestLanguageFileSystem < MiniTest::Test
def test_fread
interpreter = Rpl.new
interpreter.run '"spec/test.rpl" fread'
interpreter.run '"./spec/test.rpl" fread'
assert_equal [{ value: "1 2 +
« dup dup * * »
'trrr' sto
trrr
", type: :string }],
assert_equal [{:type=>:string, :value=>"1 2 +\n\n« dup dup * * »\n'trrr' sto\n\ntrrr\n"}],
interpreter.stack
interpreter.run 'eval vars'

View file

@ -16,6 +16,15 @@ class TestLanguageProgram < MiniTest::Test
interpreter = Rpl.new
interpreter.run '4 \'dup\' eval'
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