2014-10-29 18:53:13 +01:00
|
|
|
# coding: utf-8
|
|
|
|
|
2014-10-30 03:34:00 +01:00
|
|
|
require_relative '../lib/fOOrth'
|
2014-10-29 18:53:13 +01:00
|
|
|
require_relative 'support/foorth_testing'
|
2015-04-12 21:29:54 +02:00
|
|
|
gem 'minitest'
|
2014-11-04 06:26:00 +01:00
|
|
|
require 'minitest/autorun'
|
2014-12-20 01:17:23 +01:00
|
|
|
require 'minitest_visible'
|
2014-10-29 18:53:13 +01:00
|
|
|
|
|
|
|
#Test the standard fOOrth library.
|
2015-04-12 21:29:54 +02:00
|
|
|
class ObjectLibraryTester < Minitest::Test
|
2014-10-29 18:53:13 +01:00
|
|
|
|
|
|
|
include XfOOrthTestExtensions
|
|
|
|
|
2014-12-20 01:17:23 +01:00
|
|
|
#Track mini-test progress.
|
2016-02-18 18:23:04 +01:00
|
|
|
include MinitestVisible
|
2014-10-29 18:53:13 +01:00
|
|
|
|
|
|
|
def test_that_the_object_class_is_available
|
2014-11-13 18:06:25 +01:00
|
|
|
foorth_equal("Object", [Object])
|
2014-10-29 18:53:13 +01:00
|
|
|
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-10-29 18:53:13 +01:00
|
|
|
|
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-20 16:39:21 +02:00
|
|
|
foorth_equal('"abc" protect .mutable?', [false])
|
2016-04-19 17:12:25 +02:00
|
|
|
|
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])
|
2016-04-20 16:39:21 +02:00
|
|
|
foorth_equal('"abc"* protect .mutable?', [false])
|
2016-04-19 17:12:25 +02:00
|
|
|
foorth_raises('"abc"* dup .protect "a" <<', RuntimeError)
|
2016-04-20 16:39:21 +02:00
|
|
|
foorth_raises('"abc"* 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-20 16:39:21 +02:00
|
|
|
foorth_equal('[ "abc" ] 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-20 16:39:21 +02:00
|
|
|
foorth_equal('Object .new protect .mutable?', [false])
|
2016-04-19 16:25:42 +02:00
|
|
|
end
|
|
|
|
|
2014-10-29 18:53:13 +01:00
|
|
|
end
|