fOOrth 0.6.6 → 0.6.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CODE_OF_CONDUCT.md +49 -0
- data/README.md +32 -1
- data/fOOrth.gemspec +3 -3
- data/integration/array_lib_tests.rb +10 -0
- data/integration/compile_lib_tests.rb +67 -1
- data/integration/exception_lib_tests.rb +4 -0
- data/integration/hash_lib_tests.rb +9 -0
- data/integration/numeric_lib_tests.rb +326 -321
- data/integration/procedure_lib_tests.rb +16 -0
- data/integration/queue_lib_tests.rb +2 -1
- data/integration/stack_lib_tests.rb +2 -1
- data/integration/stdio_lib_tests.rb +62 -0
- data/integration/string_lib_tests.rb +11 -0
- data/integration/thread_lib_tests.rb +19 -5
- data/lib/fOOrth.rb +0 -2
- data/lib/fOOrth/compiler/context.rb +64 -64
- data/lib/fOOrth/compiler/context/locals.rb +34 -34
- data/lib/fOOrth/compiler/context/map_name.rb +85 -74
- data/lib/fOOrth/compiler/context/tags.rb +60 -48
- data/lib/fOOrth/compiler/process/generate.rb +1 -1
- data/lib/fOOrth/compiler/process/procedure.rb +40 -0
- data/lib/fOOrth/compiler/word_specs.rb +3 -3
- data/lib/fOOrth/core/object.rb +1 -1
- data/lib/fOOrth/library.rb +3 -0
- data/lib/fOOrth/library/alias_library.rb +126 -0
- data/lib/fOOrth/library/array_library.rb +41 -21
- data/lib/fOOrth/library/command_library.rb +1 -1
- data/lib/fOOrth/library/compile_library.rb +266 -264
- data/lib/fOOrth/library/complex_library.rb +82 -80
- data/lib/fOOrth/library/float_library.rb +37 -0
- data/lib/fOOrth/library/formatting/array.rb +90 -0
- data/lib/fOOrth/library/formatting/bullets.rb +15 -79
- data/lib/fOOrth/library/formatting/columns.rb +20 -42
- data/lib/fOOrth/library/formatting/hash.rb +29 -0
- data/lib/fOOrth/library/formatting/nil.rb +13 -0
- data/lib/fOOrth/library/formatting/object.rb +18 -0
- data/lib/fOOrth/library/formatting/string.rb +46 -0
- data/lib/fOOrth/library/hash_library.rb +14 -6
- data/lib/fOOrth/library/introspection/class.rb +20 -18
- data/lib/fOOrth/library/introspection/context.rb +3 -2
- data/lib/fOOrth/library/introspection/object.rb +42 -20
- data/lib/fOOrth/library/introspection/string.rb +21 -5
- data/lib/fOOrth/library/introspection/vm.rb +17 -29
- data/lib/fOOrth/library/mutex_library.rb +8 -1
- data/lib/fOOrth/library/numeric_library.rb +359 -380
- data/lib/fOOrth/library/procedure_library.rb +69 -65
- data/lib/fOOrth/library/queue_library.rb +6 -1
- data/lib/fOOrth/library/rational_library.rb +89 -89
- data/lib/fOOrth/library/stack_library.rb +6 -1
- data/lib/fOOrth/library/stdio_library.rb +11 -8
- data/lib/fOOrth/library/string_library.rb +21 -6
- data/lib/fOOrth/library/stubs_library.rb +49 -0
- data/lib/fOOrth/monkey_patch/exceptions.rb +2 -6
- data/lib/fOOrth/monkey_patch/object.rb +7 -0
- data/lib/fOOrth/version.rb +1 -1
- data/reek.txt +1 -59
- data/sire.rb +0 -1
- data/tests/compiler/context_tests.rb +188 -177
- data/tests/compiler/file_source_tests.rb +130 -130
- data/tests/compiler/parser_tests.rb +4 -4
- data/tests/compiler/string_source_tests.rb +4 -4
- data/tests/core_tests.rb +138 -138
- data/tests/monkey_patch/complex_test.rb +24 -24
- data/tests/monkey_patch/object_test.rb +49 -49
- data/tests/monkey_patch/string_test.rb +61 -61
- metadata +20 -13
@@ -1,130 +1,130 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
$exclude_fOOrth_library = true
|
4
|
-
require_relative '../../lib/fOOrth'
|
5
|
-
gem 'minitest'
|
6
|
-
require 'minitest/autorun'
|
7
|
-
require 'minitest_visible'
|
8
|
-
|
9
|
-
#Test the monkey patches applied to the Object class.
|
10
|
-
class FileSourceTester < Minitest::Test
|
11
|
-
|
12
|
-
#Track mini-test progress.
|
13
|
-
include MinitestVisible
|
14
|
-
|
15
|
-
#Test that we can read from a single line string
|
16
|
-
def test_single_line_file
|
17
|
-
source = XfOOrth::FileSource.new("tests/compiler/file_source_test_one.txt")
|
18
|
-
|
19
|
-
assert_equal(source.get, 'a')
|
20
|
-
refute(source.eoln?)
|
21
|
-
refute(source.eof?)
|
22
|
-
|
23
|
-
assert_equal(source.get, 'b')
|
24
|
-
refute(source.eoln?)
|
25
|
-
refute(source.eof?)
|
26
|
-
|
27
|
-
assert_equal(source.get, 'c')
|
28
|
-
refute(source.eoln?)
|
29
|
-
refute(source.eof?)
|
30
|
-
|
31
|
-
assert_equal(source.get, ' ')
|
32
|
-
assert(source.eoln?)
|
33
|
-
refute(source.eof?)
|
34
|
-
|
35
|
-
|
36
|
-
assert(source.eoln?)
|
37
|
-
assert(source.eof?)
|
38
|
-
|
39
|
-
source.close
|
40
|
-
end
|
41
|
-
|
42
|
-
#Test that we can read from a multi-line string
|
43
|
-
def test_multi_line_string
|
44
|
-
source = XfOOrth::FileSource.new("tests/compiler/file_source_test_two.txt")
|
45
|
-
|
46
|
-
assert_equal(source.get, 'a')
|
47
|
-
refute(source.eoln?)
|
48
|
-
refute(source.eof?)
|
49
|
-
|
50
|
-
assert_equal(source.get, ' ')
|
51
|
-
assert(source.eoln?)
|
52
|
-
refute(source.eof?)
|
53
|
-
|
54
|
-
assert_equal(source.get, 'b')
|
55
|
-
refute(source.eoln?)
|
56
|
-
refute(source.eof?)
|
57
|
-
|
58
|
-
assert_equal(source.get, ' ')
|
59
|
-
assert(source.eoln?)
|
60
|
-
refute(source.eof?)
|
61
|
-
|
62
|
-
assert_equal(source.get, 'c')
|
63
|
-
refute(source.eoln?)
|
64
|
-
refute(source.eof?)
|
65
|
-
|
66
|
-
assert_equal(source.get, ' ')
|
67
|
-
assert(source.eoln?)
|
68
|
-
refute(source.eof?)
|
69
|
-
|
70
|
-
|
71
|
-
assert(source.eoln?)
|
72
|
-
assert(source.eof?)
|
73
|
-
|
74
|
-
source.close
|
75
|
-
end
|
76
|
-
|
77
|
-
#Test that we can read from a multi-line string again
|
78
|
-
def test_multi_line_string_again
|
79
|
-
source = XfOOrth::FileSource.new("tests/compiler/file_source_test_three.txt")
|
80
|
-
|
81
|
-
assert_equal(source.get, 'a')
|
82
|
-
refute(source.eoln?)
|
83
|
-
refute(source.eof?)
|
84
|
-
|
85
|
-
assert_equal(source.get, ' ')
|
86
|
-
assert(source.eoln?)
|
87
|
-
refute(source.eof?)
|
88
|
-
|
89
|
-
assert_equal(source.get, 'b')
|
90
|
-
refute(source.eoln?)
|
91
|
-
refute(source.eof?)
|
92
|
-
|
93
|
-
assert_equal(source.get, ' ')
|
94
|
-
assert(source.eoln?)
|
95
|
-
refute(source.eof?)
|
96
|
-
|
97
|
-
assert_equal(source.get, 'c')
|
98
|
-
refute(source.eoln?)
|
99
|
-
refute(source.eof?)
|
100
|
-
|
101
|
-
assert_equal(source.get, ' ')
|
102
|
-
assert(source.eoln?)
|
103
|
-
refute(source.eof?)
|
104
|
-
|
105
|
-
|
106
|
-
assert(source.eoln?)
|
107
|
-
assert(source.eof?)
|
108
|
-
|
109
|
-
source.close
|
110
|
-
end
|
111
|
-
|
112
|
-
#Test closing part way through the source.
|
113
|
-
def test_closing
|
114
|
-
source = XfOOrth::FileSource.new("tests/compiler/file_source_test_one.txt")
|
115
|
-
|
116
|
-
assert_equal(source.get, 'a')
|
117
|
-
refute(source.eoln?)
|
118
|
-
refute(source.eof?)
|
119
|
-
|
120
|
-
source.close
|
121
|
-
|
122
|
-
assert(source.eoln?)
|
123
|
-
assert(source.eof?)
|
124
|
-
|
125
|
-
|
126
|
-
assert(source.eoln?)
|
127
|
-
assert(source.eof?)
|
128
|
-
end
|
129
|
-
|
130
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
$exclude_fOOrth_library = true
|
4
|
+
require_relative '../../lib/fOOrth'
|
5
|
+
gem 'minitest'
|
6
|
+
require 'minitest/autorun'
|
7
|
+
require 'minitest_visible'
|
8
|
+
|
9
|
+
#Test the monkey patches applied to the Object class.
|
10
|
+
class FileSourceTester < Minitest::Test
|
11
|
+
|
12
|
+
#Track mini-test progress.
|
13
|
+
include MinitestVisible
|
14
|
+
|
15
|
+
#Test that we can read from a single line string
|
16
|
+
def test_single_line_file
|
17
|
+
source = XfOOrth::FileSource.new("tests/compiler/file_source_test_one.txt")
|
18
|
+
|
19
|
+
assert_equal(source.get, 'a')
|
20
|
+
refute(source.eoln?)
|
21
|
+
refute(source.eof?)
|
22
|
+
|
23
|
+
assert_equal(source.get, 'b')
|
24
|
+
refute(source.eoln?)
|
25
|
+
refute(source.eof?)
|
26
|
+
|
27
|
+
assert_equal(source.get, 'c')
|
28
|
+
refute(source.eoln?)
|
29
|
+
refute(source.eof?)
|
30
|
+
|
31
|
+
assert_equal(source.get, ' ')
|
32
|
+
assert(source.eoln?)
|
33
|
+
refute(source.eof?)
|
34
|
+
|
35
|
+
assert_nil(source.get)
|
36
|
+
assert(source.eoln?)
|
37
|
+
assert(source.eof?)
|
38
|
+
|
39
|
+
source.close
|
40
|
+
end
|
41
|
+
|
42
|
+
#Test that we can read from a multi-line string
|
43
|
+
def test_multi_line_string
|
44
|
+
source = XfOOrth::FileSource.new("tests/compiler/file_source_test_two.txt")
|
45
|
+
|
46
|
+
assert_equal(source.get, 'a')
|
47
|
+
refute(source.eoln?)
|
48
|
+
refute(source.eof?)
|
49
|
+
|
50
|
+
assert_equal(source.get, ' ')
|
51
|
+
assert(source.eoln?)
|
52
|
+
refute(source.eof?)
|
53
|
+
|
54
|
+
assert_equal(source.get, 'b')
|
55
|
+
refute(source.eoln?)
|
56
|
+
refute(source.eof?)
|
57
|
+
|
58
|
+
assert_equal(source.get, ' ')
|
59
|
+
assert(source.eoln?)
|
60
|
+
refute(source.eof?)
|
61
|
+
|
62
|
+
assert_equal(source.get, 'c')
|
63
|
+
refute(source.eoln?)
|
64
|
+
refute(source.eof?)
|
65
|
+
|
66
|
+
assert_equal(source.get, ' ')
|
67
|
+
assert(source.eoln?)
|
68
|
+
refute(source.eof?)
|
69
|
+
|
70
|
+
assert_nil(source.get)
|
71
|
+
assert(source.eoln?)
|
72
|
+
assert(source.eof?)
|
73
|
+
|
74
|
+
source.close
|
75
|
+
end
|
76
|
+
|
77
|
+
#Test that we can read from a multi-line string again
|
78
|
+
def test_multi_line_string_again
|
79
|
+
source = XfOOrth::FileSource.new("tests/compiler/file_source_test_three.txt")
|
80
|
+
|
81
|
+
assert_equal(source.get, 'a')
|
82
|
+
refute(source.eoln?)
|
83
|
+
refute(source.eof?)
|
84
|
+
|
85
|
+
assert_equal(source.get, ' ')
|
86
|
+
assert(source.eoln?)
|
87
|
+
refute(source.eof?)
|
88
|
+
|
89
|
+
assert_equal(source.get, 'b')
|
90
|
+
refute(source.eoln?)
|
91
|
+
refute(source.eof?)
|
92
|
+
|
93
|
+
assert_equal(source.get, ' ')
|
94
|
+
assert(source.eoln?)
|
95
|
+
refute(source.eof?)
|
96
|
+
|
97
|
+
assert_equal(source.get, 'c')
|
98
|
+
refute(source.eoln?)
|
99
|
+
refute(source.eof?)
|
100
|
+
|
101
|
+
assert_equal(source.get, ' ')
|
102
|
+
assert(source.eoln?)
|
103
|
+
refute(source.eof?)
|
104
|
+
|
105
|
+
assert_nil(source.get)
|
106
|
+
assert(source.eoln?)
|
107
|
+
assert(source.eof?)
|
108
|
+
|
109
|
+
source.close
|
110
|
+
end
|
111
|
+
|
112
|
+
#Test closing part way through the source.
|
113
|
+
def test_closing
|
114
|
+
source = XfOOrth::FileSource.new("tests/compiler/file_source_test_one.txt")
|
115
|
+
|
116
|
+
assert_equal(source.get, 'a')
|
117
|
+
refute(source.eoln?)
|
118
|
+
refute(source.eof?)
|
119
|
+
|
120
|
+
source.close
|
121
|
+
|
122
|
+
assert(source.eoln?)
|
123
|
+
assert(source.eof?)
|
124
|
+
|
125
|
+
assert_nil(source.get)
|
126
|
+
assert(source.eoln?)
|
127
|
+
assert(source.eof?)
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
@@ -22,7 +22,7 @@ class ParserTester < Minitest::Test
|
|
22
22
|
assert_equal(parser.get_word_raw, '3')
|
23
23
|
assert_equal(parser.get_word_raw, '+')
|
24
24
|
assert_equal(parser.get_word_raw, '.')
|
25
|
-
|
25
|
+
assert_nil(parser.get_word_raw)
|
26
26
|
end
|
27
27
|
|
28
28
|
#Test parsing strings.
|
@@ -67,7 +67,7 @@ class ParserTester < Minitest::Test
|
|
67
67
|
parser.skip_over_comment
|
68
68
|
assert_equal(parser.get_word_raw, '+')
|
69
69
|
assert_equal(parser.get_word_raw, '.')
|
70
|
-
|
70
|
+
assert_nil(parser.get_word_raw)
|
71
71
|
end
|
72
72
|
|
73
73
|
#Test parsing ill-nested comments.
|
@@ -97,7 +97,7 @@ class ParserTester < Minitest::Test
|
|
97
97
|
parser.skip_to_eoln
|
98
98
|
assert_equal(parser.get_word_raw, '+')
|
99
99
|
assert_equal(parser.get_word_raw, '.')
|
100
|
-
|
100
|
+
assert_nil(parser.get_word_raw)
|
101
101
|
end
|
102
102
|
|
103
103
|
#Test parsing of words.
|
@@ -110,7 +110,7 @@ class ParserTester < Minitest::Test
|
|
110
110
|
assert_equal(parser.get_word, '2')
|
111
111
|
assert_equal(parser.get_word, '+')
|
112
112
|
assert_equal(parser.get_word, '.')
|
113
|
-
|
113
|
+
assert_nil(parser.get_word)
|
114
114
|
end
|
115
115
|
|
116
116
|
end
|
@@ -33,7 +33,7 @@ class StringSourceTester < Minitest::Test
|
|
33
33
|
assert(source.eoln?)
|
34
34
|
refute(source.eof?)
|
35
35
|
|
36
|
-
|
36
|
+
assert_nil(source.get)
|
37
37
|
assert(source.eoln?)
|
38
38
|
assert(source.eof?)
|
39
39
|
end
|
@@ -67,7 +67,7 @@ class StringSourceTester < Minitest::Test
|
|
67
67
|
assert(source.eoln?)
|
68
68
|
refute(source.eof?)
|
69
69
|
|
70
|
-
|
70
|
+
assert_nil(source.get)
|
71
71
|
assert(source.eoln?)
|
72
72
|
assert(source.eof?)
|
73
73
|
end
|
@@ -101,7 +101,7 @@ class StringSourceTester < Minitest::Test
|
|
101
101
|
assert(source.eoln?)
|
102
102
|
refute(source.eof?)
|
103
103
|
|
104
|
-
|
104
|
+
assert_nil(source.get)
|
105
105
|
assert(source.eoln?)
|
106
106
|
assert(source.eof?)
|
107
107
|
end
|
@@ -120,7 +120,7 @@ class StringSourceTester < Minitest::Test
|
|
120
120
|
assert(source.eoln?)
|
121
121
|
assert(source.eof?)
|
122
122
|
|
123
|
-
|
123
|
+
assert_nil(source.get)
|
124
124
|
assert(source.eoln?)
|
125
125
|
assert(source.eof?)
|
126
126
|
end
|
data/tests/core_tests.rb
CHANGED
@@ -1,138 +1,138 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
$exclude_fOOrth_library = true
|
4
|
-
require_relative '../lib/fOOrth'
|
5
|
-
gem 'minitest'
|
6
|
-
require 'minitest/autorun'
|
7
|
-
require 'minitest_visible'
|
8
|
-
|
9
|
-
#Test the monkey patches applied to the Object class.
|
10
|
-
class CoreTester < Minitest::Test
|
11
|
-
|
12
|
-
#Track mini-test progress.
|
13
|
-
include MinitestVisible
|
14
|
-
|
15
|
-
def test_that_object_handles_no_method_errors
|
16
|
-
#Get an object instance to test with.
|
17
|
-
obj = Object.new
|
18
|
-
|
19
|
-
XfOOrth::SymbolMap.add_entry("a_test_zero", :a_test_zero)
|
20
|
-
|
21
|
-
assert_raises(XfOOrth::XfOOrthError) do
|
22
|
-
obj.a_test_zero
|
23
|
-
end
|
24
|
-
|
25
|
-
assert_raises(NoMethodError) do
|
26
|
-
obj.qwertyuiop
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_that_shared_methods_can_be_defined
|
31
|
-
#Get an object instance to test with.
|
32
|
-
obj = Object.new
|
33
|
-
|
34
|
-
#Get the virtual machine.
|
35
|
-
vm = Thread.current[:vm]
|
36
|
-
|
37
|
-
XfOOrth::SymbolMap.add_entry("a_test_one", :a_test_one)
|
38
|
-
|
39
|
-
spec = Object.create_shared_method("a_test_one", XfOOrth::TosSpec, []) {|lvm| lvm.push(9671111) }
|
40
|
-
|
41
|
-
obj.a_test_one(vm)
|
42
|
-
|
43
|
-
assert_equal(9671111, vm.pop)
|
44
|
-
assert_equal(spec, Object.map_foorth_shared(:a_test_one))
|
45
|
-
assert_equal(spec, Class.map_foorth_shared(:a_test_one))
|
46
|
-
assert_equal(spec, Object.foorth_shared[:a_test_one])
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_that_exclusive_methods_can_be_defined
|
51
|
-
#Get an object instance to test with.
|
52
|
-
obj = Object.new
|
53
|
-
|
54
|
-
#Get the virtual machine.
|
55
|
-
vm = XfOOrth::VirtualMachine.vm
|
56
|
-
|
57
|
-
XfOOrth::SymbolMap.add_entry("a_test_two", :a_test_two)
|
58
|
-
|
59
|
-
spec = obj.create_exclusive_method("a_test_two", XfOOrth::TosSpec, []) do |lvm|
|
60
|
-
lvm.push(9686668)
|
61
|
-
end
|
62
|
-
|
63
|
-
obj.a_test_two(vm)
|
64
|
-
|
65
|
-
assert_equal(9686668, vm.pop)
|
66
|
-
assert_equal(spec, obj.map_foorth_exclusive(:a_test_two))
|
67
|
-
assert_equal(spec, obj.foorth_exclusive[:a_test_two])
|
68
|
-
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_class_naming
|
73
|
-
assert_equal("Object", Object.foorth_name)
|
74
|
-
assert_equal("Class", Class.foorth_name)
|
75
|
-
assert_equal("VirtualMachine", XfOOrth::VirtualMachine.foorth_name)
|
76
|
-
|
77
|
-
vm = Thread.current[:vm]
|
78
|
-
assert_equal("VirtualMachine instance <Main>", vm.foorth_name)
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_instance_naming
|
82
|
-
obj = Object.new
|
83
|
-
assert_equal("Object instance", obj.foorth_name)
|
84
|
-
|
85
|
-
vm = Thread.current[:vm]
|
86
|
-
assert_equal("VirtualMachine instance <Main>", vm.foorth_name)
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_that_virtual_machine_rejects_new
|
90
|
-
assert_raises(XfOOrth::XfOOrthError) do
|
91
|
-
XfOOrth::VirtualMachine.new('Fails')
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_that_the_VM_class_does_not_subclass
|
96
|
-
assert_raises(XfOOrth::XfOOrthError) do
|
97
|
-
XfOOrth::VirtualMachine.create_foorth_subclass("MyClass")
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_creating_subclasses
|
102
|
-
new_class = Object.create_foorth_subclass('MyClass')
|
103
|
-
symbol = XfOOrth::SymbolMap.map('MyClass')
|
104
|
-
|
105
|
-
assert($FOORTH_GLOBALS[symbol])
|
106
|
-
assert_equal('ClassSpec instance', new_class.foorth_name)
|
107
|
-
assert_equal(XfOOrth::XfOOrth_MyClass, new_class.new_class)
|
108
|
-
assert_equal(XfOOrth::XfOOrth_MyClass, $FOORTH_GLOBALS[symbol].new_class)
|
109
|
-
|
110
|
-
assert_raises(XfOOrth::XfOOrthError) do
|
111
|
-
Object.create_foorth_subclass('No Class')
|
112
|
-
end
|
113
|
-
|
114
|
-
assert_raises(XfOOrth::XfOOrthError) do
|
115
|
-
Object.create_foorth_subclass('MyClass')
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
def test_creating_proxies
|
120
|
-
new_proxy = String.create_foorth_proxy
|
121
|
-
symbol = XfOOrth::SymbolMap.map('String')
|
122
|
-
|
123
|
-
assert($FOORTH_GLOBALS[symbol])
|
124
|
-
assert_equal('String', new_proxy.new_class.foorth_name)
|
125
|
-
assert_equal(String, new_proxy.new_class)
|
126
|
-
assert_equal(String, $FOORTH_GLOBALS[symbol].new_class)
|
127
|
-
|
128
|
-
assert_raises(XfOOrth::XfOOrthError) do
|
129
|
-
Object.create_foorth_subclass('My Class')
|
130
|
-
end
|
131
|
-
|
132
|
-
assert_raises(XfOOrth::XfOOrthError) do
|
133
|
-
Module.create_foorth_proxy('Mod ule')
|
134
|
-
end
|
135
|
-
|
136
|
-
end
|
137
|
-
|
138
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
$exclude_fOOrth_library = true
|
4
|
+
require_relative '../lib/fOOrth'
|
5
|
+
gem 'minitest'
|
6
|
+
require 'minitest/autorun'
|
7
|
+
require 'minitest_visible'
|
8
|
+
|
9
|
+
#Test the monkey patches applied to the Object class.
|
10
|
+
class CoreTester < Minitest::Test
|
11
|
+
|
12
|
+
#Track mini-test progress.
|
13
|
+
include MinitestVisible
|
14
|
+
|
15
|
+
def test_that_object_handles_no_method_errors
|
16
|
+
#Get an object instance to test with.
|
17
|
+
obj = Object.new
|
18
|
+
|
19
|
+
XfOOrth::SymbolMap.add_entry("a_test_zero", :a_test_zero)
|
20
|
+
|
21
|
+
assert_raises(XfOOrth::XfOOrthError) do
|
22
|
+
obj.a_test_zero
|
23
|
+
end
|
24
|
+
|
25
|
+
assert_raises(NoMethodError) do
|
26
|
+
obj.qwertyuiop
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_that_shared_methods_can_be_defined
|
31
|
+
#Get an object instance to test with.
|
32
|
+
obj = Object.new
|
33
|
+
|
34
|
+
#Get the virtual machine.
|
35
|
+
vm = Thread.current[:vm]
|
36
|
+
|
37
|
+
XfOOrth::SymbolMap.add_entry("a_test_one", :a_test_one)
|
38
|
+
|
39
|
+
spec = Object.create_shared_method("a_test_one", XfOOrth::TosSpec, []) {|lvm| lvm.push(9671111) }
|
40
|
+
|
41
|
+
obj.a_test_one(vm)
|
42
|
+
|
43
|
+
assert_equal(9671111, vm.pop)
|
44
|
+
assert_equal(spec, Object.map_foorth_shared(:a_test_one))
|
45
|
+
assert_equal(spec, Class.map_foorth_shared(:a_test_one))
|
46
|
+
assert_equal(spec, Object.foorth_shared[:a_test_one])
|
47
|
+
assert_nil(Class.foorth_shared[:a_test_one])
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_that_exclusive_methods_can_be_defined
|
51
|
+
#Get an object instance to test with.
|
52
|
+
obj = Object.new
|
53
|
+
|
54
|
+
#Get the virtual machine.
|
55
|
+
vm = XfOOrth::VirtualMachine.vm
|
56
|
+
|
57
|
+
XfOOrth::SymbolMap.add_entry("a_test_two", :a_test_two)
|
58
|
+
|
59
|
+
spec = obj.create_exclusive_method("a_test_two", XfOOrth::TosSpec, []) do |lvm|
|
60
|
+
lvm.push(9686668)
|
61
|
+
end
|
62
|
+
|
63
|
+
obj.a_test_two(vm)
|
64
|
+
|
65
|
+
assert_equal(9686668, vm.pop)
|
66
|
+
assert_equal(spec, obj.map_foorth_exclusive(:a_test_two))
|
67
|
+
assert_equal(spec, obj.foorth_exclusive[:a_test_two])
|
68
|
+
assert_nil(Object.map_foorth_shared(:a_test_two))
|
69
|
+
assert_nil(Class.map_foorth_shared(:a_test_two))
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_class_naming
|
73
|
+
assert_equal("Object", Object.foorth_name)
|
74
|
+
assert_equal("Class", Class.foorth_name)
|
75
|
+
assert_equal("VirtualMachine", XfOOrth::VirtualMachine.foorth_name)
|
76
|
+
|
77
|
+
vm = Thread.current[:vm]
|
78
|
+
assert_equal("VirtualMachine instance <Main>", vm.foorth_name)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_instance_naming
|
82
|
+
obj = Object.new
|
83
|
+
assert_equal("Object instance", obj.foorth_name)
|
84
|
+
|
85
|
+
vm = Thread.current[:vm]
|
86
|
+
assert_equal("VirtualMachine instance <Main>", vm.foorth_name)
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_that_virtual_machine_rejects_new
|
90
|
+
assert_raises(XfOOrth::XfOOrthError) do
|
91
|
+
XfOOrth::VirtualMachine.new('Fails')
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_that_the_VM_class_does_not_subclass
|
96
|
+
assert_raises(XfOOrth::XfOOrthError) do
|
97
|
+
XfOOrth::VirtualMachine.create_foorth_subclass("MyClass")
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_creating_subclasses
|
102
|
+
new_class = Object.create_foorth_subclass('MyClass')
|
103
|
+
symbol = XfOOrth::SymbolMap.map('MyClass')
|
104
|
+
|
105
|
+
assert($FOORTH_GLOBALS[symbol])
|
106
|
+
assert_equal('ClassSpec instance', new_class.foorth_name)
|
107
|
+
assert_equal(XfOOrth::XfOOrth_MyClass, new_class.new_class)
|
108
|
+
assert_equal(XfOOrth::XfOOrth_MyClass, $FOORTH_GLOBALS[symbol].new_class)
|
109
|
+
|
110
|
+
assert_raises(XfOOrth::XfOOrthError) do
|
111
|
+
Object.create_foorth_subclass('No Class')
|
112
|
+
end
|
113
|
+
|
114
|
+
assert_raises(XfOOrth::XfOOrthError) do
|
115
|
+
Object.create_foorth_subclass('MyClass')
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_creating_proxies
|
120
|
+
new_proxy = String.create_foorth_proxy
|
121
|
+
symbol = XfOOrth::SymbolMap.map('String')
|
122
|
+
|
123
|
+
assert($FOORTH_GLOBALS[symbol])
|
124
|
+
assert_equal('String', new_proxy.new_class.foorth_name)
|
125
|
+
assert_equal(String, new_proxy.new_class)
|
126
|
+
assert_equal(String, $FOORTH_GLOBALS[symbol].new_class)
|
127
|
+
|
128
|
+
assert_raises(XfOOrth::XfOOrthError) do
|
129
|
+
Object.create_foorth_subclass('My Class')
|
130
|
+
end
|
131
|
+
|
132
|
+
assert_raises(XfOOrth::XfOOrthError) do
|
133
|
+
Module.create_foorth_proxy('Mod ule')
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|