2022-08-31 13:19:35 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'minitest/autorun'
|
|
|
|
|
|
|
|
require 'rpl'
|
|
|
|
|
2024-03-27 08:08:43 +01:00
|
|
|
class TestLanguageString < Minitest::Test
|
2022-08-31 13:19:35 +02:00
|
|
|
include Types
|
|
|
|
|
|
|
|
def test_to_string
|
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '2 →str'
|
2022-08-31 13:19:35 +02:00
|
|
|
|
|
|
|
assert_equal [Types.new_object( RplString, '"2"' )],
|
|
|
|
interpreter.stack
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_from_string
|
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '"2" str→'
|
2022-08-31 13:19:35 +02:00
|
|
|
|
|
|
|
assert_equal [Types.new_object( RplNumeric, 2 )],
|
|
|
|
interpreter.stack
|
|
|
|
|
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '"« dup * » \'carré\' sto" str→'
|
2022-08-31 13:19:35 +02:00
|
|
|
|
|
|
|
assert_equal [Types.new_object( RplProgram, '« dup * »' ),
|
|
|
|
Types.new_object( RplName, 'carré' ),
|
|
|
|
Types.new_object( RplName, 'sto' )],
|
|
|
|
interpreter.stack
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_chr
|
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '71 chr'
|
2022-08-31 13:19:35 +02:00
|
|
|
|
|
|
|
assert_equal [Types.new_object( RplString, '"G"' )],
|
|
|
|
interpreter.stack
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_num
|
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '"G" num'
|
2022-08-31 13:19:35 +02:00
|
|
|
|
|
|
|
assert_equal [Types.new_object( RplNumeric, 71 )],
|
|
|
|
interpreter.stack
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_size
|
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '"test" size'
|
2022-08-31 13:19:35 +02:00
|
|
|
|
|
|
|
assert_equal [Types.new_object( RplNumeric, 4 )],
|
|
|
|
interpreter.stack
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_pos
|
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '"test of POS" "of" pos'
|
2022-08-31 13:19:35 +02:00
|
|
|
|
|
|
|
assert_equal [Types.new_object( RplNumeric, 5 )],
|
|
|
|
interpreter.stack
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_sub
|
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '"my string to sub" 4 6 sub'
|
2022-08-31 13:19:35 +02:00
|
|
|
|
|
|
|
assert_equal [Types.new_object( RplString, '"str"' )],
|
|
|
|
interpreter.stack
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_split
|
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '"my string to sub" " " split'
|
2022-08-31 13:19:35 +02:00
|
|
|
|
|
|
|
assert_equal [Types.new_object( RplString, '"my"' ),
|
|
|
|
Types.new_object( RplString, '"string"' ),
|
|
|
|
Types.new_object( RplString, '"to"' ),
|
|
|
|
Types.new_object( RplString, '"sub"' )],
|
|
|
|
interpreter.stack
|
|
|
|
|
|
|
|
interpreter = Rpl.new
|
2022-10-12 17:04:50 +02:00
|
|
|
interpreter.run! '"my,string,to sub" "," split'
|
2022-08-31 13:19:35 +02:00
|
|
|
|
|
|
|
assert_equal [Types.new_object( RplString, '"my"' ),
|
|
|
|
Types.new_object( RplString, '"string"' ),
|
|
|
|
Types.new_object( RplString, '"to sub"' )],
|
|
|
|
interpreter.stack
|
|
|
|
end
|
|
|
|
end
|