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
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '"spec/test.rpl" fread'
|
2021-12-15 16:36:11 +01:00
|
|
|
|
2022-01-26 18:30:51 +01:00
|
|
|
assert_equal [{ value: "1 2 +
|
2021-12-15 16:36:11 +01:00
|
|
|
|
|
|
|
« dup dup * * »
|
|
|
|
'trrr' sto
|
|
|
|
|
|
|
|
trrr
|
2022-01-26 18:30:51 +01:00
|
|
|
", type: :string }],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-15 16:36:11 +01:00
|
|
|
|
2022-02-09 13:38:32 +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 }],
|
2022-02-09 13:38:32 +01:00
|
|
|
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
|
2022-02-09 13:38:32 +01:00
|
|
|
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 }],
|
2022-02-09 13:38:32 +01:00
|
|
|
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
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '"Ceci est un test de fwrite" "spec/test_fwrite.txt" fwrite'
|
2021-12-16 11:02:42 +01:00
|
|
|
assert_equal [],
|
2022-02-09 13:38:32 +01:00
|
|
|
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' )
|
2022-01-26 18:30:51 +01:00
|
|
|
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
|