fOOrth 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.rdoc_options +17 -0
  4. data/Gemfile +4 -0
  5. data/README.md +67 -0
  6. data/bin/fOOrth +8 -0
  7. data/demo.rb +24 -0
  8. data/fOOrth.gemspec +40 -0
  9. data/fOOrth.reek +109 -0
  10. data/integration/README.md +12 -0
  11. data/integration/_FILE_test.foorth +5 -0
  12. data/integration/array_lib_tests.rb +360 -0
  13. data/integration/class_lib_tests.rb +116 -0
  14. data/integration/clone_lib_tests.rb +108 -0
  15. data/integration/comparison_tests.rb +132 -0
  16. data/integration/compile_lib_tests.rb +190 -0
  17. data/integration/ctrl_struct_lib_tests.rb +80 -0
  18. data/integration/data_ref_lib_tests.rb +43 -0
  19. data/integration/exception_lib_tests.rb +86 -0
  20. data/integration/fiber_bundle_tests.rb +380 -0
  21. data/integration/hash_lib_tests.rb +120 -0
  22. data/integration/in_stream_test_1.txt +4 -0
  23. data/integration/load_test_one.foorth +6 -0
  24. data/integration/load_test_two.foorth +4 -0
  25. data/integration/numeric_lib_tests.rb +321 -0
  26. data/integration/object_lib_tests.rb +38 -0
  27. data/integration/procedure_lib_tests.rb +40 -0
  28. data/integration/queue_lib_tests.rb +66 -0
  29. data/integration/stack_lib_tests.rb +70 -0
  30. data/integration/standard_lib_tests.rb +208 -0
  31. data/integration/stdio_lib_tests.rb +52 -0
  32. data/integration/stream_lib_tests.rb +196 -0
  33. data/integration/string_lib_tests.rb +217 -0
  34. data/integration/support/foorth_testing.rb +135 -0
  35. data/integration/thread_lib_tests.rb +83 -0
  36. data/integration/time_lib_tests.rb +791 -0
  37. data/integration/vm_lib_tests.rb +38 -0
  38. data/lib/fOOrth.rb +57 -0
  39. data/lib/fOOrth/compiler.rb +78 -0
  40. data/lib/fOOrth/compiler/context.rb +49 -0
  41. data/lib/fOOrth/compiler/context/locals.rb +34 -0
  42. data/lib/fOOrth/compiler/context/map_name.rb +92 -0
  43. data/lib/fOOrth/compiler/context/tags.rb +48 -0
  44. data/lib/fOOrth/compiler/modes.rb +32 -0
  45. data/lib/fOOrth/compiler/modes/compiled.rb +41 -0
  46. data/lib/fOOrth/compiler/modes/deferred.rb +57 -0
  47. data/lib/fOOrth/compiler/modes/delayed.rb +40 -0
  48. data/lib/fOOrth/compiler/modes/nested.rb +34 -0
  49. data/lib/fOOrth/compiler/modes/suspend.rb +32 -0
  50. data/lib/fOOrth/compiler/parser.rb +26 -0
  51. data/lib/fOOrth/compiler/parser/get_string.rb +71 -0
  52. data/lib/fOOrth/compiler/parser/normal.rb +53 -0
  53. data/lib/fOOrth/compiler/parser/skip.rb +50 -0
  54. data/lib/fOOrth/compiler/parser/special.rb +42 -0
  55. data/lib/fOOrth/compiler/process.rb +47 -0
  56. data/lib/fOOrth/compiler/process/generate.rb +24 -0
  57. data/lib/fOOrth/compiler/process/get_token.rb +23 -0
  58. data/lib/fOOrth/compiler/process/procedure.rb +55 -0
  59. data/lib/fOOrth/compiler/process/string.rb +20 -0
  60. data/lib/fOOrth/compiler/source.rb +51 -0
  61. data/lib/fOOrth/compiler/source/console.rb +70 -0
  62. data/lib/fOOrth/compiler/source/file_source.rb +37 -0
  63. data/lib/fOOrth/compiler/source/read_point.rb +46 -0
  64. data/lib/fOOrth/compiler/source/string_source.rb +28 -0
  65. data/lib/fOOrth/compiler/token.rb +37 -0
  66. data/lib/fOOrth/compiler/word_specs.rb +178 -0
  67. data/lib/fOOrth/core.rb +27 -0
  68. data/lib/fOOrth/core/class.rb +116 -0
  69. data/lib/fOOrth/core/object.rb +78 -0
  70. data/lib/fOOrth/core/virtual_machine.rb +28 -0
  71. data/lib/fOOrth/debug.rb +13 -0
  72. data/lib/fOOrth/debug/context_dump.rb +31 -0
  73. data/lib/fOOrth/debug/dbg_puts.rb +17 -0
  74. data/lib/fOOrth/debug/display_abort.rb +37 -0
  75. data/lib/fOOrth/debug/vm_dump.rb +27 -0
  76. data/lib/fOOrth/initialize.rb +83 -0
  77. data/lib/fOOrth/interpreter.rb +24 -0
  78. data/lib/fOOrth/interpreter/add_to_hash.rb +17 -0
  79. data/lib/fOOrth/interpreter/data_stack.rb +125 -0
  80. data/lib/fOOrth/interpreter/do_loop.rb +55 -0
  81. data/lib/fOOrth/interpreter/squash.rb +25 -0
  82. data/lib/fOOrth/library.rb +38 -0
  83. data/lib/fOOrth/library/array_library.rb +577 -0
  84. data/lib/fOOrth/library/bundle_library.rb +112 -0
  85. data/lib/fOOrth/library/class_library.rb +90 -0
  86. data/lib/fOOrth/library/clone_library.rb +72 -0
  87. data/lib/fOOrth/library/command_library.rb +205 -0
  88. data/lib/fOOrth/library/compile_library.rb +181 -0
  89. data/lib/fOOrth/library/complex_library.rb +81 -0
  90. data/lib/fOOrth/library/ctrl_struct_library.rb +116 -0
  91. data/lib/fOOrth/library/data_ref_library.rb +100 -0
  92. data/lib/fOOrth/library/duration/arithmetic.rb +114 -0
  93. data/lib/fOOrth/library/duration/formatter.rb +152 -0
  94. data/lib/fOOrth/library/duration/intervals.rb +233 -0
  95. data/lib/fOOrth/library/duration/make.rb +75 -0
  96. data/lib/fOOrth/library/duration_library.rb +52 -0
  97. data/lib/fOOrth/library/fiber_library.rb +120 -0
  98. data/lib/fOOrth/library/hash_library.rb +203 -0
  99. data/lib/fOOrth/library/in_stream_library.rb +81 -0
  100. data/lib/fOOrth/library/integer_library.rb +104 -0
  101. data/lib/fOOrth/library/mutex_library.rb +31 -0
  102. data/lib/fOOrth/library/numeric_library.rb +380 -0
  103. data/lib/fOOrth/library/object_library.rb +80 -0
  104. data/lib/fOOrth/library/other_value_types_library.rb +96 -0
  105. data/lib/fOOrth/library/out_stream_library.rb +146 -0
  106. data/lib/fOOrth/library/procedure_library.rb +65 -0
  107. data/lib/fOOrth/library/queue_library.rb +47 -0
  108. data/lib/fOOrth/library/rational_library.rb +90 -0
  109. data/lib/fOOrth/library/stack_library.rb +56 -0
  110. data/lib/fOOrth/library/stdio_library.rb +56 -0
  111. data/lib/fOOrth/library/string_library.rb +285 -0
  112. data/lib/fOOrth/library/stubs.rb +76 -0
  113. data/lib/fOOrth/library/sync_bundle_library.rb +50 -0
  114. data/lib/fOOrth/library/thread_library.rb +73 -0
  115. data/lib/fOOrth/library/time_library.rb +302 -0
  116. data/lib/fOOrth/library/vm_library.rb +105 -0
  117. data/lib/fOOrth/main.rb +125 -0
  118. data/lib/fOOrth/monkey_patch.rb +14 -0
  119. data/lib/fOOrth/monkey_patch/complex.rb +30 -0
  120. data/lib/fOOrth/monkey_patch/exceptions.rb +154 -0
  121. data/lib/fOOrth/monkey_patch/false.rb +11 -0
  122. data/lib/fOOrth/monkey_patch/float.rb +22 -0
  123. data/lib/fOOrth/monkey_patch/integer.rb +22 -0
  124. data/lib/fOOrth/monkey_patch/nil.rb +11 -0
  125. data/lib/fOOrth/monkey_patch/numeric.rb +33 -0
  126. data/lib/fOOrth/monkey_patch/object.rb +43 -0
  127. data/lib/fOOrth/monkey_patch/rational.rb +31 -0
  128. data/lib/fOOrth/monkey_patch/string.rb +51 -0
  129. data/lib/fOOrth/symbol_map.rb +82 -0
  130. data/lib/fOOrth/version.rb +7 -0
  131. data/license.txt +21 -0
  132. data/rakefile.rb +65 -0
  133. data/reek.txt +1 -0
  134. data/sire.rb +132 -0
  135. data/t.txt +3 -0
  136. data/test.foorth +5 -0
  137. data/tests/compiler/context_tests.rb +180 -0
  138. data/tests/compiler/file_source_test_one.txt +1 -0
  139. data/tests/compiler/file_source_test_three.txt +3 -0
  140. data/tests/compiler/file_source_test_two.txt +3 -0
  141. data/tests/compiler/file_source_tests.rb +130 -0
  142. data/tests/compiler/mode_tests.rb +45 -0
  143. data/tests/compiler/parser_tests.rb +116 -0
  144. data/tests/compiler/spec_tests.rb +113 -0
  145. data/tests/compiler/string_source_tests.rb +128 -0
  146. data/tests/core_tests.rb +138 -0
  147. data/tests/interpreter/data_stack_tests.rb +119 -0
  148. data/tests/monkey_patch/coerce_test.rb +131 -0
  149. data/tests/monkey_patch/complex_test.rb +25 -0
  150. data/tests/monkey_patch/numeric_test.rb +62 -0
  151. data/tests/monkey_patch/object_test.rb +49 -0
  152. data/tests/monkey_patch/rational_test.rb +57 -0
  153. data/tests/monkey_patch/string_test.rb +53 -0
  154. data/tests/symbol_map_tests.rb +53 -0
  155. metadata +366 -0
