2014-09-12 00:35:51 +02:00
|
|
|
# coding: utf-8
|
|
|
|
|
2014-11-03 23:43:45 +01:00
|
|
|
require_relative '../../lib/fOOrth/interpreter'
|
2014-11-04 06:26:00 +01:00
|
|
|
require 'minitest/autorun'
|
2014-12-20 01:17:23 +01:00
|
|
|
require 'minitest_visible'
|
2014-09-12 00:35:51 +02:00
|
|
|
|
|
|
|
#Test the monkey patches applied to the Object class.
|
2014-11-04 06:26:00 +01:00
|
|
|
class DataStackMapTester < MiniTest::Unit::TestCase
|
2014-09-12 00:35:51 +02:00
|
|
|
|
2014-12-20 01:17:23 +01:00
|
|
|
#Track mini-test progress.
|
|
|
|
MinitestVisible.track self, __FILE__
|
2014-09-12 00:35:51 +02:00
|
|
|
|
|
|
|
def test_data_stack_ops
|
2014-11-13 18:06:25 +01:00
|
|
|
vm = Thread.current[:vm]
|
2014-09-12 00:35:51 +02:00
|
|
|
refute(vm == nil)
|
|
|
|
|
|
|
|
vm.interpreter_reset
|
|
|
|
|
|
|
|
assert_equal(vm.data_stack, [])
|
|
|
|
vm.push(4)
|
|
|
|
assert_equal(vm.data_stack, [4])
|
|
|
|
vm.push(8)
|
|
|
|
assert_equal(vm.data_stack, [4, 8])
|
|
|
|
assert_equal(vm.peek, 8)
|
|
|
|
assert_equal(vm.peek(1), 8)
|
|
|
|
assert_equal(vm.peek(2), 4)
|
|
|
|
assert_equal(vm.pop, 8)
|
|
|
|
assert_equal(vm.data_stack, [4])
|
|
|
|
assert_equal(vm.pop, 4)
|
|
|
|
assert_equal(vm.data_stack, [])
|
2014-11-29 19:53:24 +01:00
|
|
|
|
|
|
|
vm.push(8)
|
|
|
|
assert_equal(vm.data_stack, [8])
|
|
|
|
vm.pushm([1,2,3])
|
|
|
|
assert_equal(vm.data_stack, [8, 1, 2, 3])
|
2014-09-12 00:35:51 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_boolean_stack_data
|
2014-11-13 18:06:25 +01:00
|
|
|
vm = Thread.current[:vm]
|
2014-09-12 00:35:51 +02:00
|
|
|
refute(vm == nil)
|
|
|
|
|
|
|
|
vm.interpreter_reset
|
|
|
|
|
|
|
|
vm.push(16)
|
|
|
|
assert(vm.pop?)
|
|
|
|
|
|
|
|
vm.push(true)
|
|
|
|
assert(vm.pop?)
|
|
|
|
|
|
|
|
vm.push('test')
|
|
|
|
assert(vm.pop?)
|
|
|
|
|
|
|
|
vm.push(0)
|
2014-12-01 03:06:07 +01:00
|
|
|
assert(vm.pop?)
|
2014-09-12 00:35:51 +02:00
|
|
|
|
|
|
|
vm.push(false)
|
|
|
|
refute(vm.pop?)
|
|
|
|
|
|
|
|
vm.push('')
|
2014-12-01 03:06:07 +01:00
|
|
|
assert(vm.pop?)
|
2014-09-12 00:35:51 +02:00
|
|
|
|
|
|
|
vm.push(nil)
|
|
|
|
refute(vm.pop?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_pop_multiple
|
2014-11-13 18:06:25 +01:00
|
|
|
vm = Thread.current[:vm]
|
2014-09-12 00:35:51 +02:00
|
|
|
refute(vm == nil)
|
|
|
|
|
|
|
|
vm.interpreter_reset
|
|
|
|
|
|
|
|
vm.push(16)
|
|
|
|
vm.push(true)
|
|
|
|
vm.push('test')
|
|
|
|
vm.push(0)
|
|
|
|
vm.push('')
|
|
|
|
vm.push(nil)
|
|
|
|
|
|
|
|
assert_equal(vm.data_stack, [16, true, 'test', 0, '', nil])
|
|
|
|
assert_equal(vm.popm(3), [0, '', nil])
|
|
|
|
assert_equal(vm.popm(3), [16, true, 'test'])
|
|
|
|
assert_equal(vm.data_stack, [])
|
|
|
|
end
|
|
|
|
|
2014-11-22 20:18:20 +01:00
|
|
|
def test_poke
|
|
|
|
vm = Thread.current[:vm]
|
|
|
|
refute(vm == nil)
|
|
|
|
|
|
|
|
vm.interpreter_reset
|
|
|
|
|
|
|
|
vm.push(42)
|
|
|
|
vm.poke("hello")
|
|
|
|
assert_equal(vm.data_stack, ["hello"])
|
|
|
|
end
|
|
|
|
|
2014-09-22 06:04:16 +02:00
|
|
|
def test_swap_pop
|
2014-11-13 18:06:25 +01:00
|
|
|
vm = Thread.current[:vm]
|
2014-09-22 06:04:16 +02:00
|
|
|
refute(vm == nil)
|
|
|
|
|
|
|
|
vm.interpreter_reset
|
|
|
|
|
|
|
|
vm.push(16)
|
|
|
|
vm.push(99)
|
|
|
|
assert_equal(vm.swap_pop, 16)
|
|
|
|
assert_equal(vm.pop, 99)
|
|
|
|
assert_equal(vm.data_stack, [])
|
|
|
|
end
|
|
|
|
|
2014-09-12 00:35:51 +02:00
|
|
|
end
|