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
@@ -0,0 +1,49 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
#* library/stubs_library.rb - Support for method stubs in fOOrth.
|
4
|
+
module XfOOrth
|
5
|
+
VirtualMachine.create_shared_method('stub:', VmSpec, [:immediate],
|
6
|
+
&lambda {|vm|
|
7
|
+
name = parser.get_word().inspect
|
8
|
+
process_text("vm.class.create_shared_method(#{name}, VmSpec, [:stub]); ")
|
9
|
+
})
|
10
|
+
|
11
|
+
VirtualMachine.create_shared_method('.stub:', VmSpec, [:immediate],
|
12
|
+
&lambda {|vm|
|
13
|
+
name = parser.get_word().inspect
|
14
|
+
process_text("vm.create_shared_stub(#{name}); ")
|
15
|
+
})
|
16
|
+
|
17
|
+
VirtualMachine.create_shared_method('.stub::', VmSpec, [:immediate],
|
18
|
+
&lambda {|vm|
|
19
|
+
name = parser.get_word().inspect
|
20
|
+
process_text("vm.create_exclusive_stub(#{name}); ")
|
21
|
+
})
|
22
|
+
|
23
|
+
# Stub support methods in the VirtualMachine class.
|
24
|
+
class VirtualMachine
|
25
|
+
|
26
|
+
#Create a shared method stub
|
27
|
+
def create_shared_stub(name)
|
28
|
+
unless (target = pop).is_a?(Class)
|
29
|
+
error "F13: The target of .stub: must be a class"
|
30
|
+
end
|
31
|
+
|
32
|
+
type = XfOOrth.name_to_type(name, self)
|
33
|
+
XfOOrth.validate_type(self, type, name)
|
34
|
+
target.create_shared_method(name, type, [:stub])
|
35
|
+
clear_cast
|
36
|
+
end
|
37
|
+
|
38
|
+
#Create an exclusive method stub
|
39
|
+
def create_exclusive_stub(name)
|
40
|
+
target = pop
|
41
|
+
type = XfOOrth.name_to_type(name, self)
|
42
|
+
XfOOrth.validate_type(self, type, name)
|
43
|
+
target.create_exclusive_method(name, type, [:stub])
|
44
|
+
clear_cast
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -108,13 +108,9 @@ end
|
|
108
108
|
#Extensions to the RunTimeError to support fOOrth
|
109
109
|
class RuntimeError
|
110
110
|
|
111
|
-
#Massage the messages a bit
|
112
|
-
#<br>Endemic Code Smells
|
113
|
-
#* :reek:FeatureEnvy
|
111
|
+
#Massage the messages a bit.
|
114
112
|
def message
|
115
|
-
|
116
|
-
msg["frozen"] && msg["frozen"] = "protected"
|
117
|
-
msg
|
113
|
+
super.gsub(/frozen/, "protected")
|
118
114
|
end
|
119
115
|
|
120
116
|
end
|
@@ -38,6 +38,13 @@ class Object
|
|
38
38
|
fail XfOOrth::XfOOrthError, msg, caller
|
39
39
|
end
|
40
40
|
|
41
|
+
#A helper macro for method not understood errors.
|
42
|
+
def f20_error(recvr, name, symbol)
|
43
|
+
fail XfOOrth::XfOOrthError,
|
44
|
+
"F20: A #{recvr.foorth_name} does not understand #{name} (#{symbol.inspect}).",
|
45
|
+
caller
|
46
|
+
end
|
47
|
+
|
41
48
|
#Argument coercion methods. These are stubs.
|
42
49
|
|
43
50
|
#Coerce the argument to match my type. Stub
|
data/lib/fOOrth/version.rb
CHANGED
data/reek.txt
CHANGED
@@ -1,59 +1 @@
|
|
1
|
-
|
2
|
-
[31]:ControlParameter: XfOOrth::Context#do_map_name is controlled by argument allow_defaults [https://github.com/troessner/reek/blob/master/docs/Control-Parameter.md]
|
3
|
-
lib/fOOrth/library/compile_library.rb -- 2 warnings:
|
4
|
-
[230]:ControlParameter: XfOOrth#self.name_to_type is controlled by argument cast_spec [https://github.com/troessner/reek/blob/master/docs/Control-Parameter.md]
|
5
|
-
[191]:TooManyStatements: XfOOrth#self.add_common_compiler_locals has approx 8 statements [https://github.com/troessner/reek/blob/master/docs/Too-Many-Statements.md]
|
6
|
-
lib/fOOrth/library/formatting/bullets.rb -- 10 warnings:
|
7
|
-
[20, 22]:DuplicateMethodCall: XfOOrth::BulletPoints#add calls raw_bullet.in_array 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
|
8
|
-
[62, 68]:DuplicateMethodCall: XfOOrth::BulletPoints#render_bullet calls ' ' * @key_length 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
|
9
|
-
[67, 76]:DuplicateMethodCall: XfOOrth::BulletPoints#render_bullet calls result << temp 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
|
10
|
-
[63, 69]:DuplicateMethodCall: XfOOrth::BulletPoints#render_bullet calls temp.length 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
|
11
|
-
[26, 27]:FeatureEnvy: XfOOrth::BulletPoints#add refers to items more than self (maybe move it to another class?) [https://github.com/troessner/reek/blob/master/docs/Feature-Envy.md]
|
12
|
-
[20, 22]:FeatureEnvy: XfOOrth::BulletPoints#add refers to raw_bullet more than self (maybe move it to another class?) [https://github.com/troessner/reek/blob/master/docs/Feature-Envy.md]
|
13
|
-
[18, 23]:FeatureEnvy: XfOOrth::BulletPoints#add refers to raw_item more than self (maybe move it to another class?) [https://github.com/troessner/reek/blob/master/docs/Feature-Envy.md]
|
14
|
-
[83]:IrresponsibleModule: Array has no descriptive comment [https://github.com/troessner/reek/blob/master/docs/Irresponsible-Module.md]
|
15
|
-
[103]:IrresponsibleModule: Hash has no descriptive comment [https://github.com/troessner/reek/blob/master/docs/Irresponsible-Module.md]
|
16
|
-
[51]:TooManyStatements: XfOOrth::BulletPoints#render_bullet has approx 15 statements [https://github.com/troessner/reek/blob/master/docs/Too-Many-Statements.md]
|
17
|
-
lib/fOOrth/library/formatting/columns.rb -- 2 warnings:
|
18
|
-
[36]:NestedIterators: XfOOrth::ColumnizedPage#render contains iterators nested 2 deep [https://github.com/troessner/reek/blob/master/docs/Nested-Iterators.md]
|
19
|
-
[31]:TooManyStatements: XfOOrth::ColumnizedPage#render has approx 8 statements [https://github.com/troessner/reek/blob/master/docs/Too-Many-Statements.md]
|
20
|
-
lib/fOOrth/library/introspection/class.rb -- 15 warnings:
|
21
|
-
[35, 42]:DuplicateMethodCall: Class#foorth_method_info calls !spec.has_tag?(:stub) 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
|
22
|
-
[36, 43]:DuplicateMethodCall: Class#foorth_method_info calls (results << ["", ""]).concat(info) 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
|
23
|
-
[36, 43]:DuplicateMethodCall: Class#foorth_method_info calls (results << ["", ""]).concat(info).concat(spec.get_info) 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
|
24
|
-
[36, 43]:DuplicateMethodCall: Class#foorth_method_info calls results << ["", ""] 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
|
25
|
-
[36, 43]:DuplicateMethodCall: Class#foorth_method_info calls spec.get_info 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
|
26
|
-
[35, 42]:DuplicateMethodCall: Class#foorth_method_info calls spec.has_tag?(:stub) 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
|
27
|
-
[62, 74]:DuplicateMethodCall: Class#get_info calls (results << ["", ""]).concat(info) 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
|
28
|
-
[61, 73]:DuplicateMethodCall: Class#get_info calls XfOOrth::SymbolMap.map_info(name) 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
|
29
|
-
[62, 74]:DuplicateMethodCall: Class#get_info calls results << ["", ""] 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
|
30
|
-
[65, 77]:DuplicateMethodCall: Class#get_info calls results.concat(info) 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
|
31
|
-
[65, 77]:DuplicateMethodCall: Class#get_info calls results.concat(info).concat(spec.get_info) 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
|
32
|
-
[65, 77]:DuplicateMethodCall: Class#get_info calls spec.get_info 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
|
33
|
-
[35, 36, 42, 43]:FeatureEnvy: Class#foorth_method_info refers to spec more than self (maybe move it to another class?) [https://github.com/troessner/reek/blob/master/docs/Feature-Envy.md]
|
34
|
-
[28]:TooManyStatements: Class#foorth_method_info has approx 10 statements [https://github.com/troessner/reek/blob/master/docs/Too-Many-Statements.md]
|
35
|
-
[54]:TooManyStatements: Class#get_info has approx 14 statements [https://github.com/troessner/reek/blob/master/docs/Too-Many-Statements.md]
|
36
|
-
lib/fOOrth/library/introspection/context.rb -- 3 warnings:
|
37
|
-
[14, 28]:DuplicateMethodCall: XfOOrth::Context#get_info calls results << ["", ""] 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
|
38
|
-
[14, 17, 18, 19, 21, 22, 28, 29]:FeatureEnvy: XfOOrth::Context#get_info refers to results more than self (maybe move it to another class?) [https://github.com/troessner/reek/blob/master/docs/Feature-Envy.md]
|
39
|
-
[10]:TooManyStatements: XfOOrth::Context#get_info has approx 11 statements [https://github.com/troessner/reek/blob/master/docs/Too-Many-Statements.md]
|
40
|
-
lib/fOOrth/library/introspection/object.rb -- 3 warnings:
|
41
|
-
[53, 57]:FeatureEnvy: Object#foorth_method_info refers to results more than self (maybe move it to another class?) [https://github.com/troessner/reek/blob/master/docs/Feature-Envy.md]
|
42
|
-
[52, 53]:FeatureEnvy: Object#foorth_method_info refers to spec more than self (maybe move it to another class?) [https://github.com/troessner/reek/blob/master/docs/Feature-Envy.md]
|
43
|
-
[18]:TooManyStatements: Object#get_info has approx 12 statements [https://github.com/troessner/reek/blob/master/docs/Too-Many-Statements.md]
|
44
|
-
lib/fOOrth/library/introspection/string.rb -- 10 warnings:
|
45
|
-
[17, 20]:DuplicateMethodCall: String#foorth_method_scan calls (results << ["", ""]).concat(info) 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
|
46
|
-
[17, 20]:DuplicateMethodCall: String#foorth_method_scan calls (results << ["", ""]).concat(info).concat(spec.get_info) 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
|
47
|
-
[17, 20]:DuplicateMethodCall: String#foorth_method_scan calls results << ["", ""] 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
|
48
|
-
[17, 20]:DuplicateMethodCall: String#foorth_method_scan calls spec.get_info 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
|
49
|
-
[17, 20, 23]:FeatureEnvy: String#foorth_method_scan refers to found more than self (maybe move it to another class?) [https://github.com/troessner/reek/blob/master/docs/Feature-Envy.md]
|
50
|
-
[17, 20, 23]:FeatureEnvy: String#foorth_method_scan refers to results more than self (maybe move it to another class?) [https://github.com/troessner/reek/blob/master/docs/Feature-Envy.md]
|
51
|
-
[13, 17, 20]:FeatureEnvy: String#foorth_method_scan refers to spec more than self (maybe move it to another class?) [https://github.com/troessner/reek/blob/master/docs/Feature-Envy.md]
|
52
|
-
[7]:TooManyStatements: String#foorth_method_scan has approx 12 statements [https://github.com/troessner/reek/blob/master/docs/Too-Many-Statements.md]
|
53
|
-
[14]:UncommunicativeVariableName: String#foorth_method_scan has the variable name 'a' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Variable-Name.md]
|
54
|
-
[14]:UncommunicativeVariableName: String#foorth_method_scan has the variable name 'b' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Variable-Name.md]
|
55
|
-
lib/fOOrth/library/introspection/vm.rb -- 3 warnings:
|
56
|
-
[10]:TooManyStatements: XfOOrth::VirtualMachine#get_info has approx 22 statements [https://github.com/troessner/reek/blob/master/docs/Too-Many-Statements.md]
|
57
|
-
[47]:UncommunicativeVariableName: XfOOrth::VirtualMachine#get_info has the variable name 'a' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Variable-Name.md]
|
58
|
-
[47]:UncommunicativeVariableName: XfOOrth::VirtualMachine#get_info has the variable name 'b' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Variable-Name.md]
|
59
|
-
49 total warnings
|
1
|
+
0 total warnings
|
data/sire.rb
CHANGED
@@ -1,177 +1,188 @@
|
|
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
|
-
class MockClass
|
10
|
-
def initialize; @data = {}; end
|
11
|
-
def []=(index, value); @data[index] = value; end
|
12
|
-
def map_foorth_shared(index); @data[index]; end
|
13
|
-
end
|
14
|
-
|
15
|
-
class MockObject
|
16
|
-
def initialize; @data = {}; end
|
17
|
-
def []=(index, value); @data[index] = value; end
|
18
|
-
def map_foorth_exclusive(index); @data[index]; end
|
19
|
-
end
|
20
|
-
|
21
|
-
#Test the monkey patches applied to the Object class.
|
22
|
-
class ContextTester < Minitest::Test
|
23
|
-
|
24
|
-
#Track mini-test progress.
|
25
|
-
include MinitestVisible
|
26
|
-
|
27
|
-
def test_data_store
|
28
|
-
context = XfOOrth::Context.new(45, stuff: 'buy', price: :plenty)
|
29
|
-
|
30
|
-
assert_equal(context.previous, 45)
|
31
|
-
assert_equal(context[:stuff], 'buy')
|
32
|
-
assert_equal(context[:price], :plenty)
|
33
|
-
|
34
|
-
context[:stuff] = 'sell'
|
35
|
-
assert_equal(context[:stuff], 'sell')
|
36
|
-
assert_equal(context[:price], :plenty)
|
37
|
-
|
38
|
-
context[:price] = 9.95
|
39
|
-
assert_equal(context[:stuff], 'sell')
|
40
|
-
assert_equal(context[:price], 9.95)
|
41
|
-
end
|
42
|
-
|
43
|
-
#Test level counting
|
44
|
-
def test_level_tracking
|
45
|
-
context = XfOOrth::Context.new(nil, stuff: 'buy')
|
46
|
-
assert_equal(context.depth, 1)
|
47
|
-
|
48
|
-
context = XfOOrth::Context.new(context, stuff: 'other')
|
49
|
-
assert_equal(context.depth, 2)
|
50
|
-
|
51
|
-
context = XfOOrth::Context.new(context, stuff: 'more')
|
52
|
-
assert_equal(context.depth, 3)
|
53
|
-
|
54
|
-
context = context.previous
|
55
|
-
assert_equal(context.depth, 2)
|
56
|
-
|
57
|
-
context = context.previous
|
58
|
-
assert_equal(context.depth, 1)
|
59
|
-
|
60
|
-
context = context.previous
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_the_nesting_of_scopes
|
65
|
-
context = XfOOrth::Context.new(nil, stuff: 'buy')
|
66
|
-
|
67
|
-
|
68
|
-
assert_equal(context[:stuff], 'buy')
|
69
|
-
context[:foo] = 1
|
70
|
-
context[:jelly] = 'donut'
|
71
|
-
assert_equal(context[:jelly], 'donut')
|
72
|
-
assert_equal(context[:stuff], 'buy')
|
73
|
-
assert_equal(context[:foo], 1)
|
74
|
-
|
75
|
-
context = XfOOrth::Context.new(context, stuff: 'other')
|
76
|
-
assert_equal(context[:foo], 1)
|
77
|
-
assert_equal(context[:jelly], 'donut')
|
78
|
-
assert_equal(context[:stuff], 'other')
|
79
|
-
context[:foo] = 2
|
80
|
-
assert_equal(context[:jelly], 'donut')
|
81
|
-
assert_equal(context[:stuff], 'other')
|
82
|
-
assert_equal(context[:foo], 2)
|
83
|
-
|
84
|
-
context = XfOOrth::Context.new(context, stuff: 'more')
|
85
|
-
assert_equal(context[:foo], 2)
|
86
|
-
assert_equal(context[:jelly], 'donut')
|
87
|
-
assert_equal(context[:stuff], 'more')
|
88
|
-
context[:foo] = 3
|
89
|
-
context[:jelly] = 'Berliner'
|
90
|
-
assert_equal(context[:jelly], 'Berliner')
|
91
|
-
assert_equal(context[:stuff], 'more')
|
92
|
-
assert_equal(context[:foo], 3)
|
93
|
-
|
94
|
-
context = context.previous
|
95
|
-
assert_equal(context[:foo], 2)
|
96
|
-
assert_equal(context[:jelly], 'donut')
|
97
|
-
assert_equal(context[:stuff], 'other')
|
98
|
-
|
99
|
-
context = context.previous
|
100
|
-
assert_equal(context[:foo], 1)
|
101
|
-
assert_equal(context[:jelly], 'donut')
|
102
|
-
assert_equal(context[:stuff], 'buy')
|
103
|
-
end
|
104
|
-
|
105
|
-
def
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
context = XfOOrth::Context.new(nil
|
118
|
-
|
119
|
-
name = '
|
120
|
-
sym = XfOOrth::SymbolMap.add_entry(name)
|
121
|
-
|
122
|
-
spec = context.
|
123
|
-
assert(spec.is_a?(XfOOrth::
|
124
|
-
end
|
125
|
-
|
126
|
-
def
|
127
|
-
mk =
|
128
|
-
context = XfOOrth::Context.new(nil,
|
129
|
-
|
130
|
-
name = '.
|
131
|
-
sym = XfOOrth::SymbolMap.add_entry(name)
|
132
|
-
mk[sym] = XfOOrth::TosSpec.new(name, sym, [])
|
133
|
-
spec = context.
|
134
|
-
assert(spec.is_a?(XfOOrth::TosSpec))
|
135
|
-
end
|
136
|
-
|
137
|
-
def
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
context = XfOOrth::Context.new(
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
context.
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
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
|
+
class MockClass
|
10
|
+
def initialize; @data = {}; end
|
11
|
+
def []=(index, value); @data[index] = value; end
|
12
|
+
def map_foorth_shared(index); @data[index]; end
|
13
|
+
end
|
14
|
+
|
15
|
+
class MockObject
|
16
|
+
def initialize; @data = {}; end
|
17
|
+
def []=(index, value); @data[index] = value; end
|
18
|
+
def map_foorth_exclusive(index); @data[index]; end
|
19
|
+
end
|
20
|
+
|
21
|
+
#Test the monkey patches applied to the Object class.
|
22
|
+
class ContextTester < Minitest::Test
|
23
|
+
|
24
|
+
#Track mini-test progress.
|
25
|
+
include MinitestVisible
|
26
|
+
|
27
|
+
def test_data_store
|
28
|
+
context = XfOOrth::Context.new(45, stuff: 'buy', price: :plenty)
|
29
|
+
|
30
|
+
assert_equal(context.previous, 45)
|
31
|
+
assert_equal(context[:stuff], 'buy')
|
32
|
+
assert_equal(context[:price], :plenty)
|
33
|
+
|
34
|
+
context[:stuff] = 'sell'
|
35
|
+
assert_equal(context[:stuff], 'sell')
|
36
|
+
assert_equal(context[:price], :plenty)
|
37
|
+
|
38
|
+
context[:price] = 9.95
|
39
|
+
assert_equal(context[:stuff], 'sell')
|
40
|
+
assert_equal(context[:price], 9.95)
|
41
|
+
end
|
42
|
+
|
43
|
+
#Test level counting
|
44
|
+
def test_level_tracking
|
45
|
+
context = XfOOrth::Context.new(nil, stuff: 'buy')
|
46
|
+
assert_equal(context.depth, 1)
|
47
|
+
|
48
|
+
context = XfOOrth::Context.new(context, stuff: 'other')
|
49
|
+
assert_equal(context.depth, 2)
|
50
|
+
|
51
|
+
context = XfOOrth::Context.new(context, stuff: 'more')
|
52
|
+
assert_equal(context.depth, 3)
|
53
|
+
|
54
|
+
context = context.previous
|
55
|
+
assert_equal(context.depth, 2)
|
56
|
+
|
57
|
+
context = context.previous
|
58
|
+
assert_equal(context.depth, 1)
|
59
|
+
|
60
|
+
context = context.previous
|
61
|
+
assert_nil(context)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_the_nesting_of_scopes
|
65
|
+
context = XfOOrth::Context.new(nil, stuff: 'buy')
|
66
|
+
assert_nil(context[:foo])
|
67
|
+
assert_nil(context[:jelly])
|
68
|
+
assert_equal(context[:stuff], 'buy')
|
69
|
+
context[:foo] = 1
|
70
|
+
context[:jelly] = 'donut'
|
71
|
+
assert_equal(context[:jelly], 'donut')
|
72
|
+
assert_equal(context[:stuff], 'buy')
|
73
|
+
assert_equal(context[:foo], 1)
|
74
|
+
|
75
|
+
context = XfOOrth::Context.new(context, stuff: 'other')
|
76
|
+
assert_equal(context[:foo], 1)
|
77
|
+
assert_equal(context[:jelly], 'donut')
|
78
|
+
assert_equal(context[:stuff], 'other')
|
79
|
+
context[:foo] = 2
|
80
|
+
assert_equal(context[:jelly], 'donut')
|
81
|
+
assert_equal(context[:stuff], 'other')
|
82
|
+
assert_equal(context[:foo], 2)
|
83
|
+
|
84
|
+
context = XfOOrth::Context.new(context, stuff: 'more')
|
85
|
+
assert_equal(context[:foo], 2)
|
86
|
+
assert_equal(context[:jelly], 'donut')
|
87
|
+
assert_equal(context[:stuff], 'more')
|
88
|
+
context[:foo] = 3
|
89
|
+
context[:jelly] = 'Berliner'
|
90
|
+
assert_equal(context[:jelly], 'Berliner')
|
91
|
+
assert_equal(context[:stuff], 'more')
|
92
|
+
assert_equal(context[:foo], 3)
|
93
|
+
|
94
|
+
context = context.previous
|
95
|
+
assert_equal(context[:foo], 2)
|
96
|
+
assert_equal(context[:jelly], 'donut')
|
97
|
+
assert_equal(context[:stuff], 'other')
|
98
|
+
|
99
|
+
context = context.previous
|
100
|
+
assert_equal(context[:foo], 1)
|
101
|
+
assert_equal(context[:jelly], 'donut')
|
102
|
+
assert_equal(context[:stuff], 'buy')
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_getting_context_with_a_specific_tag
|
106
|
+
c1 = XfOOrth::Context.new(nil, ctrl: :procedure)
|
107
|
+
c2 = XfOOrth::Context.new(c1, ctrl: :if)
|
108
|
+
c3 = XfOOrth::Context.new(c2, ctrl: :loop)
|
109
|
+
|
110
|
+
assert_equal(c1, c3.get_context_by_ctrl(:procedure))
|
111
|
+
assert_equal(c2, c3.get_context_by_ctrl(:if))
|
112
|
+
assert_equal(c3, c3.get_context_by_ctrl(:loop))
|
113
|
+
assert_raises(XfOOrth::XfOOrthError) { c3.get_context_by_ctrl(:wrong) }
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_the_local_mapping_of_symbols
|
117
|
+
context = XfOOrth::Context.new(nil)
|
118
|
+
|
119
|
+
name = 'b'
|
120
|
+
sym = XfOOrth::SymbolMap.add_entry(name)
|
121
|
+
context[sym] = XfOOrth::VmSpec.new(name, sym, [])
|
122
|
+
spec = context.map_with_defaults(name)
|
123
|
+
assert(spec.is_a?(XfOOrth::VmSpec))
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_the_class_mapping_of_symbols
|
127
|
+
mk = MockClass.new
|
128
|
+
context = XfOOrth::Context.new(nil, cls: mk)
|
129
|
+
|
130
|
+
name = '.c'
|
131
|
+
sym = XfOOrth::SymbolMap.add_entry(name)
|
132
|
+
mk[sym] = XfOOrth::TosSpec.new(name, sym, [])
|
133
|
+
spec = context.map_with_defaults(name)
|
134
|
+
assert(spec.is_a?(XfOOrth::TosSpec))
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_the_exclusive_mapping_of_symbols
|
138
|
+
mk = MockObject.new
|
139
|
+
context = XfOOrth::Context.new(nil, obj: mk)
|
140
|
+
|
141
|
+
name = '.d'
|
142
|
+
sym = XfOOrth::SymbolMap.add_entry(name)
|
143
|
+
mk[sym] = XfOOrth::TosSpec.new(name, sym, [])
|
144
|
+
spec = context.map_with_defaults(name)
|
145
|
+
assert(spec.is_a?(XfOOrth::TosSpec))
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_that_it_verifies_sets
|
149
|
+
context = XfOOrth::Context.new(nil, mode: :Execute, ctrl: :colon)
|
150
|
+
|
151
|
+
assert(context.check_set(:mode, [:Execute, :Compile]))
|
152
|
+
|
153
|
+
assert_raises(XfOOrth::XfOOrthError) do
|
154
|
+
context.check_set(:mode, [:Compile, :Deferred])
|
155
|
+
end
|
156
|
+
|
157
|
+
assert(context.check_set(:stuff, [nil]))
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_the_locating_of_the_receiver
|
161
|
+
context = XfOOrth::Context.new(nil, vm: 'vm_sample')
|
162
|
+
assert_equal('vm_sample', context.target)
|
163
|
+
|
164
|
+
context = XfOOrth::Context.new(context, cls: 'cls_sample')
|
165
|
+
assert_equal('cls_sample', context.target)
|
166
|
+
|
167
|
+
context = XfOOrth::Context.new(context, obj: 'obj_sample')
|
168
|
+
assert_equal('obj_sample', context.target)
|
169
|
+
|
170
|
+
context = XfOOrth::Context.new(nil)
|
171
|
+
assert_raises(XfOOrth::XfOOrthError) { context.target }
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_adding_and_removing_local_methods
|
175
|
+
context = XfOOrth::Context.new(nil, vm: 'vm_sample')
|
176
|
+
name = 'lm'
|
177
|
+
sym = XfOOrth::SymbolMap.add_entry(name)
|
178
|
+
spec = context.create_local_method(name, XfOOrth::LocalSpec, [])
|
179
|
+
|
180
|
+
assert_equal(spec, context[sym])
|
181
|
+
|
182
|
+
context.remove_local_method(name)
|
183
|
+
|
184
|
+
assert_nil(context[sym])
|
185
|
+
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|