@@ -0,0 +1,80 @@
1
+ # coding: utf-8
2
+
3
+ require_relative '../lib/fOOrth'
4
+ require_relative 'support/foorth_testing'
5
+ gem 'minitest'
6
+ require 'minitest/autorun'
7
+ require 'minitest_visible'
8
+
9
+ #Test the standard fOOrth library.
10
+ class CtrlStructLibraryTester < Minitest::Test
11
+
12
+ include XfOOrthTestExtensions
13
+
14
+ #Track mini-test progress.
15
+ include MinitestVisible
16
+
17
+ def test_if_else_then_constructs
18
+ foorth_equal('1 if "yay" then', ['yay'])
19
+ foorth_equal('false if "yay" then', [])
20
+ foorth_equal('1 if "yay" else "nay" then', ['yay'])
21
+ foorth_equal('nil if "yay" else "nay" then', ['nay'])
22
+
23
+ foorth_raises('false if ."yes" else ."no" else ."NO" then ')
24
+ end
25
+
26
+ def test_switch_constructs
27
+ foorth_equal('switch 5 end', [5])
28
+
29
+ foorth_run(': tsw switch 1 = if "one" break then "other" end ; ')
30
+
31
+ foorth_equal(' 1 tsw', ["one"])
32
+ foorth_equal(' 2 tsw', ["other"])
33
+ end
34
+
35
+ def test_begin_until_contructs
36
+ foorth_equal('1 begin dup 1 + dup 3 >= until', [1,2,3])
37
+ foorth_equal('1 begin dup 1 + dup 3 < while again', [1,2,3])
38
+ foorth_equal('1 begin dup 1 + dup 3 < while repeat', [1,2,3])
39
+ end
40
+
41
+ def test_do_loop_contructs
42
+ foorth_equal('1 4 do i loop', [1,2,3])
43
+ foorth_equal('1 4 do -i loop', [3,2,1])
44
+
45
+ foorth_equal('1 4 do i 1 +loop', [1,2,3])
46
+ foorth_equal('1 4 do -i 1 +loop', [3,2,1])
47
+
48
+ foorth_equal('1 10 do i 3 +loop', [1,4,7])
49
+ foorth_equal('1 10 do -i 3 +loop', [9,6,3])
50
+
51
+ foorth_equal('3 10 do i 3 +loop', [3,6,9])
52
+ foorth_equal('3 10 do -i 3 +loop', [9,6,3])
53
+
54
+ foorth_equal('1 4 do 1 3 do j loop loop', [1,1,2,2,3,3])
55
+ foorth_equal('1 4 do 1 3 do -j loop loop', [3,3,2,2,1,1])
56
+
57
+ foorth_equal('1 4 do 1 3 do i j loop loop', [1,1,2,1,1,2,2,2,1,3,2,3])
58
+
59
+ foorth_equal('1 4 do 1 3 do i j * loop loop', [1,2,2,4,3,6])
60
+
61
+ foorth_raises('0 10 do 0 +loop')
62
+ foorth_raises('0 10 do -1 +loop')
63
+ foorth_raises('0 10 do "apple" +loop')
64
+ end
65
+
66
+ def test_with_constructs
67
+ foorth_equal('4 .with{{ self 2* }}', [8])
68
+
69
+ foorth_run(': twc01 4 .with{{ self 2* }} ;')
70
+ foorth_equal('twc01', [8])
71
+ end
72
+
73
+ def test_for_unsupported_structures
74
+ foorth_raises('4 .new{{ }}')
75
+ foorth_raises('4 .each{{ }}')
76
+ foorth_raises('4 .map{{ }}')
77
+ foorth_raises('4 .select{{ }}')
78
+ end
79
+
80
+ end
@@ -0,0 +1,43 @@
1
+ # coding: utf-8
2
+
3
+ require_relative '../lib/fOOrth'
4
+ require_relative 'support/foorth_testing'
5
+ gem 'minitest'
6
+ require 'minitest/autorun'
7
+ require 'minitest_visible'
8
+
9
+ #Test the standard fOOrth library.
10
+ class DataRefLibraryTester < Minitest::Test
11
+
12
+ include XfOOrthTestExtensions
13
+
14
+ #Track mini-test progress.
15
+ include MinitestVisible
16
+
17
+ def test_basic_thread_variables
18
+ foorth_equal('10 var#: #test1', [])
19
+ foorth_equal('#test1 @', [10])
20
+ foorth_equal('20 #test1 !', [])
21
+ foorth_equal('#test1 @', [20])
22
+
23
+ foorth_equal('10 val#: #test2', [])
24
+ foorth_equal('#test2', [10])
25
+ end
26
+
27
+ def test_thread_vars_some_more
28
+ foorth_run('42 val#: #ttvsm ')
29
+ foorth_output('#ttvsm .', "42")
30
+ foorth_output('{{ #ttvsm . }} .call ', "42")
31
+ foorth_output('{{ #ttvsm . }} .start 0.001 .sleep ', "42")
32
+ end
33
+
34
+ def test_basic_global_variables
35
+ foorth_equal('10 var$: $test1', [])
36
+ foorth_equal('$test1 @', [10])
37
+ foorth_equal('20 $test1 !', [])
38
+ foorth_equal('$test1 @', [20])
39
+
40
+ foorth_equal('10 val$: $test2', [])
41
+ foorth_equal('$test2', [10])
42
+ end
43
+ end
@@ -0,0 +1,86 @@
1
+ # coding: utf-8
2
+
3
+ require_relative '../lib/fOOrth'
4
+ require_relative 'support/foorth_testing'
5
+ gem 'minitest'
6
+ require 'minitest/autorun'
7
+ require 'minitest_visible'
8
+
9
+ #Test the standard fOOrth library.
10
+ class ExceptionLibraryTester < Minitest::Test
11
+
12
+ include XfOOrthTestExtensions
13
+
14
+ #Track mini-test progress.
15
+ include MinitestVisible
16
+
17
+ def test_for_exception_patches
18
+ assert_equal("E15: ZeroDivisionError", ZeroDivisionError.new.foorth_message)
19
+ assert_equal("F123: oops", XfOOrth::XfOOrthError.new("F123: oops").foorth_message)
20
+ assert_equal("A123: oh oh", XfOOrth::XfOOrthError.new("A123: oh oh").foorth_message)
21
+
22
+ assert(ZeroDivisionError.new.foorth_match('E'))
23
+ assert(ZeroDivisionError.new.foorth_match('E1'))
24
+ assert(ZeroDivisionError.new.foorth_match('E15'))
25
+
26
+ refute(ZeroDivisionError.new.foorth_match('F'))
27
+ refute(ZeroDivisionError.new.foorth_match('E2'))
28
+ refute(ZeroDivisionError.new.foorth_match('E12'))
29
+ refute(ZeroDivisionError.new.foorth_match('E1501'))
30
+
31
+ assert_equal("E??:" , Exception.new.foorth_code)
32
+ assert_equal("E:" , StandardError.new.foorth_code)
33
+ assert_equal("E15:" , ZeroDivisionError.new.foorth_code)
34
+ assert_equal("F12,33:", XfOOrth::XfOOrthError.new("F12,33: oops").foorth_code)
35
+ assert_equal("A12,93:", XfOOrth::XfOOrthError.new("A12,93: oh oh").foorth_code)
36
+ assert_equal("E12,E2BIG:", Errno::E2BIG.new.foorth_code)
37
+ assert_equal("E30:", SignalException.new("INT").foorth_code)
38
+ assert_equal("E30,01:", Interrupt.new.foorth_code)
39
+ end
40
+
41
+ def test_for_try_blocks
42
+ foorth_equal('try 5 end', [5])
43
+ end
44
+
45
+ def test_for_try_catch
46
+ foorth_equal('try 5 0 + catch 6 end ', [5])
47
+ foorth_equal('try 5 0 / catch 6 end ', [6])
48
+ foorth_equal('try 5 0 / catch error end ', ["E15: divided by 0"])
49
+ end
50
+
51
+ def test_for_exception_methods
52
+ foorth_equal('try 5 0 / catch ?"E15" if 0 then end ', [0])
53
+ end
54
+
55
+ def test_with_finally
56
+ foorth_equal('try 5 0 + drop catch finally "apple" end', ["apple"])
57
+ foorth_equal('try 5 0 / drop catch finally "apple" end', ["apple"])
58
+ end
59
+
60
+ def test_for_bad_constructs_errors
61
+ foorth_raises('try 5 0 / catch 6 catch ."YA!" end ')
62
+ foorth_raises('try 5 0 / finally 6 finally ."YA!" end ')
63
+ foorth_raises('try 5 0 / catch 6 finally error ."YA!" end ')
64
+ foorth_raises('try 5 0 / catch 6 finally ?"E150" ."YA!" end ')
65
+
66
+ end
67
+
68
+ def test_for_error_error
69
+ foorth_raises('try 5 0 error end')
70
+ end
71
+
72
+ def test_for_error_bouncing
73
+ foorth_run(': test_bounce try .ceil catch ?"E15" if "WTF?" else bounce then end ;')
74
+ foorth_equal('try 1+1i test_bounce catch "Got it!" end', ["Got it!"])
75
+ end
76
+
77
+ def test_raising_an_exception
78
+ foorth_raises(' "F99 Error!!!" .throw')
79
+ foorth_raises(' throw"F99 Error!!!" ')
80
+
81
+ foorth_equal('try "err msg" .throw catch error end', ["err msg"])
82
+ foorth_equal('try throw"err msg" catch error end', ["err msg"])
83
+
84
+ end
85
+
86
+ end
@@ -0,0 +1,380 @@
1
+ # coding: utf-8
2
+
3
+ require_relative '../lib/fOOrth'
4
+ require_relative 'support/foorth_testing'
5
+ gem 'minitest'
6
+ require 'minitest/autorun'
7
+ require 'minitest_visible'
8
+
9
+ #Test the standard fOOrth library.
10
+ class FiberBundleLibraryTester < Minitest::Test
11
+
12
+ include XfOOrthTestExtensions
13
+
14
+ #Track mini-test progress.
15
+ include MinitestVisible
16
+
17
+ def test_that_the_fiber_classes_exist
18
+ foorth_equal('Fiber', [XfOOrth::XfOOrth_Fiber])
19
+ foorth_equal('Bundle', [XfOOrth::XfOOrth_Bundle])
20
+ foorth_equal('SyncBundle', [XfOOrth::XfOOrth_SyncBundle])
21
+ end
22
+
23
+ # Fiber tests!
24
+
25
+ def test_creating_a_fiber
26
+ test_code = <<-EOS
27
+ Fiber .new{{ }} .class .name
28
+ EOS
29
+
30
+ foorth_equal(test_code, ["Fiber"])
31
+ end
32
+
33
+ def test_fiber_processing
34
+ test_code = <<-EOS
35
+ // Create a fibonacci fiber.
36
+ Fiber .new{{ 1 1 11 do i * yield loop .yield }} val$: $fac
37
+
38
+ 0 10 do $fac .step loop $fac .step
39
+ EOS
40
+
41
+ foorth_equal(test_code, [3628800])
42
+ end
43
+
44
+ def test_fiber_processing_data
45
+ test_code = <<-EOS
46
+ // Create a fibonacci fiber.
47
+ Fiber .new{{ 1 1 begin dup .yield over + swap again }} val$: $fib
48
+
49
+ 0 8 do $fib .step loop
50
+ EOS
51
+
52
+ foorth_equal(test_code, [1, 1, 2, 3, 5, 8, 13, 21])
53
+ end
54
+
55
+ def test_fiber_processing_overrun
56
+ test_code = <<-EOS
57
+ // Create a fiber fiber.
58
+ Fiber .new{{ 0 5 do i .yield loop }} val$: $ovr
59
+
60
+ 0 8 do $ovr .step loop
61
+ EOS
62
+
63
+ foorth_raises(test_code)
64
+ end
65
+
66
+ def test_for_fiber_alive_and_status
67
+ foorth_run('Fiber .new{{ yield }} val$: $alive')
68
+
69
+ foorth_equal('$alive .alive?', [true])
70
+ foorth_equal('$alive .status', ["new"])
71
+
72
+ foorth_equal('$alive .step $alive .alive?', [true])
73
+ foorth_equal('$alive .status', ["alive"])
74
+
75
+ foorth_equal('$alive .step $alive .alive?', [false])
76
+ foorth_equal('$alive .status', ["dead"])
77
+
78
+ foorth_raises('$alive .step')
79
+ end
80
+
81
+ def test_for_bad_yield
82
+ foorth_raises('5 .yield')
83
+ end
84
+
85
+ def test_making_a_fiber_from_a_procedure
86
+ test_code = <<-EOS
87
+ // Create a fibonacci fiber.
88
+ {{ 1 1 begin dup .yield over + swap again }} .to_fiber val$: $fib
89
+
90
+ 0 8 do $fib .step loop
91
+ EOS
92
+
93
+ foorth_equal(test_code, [1, 1, 2, 3, 5, 8, 13, 21])
94
+ end
95
+
96
+ def test_making_a_fiber_from_not_a_procedure
97
+ foorth_raises('42 .to_fiber')
98
+ end
99
+
100
+ def test_getting_the_current_fiber
101
+ foorth_run('Fiber .new{{ Fiber .current .yield }} val$: $current')
102
+
103
+ foorth_equal('Fiber .current', [nil])
104
+
105
+ symbol = XfOOrth::SymbolMap.map('$current')
106
+ current = eval "#{'$' + symbol.to_s}"
107
+
108
+ foorth_equal('$current .step', [current])
109
+ end
110
+
111
+ def test_converting_a_fiber_to_a_fiber
112
+ foorth_run('Fiber .new{{ }} val$: $current')
113
+
114
+ symbol = XfOOrth::SymbolMap.map('$current')
115
+ current = eval "#{'$' + symbol.to_s}"
116
+
117
+ foorth_equal('$current .to_fiber', [current])
118
+ end
119
+
120
+ #Bundle tests!
121
+
122
+ def test_making_a_bundle_of_fibers
123
+ test_code = <<-EOS
124
+ // Create a bunch of fibers.
125
+ [ {{ 1 .yield }} {{ 2 .yield }} {{ 3 .yield }} ] .to_bundle val$: $bundle
126
+
127
+ $bundle .run
128
+ EOS
129
+
130
+ foorth_equal(test_code, [1, 2, 3])
131
+ end
132
+
133
+ def test_making_a_bundle_of_one_fiber
134
+ test_code = <<-EOS
135
+ // Create a bunch of one fiber.
136
+ {{ 1 .yield }} .to_bundle val$: $bundle
137
+
138
+ $bundle .run
139
+ EOS
140
+
141
+ foorth_equal(test_code, [1])
142
+ end
143
+
144
+ def test_making_a_bundle_of_nested_fibers
145
+ test_code = <<-EOS
146
+ // Create a bunch of fibers.
147
+ [ {{ 2 .yield }} {{ 4 .yield 5 .yield }} ] .to_bundle val$: $sub
148
+
149
+ [ {{ 1 .yield }} $sub {{ 3 .yield }} ] .to_bundle val$: $bundle
150
+
151
+ $bundle .run
152
+ EOS
153
+
154
+ foorth_equal(test_code, [1, 2, 3, 4, 5])
155
+ end
156
+
157
+ def test_a_bundle_one_step_at_time
158
+ test_code = <<-EOS
159
+ // Create a bunch of fibers.
160
+ [ {{ 2 .yield }} {{ 4 .yield 5 .yield }} ] .to_bundle val$: $sub
161
+
162
+ [ {{ 1 .yield }} $sub {{ 3 .yield }} ] .to_bundle val$: $bundle
163
+ EOS
164
+
165
+ foorth_run(test_code)
166
+ foorth_equal('$bundle .alive?', [true])
167
+ foorth_equal('$bundle .status', ["alive"])
168
+ foorth_equal('$bundle .length', [3])
169
+
170
+ foorth_equal('$bundle .step', [1])
171
+ foorth_equal('$bundle .alive?', [true])
172
+ foorth_equal('$bundle .status', ["alive"])
173
+ foorth_equal('$bundle .length', [3])
174
+
175
+ foorth_equal('$bundle .step', [2])
176
+ foorth_equal('$bundle .alive?', [true])
177
+ foorth_equal('$bundle .status', ["alive"])
178
+ foorth_equal('$bundle .length', [3])
179
+
180
+ foorth_equal('$bundle .step', [3])
181
+ foorth_equal('$bundle .alive?', [true])
182
+ foorth_equal('$bundle .status', ["alive"])
183
+ foorth_equal('$bundle .length', [3])
184
+
185
+ foorth_equal('$bundle .step', [])
186
+ foorth_equal('$bundle .alive?', [true])
187
+ foorth_equal('$bundle .status', ["alive"])
188
+ foorth_equal('$bundle .length', [2])
189
+
190
+ foorth_equal('$bundle .step', [4])
191
+ foorth_equal('$bundle .alive?', [true])
192
+ foorth_equal('$bundle .status', ["alive"])
193
+ foorth_equal('$bundle .length', [2])
194
+
195
+ foorth_equal('$bundle .step', [])
196
+ foorth_equal('$bundle .alive?', [true])
197
+ foorth_equal('$bundle .status', ["alive"])
198
+ foorth_equal('$bundle .length', [1])
199
+
200
+ foorth_equal('$bundle .step', [])
201
+ foorth_equal('$bundle .alive?', [true])
202
+ foorth_equal('$bundle .status', ["alive"])
203
+ foorth_equal('$bundle .length', [1])
204
+
205
+ foorth_equal('$bundle .step', [5])
206
+ foorth_equal('$bundle .alive?', [true])
207
+ foorth_equal('$bundle .status', ["alive"])
208
+ foorth_equal('$bundle .length', [1])
209
+
210
+ foorth_equal('$bundle .step', [])
211
+ foorth_equal('$bundle .alive?', [false])
212
+ foorth_equal('$bundle .status', ["dead"])
213
+ foorth_equal('$bundle .length', [0])
214
+ end
215
+
216
+ def test_converting_a_bundle_to_a_fiber
217
+ foorth_run('[ {{ }} {{ }} ] .to_bundle val$: $test')
218
+
219
+ symbol = XfOOrth::SymbolMap.map('$test')
220
+ test = eval "#{'$' + symbol.to_s}"
221
+
222
+ foorth_equal('$test .to_fiber', [test])
223
+ end
224
+
225
+ def test_converting_a_proc_to_a_bundle
226
+ foorth_run('{{ }} .to_bundle val$: $test')
227
+
228
+ symbol = XfOOrth::SymbolMap.map('$test')
229
+ test = eval "#{'$' + symbol.to_s}"
230
+
231
+ foorth_equal('$test .to_fiber', [test])
232
+ foorth_equal('$test .alive?', [true])
233
+ foorth_equal('$test .length', [1])
234
+ end
235
+
236
+ def test_adding_fibers_to_a_bundle
237
+ foorth_run('Bundle .new val$: $add')
238
+ foorth_equal('{{ }} $add .add $add .length', [1])
239
+ foorth_equal('{{ }} $add .add $add .length', [2])
240
+ foorth_equal('{{ }} $add .add $add .length', [3])
241
+ foorth_equal('{{ }} $add .add $add .length', [4])
242
+
243
+ foorth_raises('42 $add .add $add .length')
244
+ end
245
+
246
+ def test_making_a_bundle_of_not_fibers
247
+ foorth_raises('[ 1 2 3 ] .to_bundle')
248
+ end
249
+
250
+ #Synchronized Bundle tests!
251
+
252
+ def test_making_a_sync_bundle_of_fibers
253
+ test_code = <<-EOS
254
+ // Create a bunch of fibers.
255
+ [ {{ 1 .yield }} {{ 2 .yield }} {{ 3 .yield }} ] .to_sync_bundle val$: $bundle
256
+
257
+ $bundle .run
258
+ EOS
259
+
260
+ foorth_equal(test_code, [1, 2, 3])
261
+ end
262
+
263
+ def test_making_a_sync_bundle_of_one_fiber
264
+ test_code = <<-EOS
265
+ // Create a bunch of one fiber.
266
+ {{ 1 .yield }} .to_sync_bundle val$: $bundle
267
+
268
+ $bundle .run
269
+ EOS
270
+
271
+ foorth_equal(test_code, [1])
272
+ end
273
+
274
+ def test_making_a_sync_bundle_of_nested_fibers
275
+ test_code = <<-EOS
276
+ // Create a bunch of fibers.
277
+ [ {{ 2 .yield }} {{ 4 .yield 5 .yield }} ] .to_bundle val$: $sub
278
+
279
+ [ {{ 1 .yield }} $sub {{ 3 .yield }} ] .to_sync_bundle val$: $bundle
280
+
281
+ $bundle .run
282
+ EOS
283
+
284
+ foorth_equal(test_code, [1, 2, 3, 4, 5])
285
+ end
286
+
287
+ def test_a_sync_bundle_one_step_at_time
288
+ test_code = <<-EOS
289
+ // Create a bunch of fibers.
290
+ [ {{ 2 .yield }} {{ 4 .yield 5 .yield }} ] .to_bundle val$: $sub
291
+
292
+ [ {{ 1 .yield }} $sub {{ 3 .yield }} ] .to_sync_bundle val$: $bundle
293
+ EOS
294
+
295
+ foorth_run(test_code)
296
+ foorth_equal('$bundle .alive?', [true])
297
+ foorth_equal('$bundle .status', ["alive"])
298
+ foorth_equal('$bundle .length', [3])
299
+
300
+ foorth_equal('$bundle .step', [1])
301
+ foorth_equal('$bundle .alive?', [true])
302
+ foorth_equal('$bundle .status', ["alive"])
303
+ foorth_equal('$bundle .length', [3])
304
+
305
+ foorth_equal('$bundle .step', [2])
306
+ foorth_equal('$bundle .alive?', [true])
307
+ foorth_equal('$bundle .status', ["alive"])
308
+ foorth_equal('$bundle .length', [3])
309
+
310
+ foorth_equal('$bundle .step', [3])
311
+ foorth_equal('$bundle .alive?', [true])
312
+ foorth_equal('$bundle .status', ["alive"])
313
+ foorth_equal('$bundle .length', [3])
314
+
315
+ foorth_equal('$bundle .step', [])
316
+ foorth_equal('$bundle .alive?', [true])
317
+ foorth_equal('$bundle .status', ["alive"])
318
+ foorth_equal('$bundle .length', [2])
319
+
320
+ foorth_equal('$bundle .step', [4])
321
+ foorth_equal('$bundle .alive?', [true])
322
+ foorth_equal('$bundle .status', ["alive"])
323
+ foorth_equal('$bundle .length', [2])
324
+
325
+ foorth_equal('$bundle .step', [])
326
+ foorth_equal('$bundle .alive?', [true])
327
+ foorth_equal('$bundle .status', ["alive"])
328
+ foorth_equal('$bundle .length', [1])
329
+
330
+ foorth_equal('$bundle .step', [])
331
+ foorth_equal('$bundle .alive?', [true])
332
+ foorth_equal('$bundle .status', ["alive"])
333
+ foorth_equal('$bundle .length', [1])
334
+
335
+ foorth_equal('$bundle .step', [5])
336
+ foorth_equal('$bundle .alive?', [true])
337
+ foorth_equal('$bundle .status', ["alive"])
338
+ foorth_equal('$bundle .length', [1])
339
+
340
+ foorth_equal('$bundle .step', [])
341
+ foorth_equal('$bundle .alive?', [false])
342
+ foorth_equal('$bundle .status', ["dead"])
343
+ foorth_equal('$bundle .length', [0])
344
+ end
345
+
346
+ def test_converting_a_sync_bundle_to_a_fiber
347
+ foorth_run('[ {{ }} {{ }} ] .to_sync_bundle val$: $test')
348
+
349
+ symbol = XfOOrth::SymbolMap.map('$test')
350
+ test = eval "#{'$' + symbol.to_s}"
351
+
352
+ foorth_equal('$test .to_fiber', [test])
353
+ end
354
+
355
+ def test_converting_a_proc_to_a_sync_bundle
356
+ foorth_run('{{ }} .to_sync_bundle val$: $test')
357
+
358
+ symbol = XfOOrth::SymbolMap.map('$test')
359
+ test = eval "#{'$' + symbol.to_s}"
360
+
361
+ foorth_equal('$test .to_fiber', [test])
362
+ foorth_equal('$test .alive?', [true])
363
+ foorth_equal('$test .length', [1])
364
+ end
365
+
366
+ def test_adding_fibers_to_a_sync_bundle
367
+ foorth_run('SyncBundle .new val$: $add')
368
+ foorth_equal('{{ }} $add .add $add .length', [1])
369
+ foorth_equal('{{ }} $add .add $add .length', [2])
370
+ foorth_equal('{{ }} $add .add $add .length', [3])
371
+ foorth_equal('{{ }} $add .add $add .length', [4])
372
+
373
+ foorth_raises('42 $add .add $add .length')
374
+ end
375
+
376
+ def test_making_a_sync_bundle_of_not_fibers
377
+ foorth_raises('[ 1 2 3 ] .to_sync_bundle')
378
+ end
379
+
380
+ end