rpl.rb/spec/language_string_spec.rb

73 lines
1.6 KiB
Ruby
Raw Normal View History

# coding: utf-8
# frozen_string_literal: true
require 'test/unit'
require_relative '../language'
class TestLanguageString < Test::Unit::TestCase
2021-11-24 15:04:56 +01:00
def test_to_string
lang = Rpl::Language.new
lang.run '2 →str'
2021-11-24 15:04:56 +01:00
assert_equal [{ value: '2', type: :string }],
lang.stack
2021-11-24 15:04:56 +01:00
end
def test_from_string
lang = Rpl::Language.new
lang.run '"2" str→'
2021-11-24 15:04:56 +01:00
assert_equal [{ value: 2, type: :numeric, base: 10 }],
lang.stack
2021-11-24 15:04:56 +01:00
lang = Rpl::Language.new
lang.run '"« dup * » \'carré\' sto" str→'
2021-11-24 15:04:56 +01:00
assert_equal [{ value: '« dup * »', type: :program },
2021-11-24 15:04:56 +01:00
{ value: "'carré'", type: :name },
{ value: 'sto', type: :word }],
lang.stack
2021-11-24 15:04:56 +01:00
end
def test_chr
lang = Rpl::Language.new
lang.run '71 chr'
2021-11-24 15:04:56 +01:00
assert_equal [{ value: 'G', type: :string }],
lang.stack
2021-11-24 15:04:56 +01:00
end
def test_num
lang = Rpl::Language.new
lang.run '"G" num'
2021-11-24 15:04:56 +01:00
assert_equal [{ value: 71, type: :numeric, base: 10 }],
lang.stack
2021-11-24 15:04:56 +01:00
end
def test_size
lang = Rpl::Language.new
lang.run '"test" size'
2021-11-24 15:04:56 +01:00
assert_equal [{ value: 4, type: :numeric, base: 10 }],
lang.stack
2021-11-24 15:04:56 +01:00
end
def test_pos
lang = Rpl::Language.new
lang.run '"test of POS" "of" pos'
2021-11-24 15:04:56 +01:00
assert_equal [{ value: 5, type: :numeric, base: 10 }],
lang.stack
2021-11-24 15:04:56 +01:00
end
def test_sub
lang = Rpl::Language.new
lang.run '"my string to sub" 4 6 sub'
assert_equal [{ value: 'str', type: :string }],
lang.stack
end
end