2021-11-24 13:33:44 +01:00
|
|
|
# coding: utf-8
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-02-17 15:09:29 +01:00
|
|
|
require 'minitest/autorun'
|
2021-11-24 13:33:44 +01:00
|
|
|
|
2022-02-15 17:06:19 +01:00
|
|
|
require 'rpl'
|
2021-11-24 13:33:44 +01:00
|
|
|
|
2022-02-17 15:09:29 +01:00
|
|
|
class TestLanguageString < MiniTest::Test
|
2022-02-26 18:53:39 +01:00
|
|
|
include Types
|
|
|
|
|
2021-11-24 15:04:56 +01:00
|
|
|
def test_to_string
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '2 →str'
|
2021-11-24 15:04:56 +01:00
|
|
|
|
2022-02-26 18:53:39 +01:00
|
|
|
assert_equal [RplString.new( '"2"' )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-11-24 15:04:56 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_from_string
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '"2" str→'
|
2021-11-24 15:04:56 +01:00
|
|
|
|
2022-02-26 18:53:39 +01:00
|
|
|
assert_equal [RplNumeric.new( 2 )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-11-24 15:04:56 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '"« dup * » \'carré\' sto" str→'
|
2021-11-24 15:04:56 +01:00
|
|
|
|
2022-02-26 18:53:39 +01:00
|
|
|
assert_equal [RplProgram.new( '« dup * »' ),
|
|
|
|
RplName.new( 'carré' ),
|
|
|
|
RplName.new( 'sto' )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-11-24 15:04:56 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_chr
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '71 chr'
|
2021-11-24 15:04:56 +01:00
|
|
|
|
2022-02-26 18:53:39 +01:00
|
|
|
assert_equal [RplString.new( '"G"' )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-11-24 15:04:56 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_num
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '"G" num'
|
2021-11-24 15:04:56 +01:00
|
|
|
|
2022-02-26 18:53:39 +01:00
|
|
|
assert_equal [RplNumeric.new( 71 )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-11-24 15:04:56 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_size
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '"test" size'
|
2021-11-24 15:04:56 +01:00
|
|
|
|
2022-02-26 18:53:39 +01:00
|
|
|
assert_equal [RplNumeric.new( 4 )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-11-24 15:04:56 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_pos
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '"test of POS" "of" pos'
|
2021-11-24 15:04:56 +01:00
|
|
|
|
2022-02-26 18:53:39 +01:00
|
|
|
assert_equal [RplNumeric.new( 5 )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-11-24 15:04:56 +01:00
|
|
|
end
|
|
|
|
|
2021-11-24 13:33:44 +01:00
|
|
|
def test_sub
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '"my string to sub" 4 6 sub'
|
2021-11-24 13:33:44 +01:00
|
|
|
|
2022-02-26 18:53:39 +01:00
|
|
|
assert_equal [RplString.new( '"str"' )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-11-24 13:33:44 +01:00
|
|
|
end
|
2021-12-15 13:32:48 +01:00
|
|
|
|
|
|
|
def test_rev
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '"my string to sub" rev'
|
2021-12-15 13:32:48 +01:00
|
|
|
|
2022-02-26 18:53:39 +01:00
|
|
|
assert_equal [RplString.new( '"my string to sub"'.reverse )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-15 13:32:48 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_split
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '"my string to sub" " " split'
|
2021-12-15 13:32:48 +01:00
|
|
|
|
2022-02-26 18:53:39 +01:00
|
|
|
assert_equal [RplString.new( '"my"' ),
|
|
|
|
RplString.new( '"string"' ),
|
|
|
|
RplString.new( '"to"' ),
|
|
|
|
RplString.new( '"sub"' )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-15 13:32:48 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
interpreter = Rpl.new
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.run '"my,string,to sub" "," split'
|
2021-12-15 13:32:48 +01:00
|
|
|
|
2022-02-26 18:53:39 +01:00
|
|
|
assert_equal [RplString.new( '"my"' ),
|
|
|
|
RplString.new( '"string"' ),
|
|
|
|
RplString.new( '"to sub"' )],
|
2022-02-09 13:38:32 +01:00
|
|
|
interpreter.stack
|
2021-12-15 13:32:48 +01:00
|
|
|
end
|
2021-11-24 13:33:44 +01:00
|
|
|
end
|