rpl.rb/spec/language_filesystem_spec.rb

52 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
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
assert_equal [{ value: "1 2 +
2021-12-15 16:36:11 +01:00
« dup dup * * »
'trrr' sto
trrr
", type: :string }],
interpreter.stack
2021-12-15 16:36:11 +01:00
interpreter.run 'eval vars'
2021-12-15 16:36:11 +01:00
assert_equal [{ value: 27, base: 10, type: :numeric },
2022-02-08 15:45:36 +01:00
{ value: [{ type: :name, value: 'trrr' }], type: :list }],
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'
2021-12-16 11:02:42 +01:00
assert_equal [{ value: 27, base: 10, type: :numeric },
2022-02-08 15:45:36 +01:00
{ value: [{ type: :name, value: 'trrr' }], type: :list }],
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