rpl.rb/spec/language_string-list_spec.rb

102 lines
2.3 KiB
Ruby
Raw Normal View History

# coding: utf-8
# frozen_string_literal: true
2022-02-17 15:09:29 +01:00
require 'minitest/autorun'
2022-02-15 17:06:19 +01:00
require 'rpl'
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
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"' )],
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
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 )],
interpreter.stack
2021-11-24 15:04:56 +01:00
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
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' )],
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
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"' )],
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
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 )],
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
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 )],
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
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 )],
interpreter.stack
2021-11-24 15:04:56 +01:00
end
def test_sub
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
interpreter.run '"my string to sub" 4 6 sub'
2022-02-26 18:53:39 +01:00
assert_equal [RplString.new( '"str"' )],
interpreter.stack
end
2021-12-15 13:32:48 +01:00
def test_rev
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
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 )],
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
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"' )],
interpreter.stack
2021-12-15 13:32:48 +01:00
2022-02-10 14:50:59 +01:00
interpreter = Rpl.new
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"' )],
interpreter.stack
2021-12-15 13:32:48 +01:00
end
end