rpl.rb/spec/language_filesystem_spec.rb

51 lines
1.2 KiB
Ruby
Raw Normal View History

2021-12-15 16:36:11 +01:00
# coding: utf-8
# frozen_string_literal: true
require 'test/unit'
2022-02-10 14:50:59 +01:00
require_relative '../rpl'
2021-12-15 16:36:11 +01:00
2021-12-16 11:02:42 +01:00
class TestLanguageFileSystem < Test::Unit::TestCase
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
assert_true File.exist?( 'spec/test_fwrite.txt' )
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