fOOrth/integration/object_lib_tests.rb

62 lines
1.9 KiB
Ruby
Raw Normal View History

# coding: utf-8
require_relative '../lib/fOOrth'
require_relative 'support/foorth_testing'
2015-04-12 21:29:54 +02:00
gem 'minitest'
require 'minitest/autorun'
2014-12-20 01:17:23 +01:00
require 'minitest_visible'
#Test the standard fOOrth library.
2015-04-12 21:29:54 +02:00
class ObjectLibraryTester < Minitest::Test
include XfOOrthTestExtensions
2014-12-20 01:17:23 +01:00
#Track mini-test progress.
2016-02-18 18:23:04 +01:00
include MinitestVisible
def test_that_the_object_class_is_available
foorth_equal("Object", [Object])
end
2014-10-30 02:39:29 +01:00
def test_getting_a_things_name
foorth_equal("Object .name", ['Object'])
foorth_equal("Class .name", ['Class'])
foorth_equal("Object .new .name", ['Object instance'])
foorth_equal("45 .name", ['Fixnum instance'])
foorth_equal('"Foobar" .name', ['String instance'])
end
2014-12-03 20:10:20 +01:00
def test_getting_an_object_as_a_string
foorth_equal("4 .to_s", ['4'])
foorth_equal("Object .to_s", ['Object'])
foorth_equal("VirtualMachine .to_s", ['VirtualMachine'])
2014-12-04 06:42:52 +01:00
foorth_equal("4 .strlen", [1])
2014-12-03 20:10:20 +01:00
end
2016-04-19 17:12:25 +02:00
def test_for_mutable_and_protect
2016-04-19 16:25:42 +02:00
foorth_equal('"abc" .mutable?', [false])
2016-04-19 17:12:25 +02:00
foorth_equal('"abc" dup .protect .mutable?', [false])
2016-04-19 16:25:42 +02:00
foorth_equal('"abc"* .mutable?', [true])
2016-04-19 17:12:25 +02:00
foorth_equal('"abc"* dup .protect .mutable?', [false])
foorth_raises('"abc"* dup .protect "a" <<', RuntimeError)
2016-04-19 16:25:42 +02:00
foorth_equal('42 .mutable?', [false])
foorth_equal('42.5 .mutable?', [false])
foorth_equal('42/5 .mutable?', [false])
foorth_equal('42+5i .mutable?', [false])
foorth_equal('[ "abc" ] .mutable?', [true])
2016-04-19 17:12:25 +02:00
foorth_equal('[ "abc" ] dup .protect .mutable?', [false])
2016-04-19 16:25:42 +02:00
foorth_equal('true .mutable?', [false])
foorth_equal('false .mutable?', [false])
foorth_equal('nil .mutable?', [false])
2016-04-19 17:12:25 +02:00
foorth_equal('Object .new dup .protect .mutable?', [false])
2016-04-19 16:25:42 +02:00
end
end