fOOrth 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.rdoc_options +17 -0
- data/Gemfile +4 -0
- data/README.md +67 -0
- data/bin/fOOrth +8 -0
- data/demo.rb +24 -0
- data/fOOrth.gemspec +40 -0
- data/fOOrth.reek +109 -0
- data/integration/README.md +12 -0
- data/integration/_FILE_test.foorth +5 -0
- data/integration/array_lib_tests.rb +360 -0
- data/integration/class_lib_tests.rb +116 -0
- data/integration/clone_lib_tests.rb +108 -0
- data/integration/comparison_tests.rb +132 -0
- data/integration/compile_lib_tests.rb +190 -0
- data/integration/ctrl_struct_lib_tests.rb +80 -0
- data/integration/data_ref_lib_tests.rb +43 -0
- data/integration/exception_lib_tests.rb +86 -0
- data/integration/fiber_bundle_tests.rb +380 -0
- data/integration/hash_lib_tests.rb +120 -0
- data/integration/in_stream_test_1.txt +4 -0
- data/integration/load_test_one.foorth +6 -0
- data/integration/load_test_two.foorth +4 -0
- data/integration/numeric_lib_tests.rb +321 -0
- data/integration/object_lib_tests.rb +38 -0
- data/integration/procedure_lib_tests.rb +40 -0
- data/integration/queue_lib_tests.rb +66 -0
- data/integration/stack_lib_tests.rb +70 -0
- data/integration/standard_lib_tests.rb +208 -0
- data/integration/stdio_lib_tests.rb +52 -0
- data/integration/stream_lib_tests.rb +196 -0
- data/integration/string_lib_tests.rb +217 -0
- data/integration/support/foorth_testing.rb +135 -0
- data/integration/thread_lib_tests.rb +83 -0
- data/integration/time_lib_tests.rb +791 -0
- data/integration/vm_lib_tests.rb +38 -0
- data/lib/fOOrth.rb +57 -0
- data/lib/fOOrth/compiler.rb +78 -0
- data/lib/fOOrth/compiler/context.rb +49 -0
- data/lib/fOOrth/compiler/context/locals.rb +34 -0
- data/lib/fOOrth/compiler/context/map_name.rb +92 -0
- data/lib/fOOrth/compiler/context/tags.rb +48 -0
- data/lib/fOOrth/compiler/modes.rb +32 -0
- data/lib/fOOrth/compiler/modes/compiled.rb +41 -0
- data/lib/fOOrth/compiler/modes/deferred.rb +57 -0
- data/lib/fOOrth/compiler/modes/delayed.rb +40 -0
- data/lib/fOOrth/compiler/modes/nested.rb +34 -0
- data/lib/fOOrth/compiler/modes/suspend.rb +32 -0
- data/lib/fOOrth/compiler/parser.rb +26 -0
- data/lib/fOOrth/compiler/parser/get_string.rb +71 -0
- data/lib/fOOrth/compiler/parser/normal.rb +53 -0
- data/lib/fOOrth/compiler/parser/skip.rb +50 -0
- data/lib/fOOrth/compiler/parser/special.rb +42 -0
- data/lib/fOOrth/compiler/process.rb +47 -0
- data/lib/fOOrth/compiler/process/generate.rb +24 -0
- data/lib/fOOrth/compiler/process/get_token.rb +23 -0
- data/lib/fOOrth/compiler/process/procedure.rb +55 -0
- data/lib/fOOrth/compiler/process/string.rb +20 -0
- data/lib/fOOrth/compiler/source.rb +51 -0
- data/lib/fOOrth/compiler/source/console.rb +70 -0
- data/lib/fOOrth/compiler/source/file_source.rb +37 -0
- data/lib/fOOrth/compiler/source/read_point.rb +46 -0
- data/lib/fOOrth/compiler/source/string_source.rb +28 -0
- data/lib/fOOrth/compiler/token.rb +37 -0
- data/lib/fOOrth/compiler/word_specs.rb +178 -0
- data/lib/fOOrth/core.rb +27 -0
- data/lib/fOOrth/core/class.rb +116 -0
- data/lib/fOOrth/core/object.rb +78 -0
- data/lib/fOOrth/core/virtual_machine.rb +28 -0
- data/lib/fOOrth/debug.rb +13 -0
- data/lib/fOOrth/debug/context_dump.rb +31 -0
- data/lib/fOOrth/debug/dbg_puts.rb +17 -0
- data/lib/fOOrth/debug/display_abort.rb +37 -0
- data/lib/fOOrth/debug/vm_dump.rb +27 -0
- data/lib/fOOrth/initialize.rb +83 -0
- data/lib/fOOrth/interpreter.rb +24 -0
- data/lib/fOOrth/interpreter/add_to_hash.rb +17 -0
- data/lib/fOOrth/interpreter/data_stack.rb +125 -0
- data/lib/fOOrth/interpreter/do_loop.rb +55 -0
- data/lib/fOOrth/interpreter/squash.rb +25 -0
- data/lib/fOOrth/library.rb +38 -0
- data/lib/fOOrth/library/array_library.rb +577 -0
- data/lib/fOOrth/library/bundle_library.rb +112 -0
- data/lib/fOOrth/library/class_library.rb +90 -0
- data/lib/fOOrth/library/clone_library.rb +72 -0
- data/lib/fOOrth/library/command_library.rb +205 -0
- data/lib/fOOrth/library/compile_library.rb +181 -0
- data/lib/fOOrth/library/complex_library.rb +81 -0
- data/lib/fOOrth/library/ctrl_struct_library.rb +116 -0
- data/lib/fOOrth/library/data_ref_library.rb +100 -0
- data/lib/fOOrth/library/duration/arithmetic.rb +114 -0
- data/lib/fOOrth/library/duration/formatter.rb +152 -0
- data/lib/fOOrth/library/duration/intervals.rb +233 -0
- data/lib/fOOrth/library/duration/make.rb +75 -0
- data/lib/fOOrth/library/duration_library.rb +52 -0
- data/lib/fOOrth/library/fiber_library.rb +120 -0
- data/lib/fOOrth/library/hash_library.rb +203 -0
- data/lib/fOOrth/library/in_stream_library.rb +81 -0
- data/lib/fOOrth/library/integer_library.rb +104 -0
- data/lib/fOOrth/library/mutex_library.rb +31 -0
- data/lib/fOOrth/library/numeric_library.rb +380 -0
- data/lib/fOOrth/library/object_library.rb +80 -0
- data/lib/fOOrth/library/other_value_types_library.rb +96 -0
- data/lib/fOOrth/library/out_stream_library.rb +146 -0
- data/lib/fOOrth/library/procedure_library.rb +65 -0
- data/lib/fOOrth/library/queue_library.rb +47 -0
- data/lib/fOOrth/library/rational_library.rb +90 -0
- data/lib/fOOrth/library/stack_library.rb +56 -0
- data/lib/fOOrth/library/stdio_library.rb +56 -0
- data/lib/fOOrth/library/string_library.rb +285 -0
- data/lib/fOOrth/library/stubs.rb +76 -0
- data/lib/fOOrth/library/sync_bundle_library.rb +50 -0
- data/lib/fOOrth/library/thread_library.rb +73 -0
- data/lib/fOOrth/library/time_library.rb +302 -0
- data/lib/fOOrth/library/vm_library.rb +105 -0
- data/lib/fOOrth/main.rb +125 -0
- data/lib/fOOrth/monkey_patch.rb +14 -0
- data/lib/fOOrth/monkey_patch/complex.rb +30 -0
- data/lib/fOOrth/monkey_patch/exceptions.rb +154 -0
- data/lib/fOOrth/monkey_patch/false.rb +11 -0
- data/lib/fOOrth/monkey_patch/float.rb +22 -0
- data/lib/fOOrth/monkey_patch/integer.rb +22 -0
- data/lib/fOOrth/monkey_patch/nil.rb +11 -0
- data/lib/fOOrth/monkey_patch/numeric.rb +33 -0
- data/lib/fOOrth/monkey_patch/object.rb +43 -0
- data/lib/fOOrth/monkey_patch/rational.rb +31 -0
- data/lib/fOOrth/monkey_patch/string.rb +51 -0
- data/lib/fOOrth/symbol_map.rb +82 -0
- data/lib/fOOrth/version.rb +7 -0
- data/license.txt +21 -0
- data/rakefile.rb +65 -0
- data/reek.txt +1 -0
- data/sire.rb +132 -0
- data/t.txt +3 -0
- data/test.foorth +5 -0
- data/tests/compiler/context_tests.rb +180 -0
- data/tests/compiler/file_source_test_one.txt +1 -0
- data/tests/compiler/file_source_test_three.txt +3 -0
- data/tests/compiler/file_source_test_two.txt +3 -0
- data/tests/compiler/file_source_tests.rb +130 -0
- data/tests/compiler/mode_tests.rb +45 -0
- data/tests/compiler/parser_tests.rb +116 -0
- data/tests/compiler/spec_tests.rb +113 -0
- data/tests/compiler/string_source_tests.rb +128 -0
- data/tests/core_tests.rb +138 -0
- data/tests/interpreter/data_stack_tests.rb +119 -0
- data/tests/monkey_patch/coerce_test.rb +131 -0
- data/tests/monkey_patch/complex_test.rb +25 -0
- data/tests/monkey_patch/numeric_test.rb +62 -0
- data/tests/monkey_patch/object_test.rb +49 -0
- data/tests/monkey_patch/rational_test.rb +57 -0
- data/tests/monkey_patch/string_test.rb +53 -0
- data/tests/symbol_map_tests.rb +53 -0
- metadata +366 -0
@@ -0,0 +1 @@
|
|
1
|
+
abc
|
@@ -0,0 +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
|
+
assert_equal(source.get, nil)
|
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_equal(source.get, nil)
|
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_equal(source.get, nil)
|
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_equal(source.get, nil)
|
126
|
+
assert(source.eoln?)
|
127
|
+
assert(source.eof?)
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
@@ -0,0 +1,45 @@
|
|
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 CompilerModeTester < Minitest::Test
|
10
|
+
|
11
|
+
#Track mini-test progress.
|
12
|
+
include MinitestVisible
|
13
|
+
|
14
|
+
def test_mode_nesting
|
15
|
+
#Get the virtual machine.
|
16
|
+
vm = Thread.current[:vm]
|
17
|
+
vm.interpreter_reset
|
18
|
+
vm.compiler_reset
|
19
|
+
|
20
|
+
#Test the baseline assumptions.
|
21
|
+
assert_equal(vm.context.depth, 1)
|
22
|
+
|
23
|
+
#Nest in by one level.
|
24
|
+
vm.nest_mode("", "[")
|
25
|
+
assert_equal(vm.context.depth, 2)
|
26
|
+
|
27
|
+
#Back off nesting by one level.
|
28
|
+
vm.unnest_mode("", ["["])
|
29
|
+
assert_equal(vm.context.depth, 1)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_ill_nesting
|
33
|
+
#Get the virtual machine.
|
34
|
+
vm = Thread.current[:vm]
|
35
|
+
vm.interpreter_reset
|
36
|
+
vm.compiler_reset
|
37
|
+
|
38
|
+
#Nest in by one level.
|
39
|
+
vm.nest_mode("", "[")
|
40
|
+
|
41
|
+
#Back off nesting by one level with wrong tag.
|
42
|
+
assert_raises(XfOOrth::XfOOrthError) { vm.unnest_mode("", ["{"]) }
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,116 @@
|
|
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 ParserTester < Minitest::Test
|
11
|
+
|
12
|
+
#Track mini-test progress.
|
13
|
+
include MinitestVisible
|
14
|
+
|
15
|
+
#Test simple parsing into words.
|
16
|
+
def test_parsing_words_raw
|
17
|
+
test_string = '2 3 + .'
|
18
|
+
source = XfOOrth::StringSource.new(test_string)
|
19
|
+
parser = XfOOrth::Parser.new(source)
|
20
|
+
|
21
|
+
assert_equal(parser.get_word_raw, '2')
|
22
|
+
assert_equal(parser.get_word_raw, '3')
|
23
|
+
assert_equal(parser.get_word_raw, '+')
|
24
|
+
assert_equal(parser.get_word_raw, '.')
|
25
|
+
assert_equal(parser.get_word_raw, nil)
|
26
|
+
end
|
27
|
+
|
28
|
+
#Test parsing strings.
|
29
|
+
def test_parsing_strings
|
30
|
+
test_string = '."Testing 1 2 3"'
|
31
|
+
source = XfOOrth::StringSource.new(test_string)
|
32
|
+
parser = XfOOrth::Parser.new(source)
|
33
|
+
|
34
|
+
assert_equal(parser.get_word_raw, '."')
|
35
|
+
assert_equal(parser.get_string, 'Testing 1 2 3')
|
36
|
+
end
|
37
|
+
|
38
|
+
#Test parsing open ended strings.
|
39
|
+
def test_parsing_open_ended_strings
|
40
|
+
test_string = '."Testing 1 2 3' + "\n"
|
41
|
+
source = XfOOrth::StringSource.new(test_string)
|
42
|
+
parser = XfOOrth::Parser.new(source)
|
43
|
+
|
44
|
+
assert_equal(parser.get_word_raw, '."')
|
45
|
+
assert_equal(parser.get_string, 'Testing 1 2 3')
|
46
|
+
end
|
47
|
+
|
48
|
+
#Test parsing strings some more.
|
49
|
+
def test_parsing_strings_breaks
|
50
|
+
test_string = '."Testing 1 ' + "\\" + "\n" + '2 3"'
|
51
|
+
source = XfOOrth::StringSource.new(test_string)
|
52
|
+
parser = XfOOrth::Parser.new(source)
|
53
|
+
|
54
|
+
assert_equal(parser.get_word_raw, '."')
|
55
|
+
assert_equal(parser.get_string, 'Testing 1 2 3')
|
56
|
+
end
|
57
|
+
|
58
|
+
#Test parsing nested comments.
|
59
|
+
def test_parsing_comments
|
60
|
+
test_string = '1 2 (Now we add them!) + .'
|
61
|
+
source = XfOOrth::StringSource.new(test_string)
|
62
|
+
parser = XfOOrth::Parser.new(source)
|
63
|
+
|
64
|
+
assert_equal(parser.get_word_raw, '1')
|
65
|
+
assert_equal(parser.get_word_raw, '2')
|
66
|
+
assert_equal(parser.get_word_raw, '(')
|
67
|
+
parser.skip_over_comment
|
68
|
+
assert_equal(parser.get_word_raw, '+')
|
69
|
+
assert_equal(parser.get_word_raw, '.')
|
70
|
+
assert_equal(parser.get_word_raw, nil)
|
71
|
+
end
|
72
|
+
|
73
|
+
#Test parsing ill-nested comments.
|
74
|
+
def test_parsing_bad_comments
|
75
|
+
test_string = '1 2 (Now we add them! + .'
|
76
|
+
source = XfOOrth::StringSource.new(test_string)
|
77
|
+
parser = XfOOrth::Parser.new(source)
|
78
|
+
|
79
|
+
assert_equal(parser.get_word_raw, '1')
|
80
|
+
assert_equal(parser.get_word_raw, '2')
|
81
|
+
assert_equal(parser.get_word_raw, '(')
|
82
|
+
|
83
|
+
assert_raises(XfOOrth::XfOOrthError) do
|
84
|
+
parser.skip_over_comment
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
#Test parsing C++ style comments.
|
89
|
+
def test_parsing_cpp_comments
|
90
|
+
test_string = '1 2 //Now we add them!' + "\n" + '+ .'
|
91
|
+
source = XfOOrth::StringSource.new(test_string)
|
92
|
+
parser = XfOOrth::Parser.new(source)
|
93
|
+
|
94
|
+
assert_equal(parser.get_word_raw, '1')
|
95
|
+
assert_equal(parser.get_word_raw, '2')
|
96
|
+
assert_equal(parser.get_word_raw, '//')
|
97
|
+
parser.skip_to_eoln
|
98
|
+
assert_equal(parser.get_word_raw, '+')
|
99
|
+
assert_equal(parser.get_word_raw, '.')
|
100
|
+
assert_equal(parser.get_word_raw, nil)
|
101
|
+
end
|
102
|
+
|
103
|
+
#Test parsing of words.
|
104
|
+
def test_parse_word
|
105
|
+
test_string = '1 2 //Now we add them!' + "\n" + '(Now add!) + (Now print!) .'
|
106
|
+
source = XfOOrth::StringSource.new(test_string)
|
107
|
+
parser = XfOOrth::Parser.new(source)
|
108
|
+
|
109
|
+
assert_equal(parser.get_word, '1')
|
110
|
+
assert_equal(parser.get_word, '2')
|
111
|
+
assert_equal(parser.get_word, '+')
|
112
|
+
assert_equal(parser.get_word, '.')
|
113
|
+
assert_equal(parser.get_word, nil)
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
@@ -0,0 +1,113 @@
|
|
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 SpecTester < Minitest::Test
|
11
|
+
|
12
|
+
#Track mini-test progress.
|
13
|
+
include MinitestVisible
|
14
|
+
|
15
|
+
#Test simple parsing into words.
|
16
|
+
def test_that_abstract_is_abstract_dammit
|
17
|
+
assert_raises(NoMethodError) do
|
18
|
+
AbstractWordSpec("fred", :freddy, [])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_vm_spec
|
23
|
+
spec = XfOOrth::VmSpec.new("fred", :freddy, [:foo])
|
24
|
+
|
25
|
+
assert_equal("vm.freddy(vm); ", spec.builds)
|
26
|
+
assert_instance_of(Proc, spec.does)
|
27
|
+
assert(spec.has_tag?(:foo))
|
28
|
+
refute(spec.has_tag?(:bar))
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_tos_spec
|
32
|
+
spec = XfOOrth::TosSpec.new("fred", :freddy, [:foo])
|
33
|
+
|
34
|
+
assert_equal("vm.pop.freddy(vm); ", spec.builds)
|
35
|
+
assert_instance_of(Proc, spec.does)
|
36
|
+
assert(spec.has_tag?(:foo))
|
37
|
+
refute(spec.has_tag?(:bar))
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_nos_spec
|
41
|
+
spec = XfOOrth::NosSpec.new("fred", :freddy, [:foo])
|
42
|
+
|
43
|
+
assert_equal("vm.swap_pop.freddy(vm); ", spec.builds)
|
44
|
+
assert_instance_of(Proc, spec.does)
|
45
|
+
assert(spec.has_tag?(:foo))
|
46
|
+
refute(spec.has_tag?(:bar))
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_self_spec
|
50
|
+
spec = XfOOrth::SelfSpec.new("fred", :freddy, [:foo])
|
51
|
+
|
52
|
+
assert_equal("self.freddy(vm); ", spec.builds)
|
53
|
+
assert_instance_of(Proc, spec.does)
|
54
|
+
assert(spec.has_tag?(:foo))
|
55
|
+
refute(spec.has_tag?(:bar))
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_class_spec
|
59
|
+
spec = XfOOrth::ClassSpec.new(Object, nil, [:class])
|
60
|
+
|
61
|
+
assert_equal("vm.push(Object); ", spec.builds)
|
62
|
+
assert_equal(Object, spec.new_class)
|
63
|
+
assert_instance_of(Proc, spec.does)
|
64
|
+
assert(spec.has_tag?(:class))
|
65
|
+
refute(spec.has_tag?(:bar))
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_instance_var_spec
|
69
|
+
spec = XfOOrth::InstanceVarSpec.new("fred", :freddy, [:foo])
|
70
|
+
|
71
|
+
assert_equal("vm.push(@freddy); ", spec.builds)
|
72
|
+
assert_instance_of(Proc, spec.does)
|
73
|
+
assert(spec.has_tag?(:foo))
|
74
|
+
refute(spec.has_tag?(:bar))
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_thread_var_spec
|
78
|
+
spec = XfOOrth::ThreadVarSpec.new("fred", :freddy, [:foo])
|
79
|
+
|
80
|
+
assert_equal("vm.push(vm.data[:freddy]); ", spec.builds)
|
81
|
+
assert_instance_of(Proc, spec.does)
|
82
|
+
assert(spec.has_tag?(:foo))
|
83
|
+
refute(spec.has_tag?(:bar))
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_global_var_spec
|
87
|
+
spec = XfOOrth::GlobalVarSpec.new("fred", :freddy, [:foo])
|
88
|
+
|
89
|
+
assert_equal("vm.push($freddy); ", spec.builds)
|
90
|
+
assert_instance_of(Proc, spec.does)
|
91
|
+
assert(spec.has_tag?(:foo))
|
92
|
+
refute(spec.has_tag?(:bar))
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_local_spec
|
96
|
+
spec = XfOOrth::LocalSpec.new("fred", :freddy, [:foo])
|
97
|
+
|
98
|
+
assert_equal("vm.context[:freddy].does.call(vm); ", spec.builds)
|
99
|
+
assert_instance_of(Proc, spec.does)
|
100
|
+
assert(spec.has_tag?(:foo))
|
101
|
+
refute(spec.has_tag?(:bar))
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_macro_spec
|
105
|
+
spec = XfOOrth::MacroSpec.new("fred", :freddy, [:foo, "macro contents"])
|
106
|
+
|
107
|
+
assert_equal("macro contents", spec.builds)
|
108
|
+
assert_instance_of(Proc, spec.does)
|
109
|
+
assert(spec.has_tag?(:foo))
|
110
|
+
refute(spec.has_tag?(:bar))
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
@@ -0,0 +1,128 @@
|
|
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 StringSourceTester < 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_string
|
17
|
+
test_string = "abc"
|
18
|
+
source = XfOOrth::StringSource.new(test_string)
|
19
|
+
|
20
|
+
assert_equal(source.get, 'a')
|
21
|
+
refute(source.eoln?)
|
22
|
+
refute(source.eof?)
|
23
|
+
|
24
|
+
assert_equal(source.get, 'b')
|
25
|
+
refute(source.eoln?)
|
26
|
+
refute(source.eof?)
|
27
|
+
|
28
|
+
assert_equal(source.get, 'c')
|
29
|
+
refute(source.eoln?)
|
30
|
+
refute(source.eof?)
|
31
|
+
|
32
|
+
assert_equal(source.get, ' ')
|
33
|
+
assert(source.eoln?)
|
34
|
+
refute(source.eof?)
|
35
|
+
|
36
|
+
assert_equal(source.get, nil)
|
37
|
+
assert(source.eoln?)
|
38
|
+
assert(source.eof?)
|
39
|
+
end
|
40
|
+
|
41
|
+
#Test that we can read from a multi-line string
|
42
|
+
def test_multi_line_string
|
43
|
+
test_string = "a\nb\nc"
|
44
|
+
source = XfOOrth::StringSource.new(test_string)
|
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_equal(source.get, nil)
|
71
|
+
assert(source.eoln?)
|
72
|
+
assert(source.eof?)
|
73
|
+
end
|
74
|
+
|
75
|
+
#Test that we can read from a multi-line string again
|
76
|
+
def test_multi_line_string_again
|
77
|
+
test_string = "a\nb\nc\n"
|
78
|
+
source = XfOOrth::StringSource.new(test_string)
|
79
|
+
|
80
|
+
assert_equal(source.get, 'a')
|
81
|
+
refute(source.eoln?)
|
82
|
+
refute(source.eof?)
|
83
|
+
|
84
|
+
assert_equal(source.get, ' ')
|
85
|
+
assert(source.eoln?)
|
86
|
+
refute(source.eof?)
|
87
|
+
|
88
|
+
assert_equal(source.get, 'b')
|
89
|
+
refute(source.eoln?)
|
90
|
+
refute(source.eof?)
|
91
|
+
|
92
|
+
assert_equal(source.get, ' ')
|
93
|
+
assert(source.eoln?)
|
94
|
+
refute(source.eof?)
|
95
|
+
|
96
|
+
assert_equal(source.get, 'c')
|
97
|
+
refute(source.eoln?)
|
98
|
+
refute(source.eof?)
|
99
|
+
|
100
|
+
assert_equal(source.get, ' ')
|
101
|
+
assert(source.eoln?)
|
102
|
+
refute(source.eof?)
|
103
|
+
|
104
|
+
assert_equal(source.get, nil)
|
105
|
+
assert(source.eoln?)
|
106
|
+
assert(source.eof?)
|
107
|
+
end
|
108
|
+
|
109
|
+
#Test closing part way through the source.
|
110
|
+
def test_closing
|
111
|
+
test_string = "ABCDEFG - Eric the Half a Bee!"
|
112
|
+
source = XfOOrth::StringSource.new(test_string)
|
113
|
+
|
114
|
+
assert_equal(source.get, 'A')
|
115
|
+
refute(source.eoln?)
|
116
|
+
refute(source.eof?)
|
117
|
+
|
118
|
+
source.close
|
119
|
+
|
120
|
+
assert(source.eoln?)
|
121
|
+
assert(source.eof?)
|
122
|
+
|
123
|
+
assert_equal(source.get, nil)
|
124
|
+
assert(source.eoln?)
|
125
|
+
assert(source.eof?)
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|