rpl.rb/spec/words_filesystem_spec.rb

48 lines
1.3 KiB
Ruby
Raw Normal View History

2021-12-15 16:36:11 +01:00
# coding: utf-8
# frozen_string_literal: true
2022-02-17 15:09:29 +01:00
require 'minitest/autorun'
2021-12-15 16:36:11 +01:00
2022-02-15 17:06:19 +01:00
require 'rpl'
2021-12-15 16:36:11 +01:00
2022-02-17 15:09:29 +01:00
class TestLanguageFileSystem < MiniTest::Test
2022-02-26 18:53:39 +01:00
include Types
2021-12-15 16:36:11 +01:00
def test_fread
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
interpreter.run! '"./spec/test.rpl" fread'
2021-12-15 16:36:11 +01:00
2022-02-28 11:40:47 +01:00
assert_equal [Types.new_object( RplString, "\"1 2 +\n\n« dup dup * * »\n'trrr' sto\n\ntrrr\n\"" )],
interpreter.stack
2021-12-15 16:36:11 +01:00
interpreter.run! 'eval vars'
2022-02-28 11:40:47 +01:00
assert_equal [Types.new_object( RplNumeric, 27 ),
Types.new_object( RplList, [ Types.new_object( RplName, 'trrr' ) ] )],
interpreter.stack
2021-12-15 16:36:11 +01:00
end
2021-12-16 11:02:42 +01:00
def test_feval
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
interpreter.run! '"spec/test.rpl" feval vars'
2022-02-28 11:40:47 +01:00
assert_equal [Types.new_object( RplNumeric, 27 ),
Types.new_object( RplList, [ Types.new_object( RplName, 'trrr' ) ] )],
interpreter.stack
2021-12-16 11:02:42 +01:00
end
def test_fwrite
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
interpreter.run! '"Ceci est un test de fwrite" "spec/test_fwrite.txt" fwrite'
2021-12-16 11:02:42 +01:00
assert_equal [],
interpreter.stack
2021-12-16 11:02:42 +01:00
2022-02-17 15:09:29 +01:00
assert_equal true,
File.exist?( 'spec/test_fwrite.txt' )
2021-12-16 11:02:42 +01:00
written_content = File.read( 'spec/test_fwrite.txt' )
assert_equal 'Ceci est un test de fwrite',
2021-12-16 11:02:42 +01:00
written_content
FileUtils.rm 'spec/test_fwrite.txt'
end
2021-12-15 16:36:11 +01:00
end