2021-11-24 16:34:13 +01:00
|
|
|
# coding: utf-8
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'test/unit'
|
|
|
|
|
2021-12-07 16:46:33 +01:00
|
|
|
require_relative '../language'
|
2021-11-24 16:34:13 +01:00
|
|
|
|
|
|
|
class TestLanguageBranch < Test::Unit::TestCase
|
2021-12-09 16:31:29 +01:00
|
|
|
def test_loop
|
|
|
|
lang = Rpl::Language.new
|
|
|
|
lang.run '11 16 « "hello no." swap + » loop'
|
|
|
|
|
2022-01-26 18:30:51 +01:00
|
|
|
assert_equal [{ value: 'hello no.11', type: :string },
|
|
|
|
{ value: 'hello no.12', type: :string },
|
|
|
|
{ value: 'hello no.13', type: :string },
|
|
|
|
{ value: 'hello no.14', type: :string },
|
|
|
|
{ value: 'hello no.15', type: :string },
|
|
|
|
{ value: 'hello no.16', type: :string }],
|
2021-12-09 16:31:29 +01:00
|
|
|
lang.stack
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_times
|
|
|
|
lang = Rpl::Language.new
|
|
|
|
lang.run '5 « "hello no." swap + » times'
|
|
|
|
|
2022-01-26 18:30:51 +01:00
|
|
|
assert_equal [{ value: 'hello no.0', type: :string },
|
|
|
|
{ value: 'hello no.1', type: :string },
|
|
|
|
{ value: 'hello no.2', type: :string },
|
|
|
|
{ value: 'hello no.3', type: :string },
|
|
|
|
{ value: 'hello no.4', type: :string }],
|
2021-12-09 16:31:29 +01:00
|
|
|
lang.stack
|
|
|
|
end
|
|
|
|
|
2021-11-24 16:34:13 +01:00
|
|
|
def test_ifte
|
2021-12-08 16:08:49 +01:00
|
|
|
lang = Rpl::Language.new
|
|
|
|
lang.run 'true « 2 3 + » « 2 3 - » ifte'
|
2021-11-24 16:34:13 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: 5, type: :numeric, base: 10 }],
|
2021-12-08 16:08:49 +01:00
|
|
|
lang.stack
|
2021-11-24 16:34:13 +01:00
|
|
|
|
2021-12-08 16:08:49 +01:00
|
|
|
lang = Rpl::Language.new
|
|
|
|
lang.run 'false « 2 3 + » « 2 3 - » ifte'
|
2021-11-24 16:34:13 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: -1, type: :numeric, base: 10 }],
|
2021-12-08 16:08:49 +01:00
|
|
|
lang.stack
|
2021-11-24 16:34:13 +01:00
|
|
|
end
|
2021-12-08 13:14:09 +01:00
|
|
|
|
|
|
|
def test_ift
|
2021-12-08 16:08:49 +01:00
|
|
|
lang = Rpl::Language.new
|
|
|
|
lang.run 'true « 2 3 + » ift'
|
2021-12-08 13:14:09 +01:00
|
|
|
|
|
|
|
assert_equal [{ value: 5, type: :numeric, base: 10 }],
|
2021-12-08 16:08:49 +01:00
|
|
|
lang.stack
|
2021-12-08 13:14:09 +01:00
|
|
|
|
2021-12-08 16:08:49 +01:00
|
|
|
lang = Rpl::Language.new
|
|
|
|
lang.run 'false « 2 3 + » ift'
|
2021-12-08 13:14:09 +01:00
|
|
|
|
|
|
|
assert_equal [],
|
2021-12-08 16:08:49 +01:00
|
|
|
lang.stack
|
2021-12-08 13:14:09 +01:00
|
|
|
end
|
2021-11-24 16:34:13 +01:00
|
|
|
end
|