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,38 @@
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 ObjectLibraryTester < Minitest::Test
11
+
12
+ include XfOOrthTestExtensions
13
+
14
+ #Track mini-test progress.
15
+ include MinitestVisible
16
+
17
+ def test_that_the_object_class_is_available
18
+ foorth_equal("Object", [Object])
19
+ end
20
+
21
+ def test_getting_a_things_name
22
+ foorth_equal("Object .name", ['Object'])
23
+ foorth_equal("Class .name", ['Class'])
24
+
25
+ foorth_equal("Object .new .name", ['Object instance'])
26
+ foorth_equal("45 .name", ['Fixnum instance'])
27
+ foorth_equal('"Foobar" .name', ['String instance'])
28
+ end
29
+
30
+ def test_getting_an_object_as_a_string
31
+ foorth_equal("4 .to_s", ['4'])
32
+ foorth_equal("Object .to_s", ['Object'])
33
+ foorth_equal("VirtualMachine .to_s", ['VirtualMachine'])
34
+
35
+ foorth_equal("4 .strlen", [1])
36
+ end
37
+
38
+ end
@@ -0,0 +1,40 @@
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 ProcedureLibraryTester < Minitest::Test
11
+
12
+ include XfOOrthTestExtensions
13
+
14
+ #Track mini-test progress.
15
+ include MinitestVisible
16
+
17
+ def test_lambda_basics
18
+ foorth_equal("{{ }} .name ", ["Procedure instance"])
19
+ end
20
+
21
+ def test_calling_lambdas
22
+ foorth_equal("1 {{ 99 + }} .call ", [100])
23
+ end
24
+
25
+ def test_creating_a_thread
26
+ foorth_run('0 var$: $tcat2')
27
+ foorth_equal('{{ 1 $tcat2 ! }} .start drop 0.01 .sleep $tcat2 @', [1])
28
+ end
29
+
30
+ def test_calling_with
31
+ foorth_equal('4 {{ self dup + }} .call_with', [8])
32
+ end
33
+
34
+ def test_calling_x_v_and_vx
35
+ foorth_equal('4 {{ v dup + }} .call_v', [8])
36
+ foorth_equal('4 {{ x dup + }} .call_x', [8])
37
+
38
+ foorth_equal('5 4 {{ v x 2dup + }} .call_vx', [5, 4, 9])
39
+ end
40
+ end
@@ -0,0 +1,66 @@
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 QueueLibraryTester < Minitest::Test
11
+
12
+ include XfOOrthTestExtensions
13
+
14
+ #Track mini-test progress.
15
+ include MinitestVisible
16
+
17
+ def test_the_queue_class_exists
18
+ foorth_equal('Queue', [Queue])
19
+ foorth_equal('Queue .new .class', [Queue])
20
+ end
21
+
22
+ def test_some_queue_operations
23
+ foorth_run('Queue .new val$: $q')
24
+ foorth_equal('$q .empty?', [true])
25
+ foorth_equal('$q .length', [0])
26
+
27
+ foorth_equal('5 $q .push', [])
28
+ foorth_equal('$q .empty?', [false])
29
+ foorth_equal('$q .length', [1])
30
+
31
+ foorth_equal('6 $q .push', [])
32
+ foorth_equal('$q .empty?', [false])
33
+ foorth_equal('$q .length', [2])
34
+
35
+ foorth_equal('$q .pop' , [5])
36
+ foorth_equal('$q .empty?', [false])
37
+ foorth_equal('$q .length', [1])
38
+
39
+ foorth_equal('$q .pop' , [6])
40
+ foorth_equal('$q .empty?', [true])
41
+ foorth_equal('$q .length', [0])
42
+
43
+ foorth_equal('5 $q .push', [])
44
+ foorth_equal('$q .empty?', [false])
45
+ foorth_equal('$q .length', [1])
46
+ foorth_equal('$q .clear', [])
47
+ foorth_equal('$q .empty?', [true])
48
+ foorth_equal('$q .length', [0])
49
+
50
+ foorth_equal('"A" $q .push $q .pend', ["A"])
51
+ end
52
+
53
+ def test_queues_between_threads
54
+ foorth_run('Queue .new val$: $q')
55
+ foorth_run('"Hello" $q .push')
56
+ foorth_run('{{ $q .pend . }} val$: $b')
57
+ foorth_output('$b .start 0.01 .sleep', "Hello")
58
+
59
+ end
60
+
61
+ def test_that_it_catches_underflows
62
+ foorth_run('Queue .new val$: $q')
63
+ foorth_raises('$q .pop')
64
+ end
65
+
66
+ end
@@ -0,0 +1,70 @@
1
+ # coding: utf-8
2
+
3
+ require_relative 'support/foorth_testing'
4
+ gem 'minitest'
5
+ require 'minitest/autorun'
6
+ require 'minitest_visible'
7
+
8
+ #Test the standard fOOrth library.
9
+ class StackLibraryTester < Minitest::Test
10
+
11
+ include XfOOrthTestExtensions
12
+
13
+ #Track mini-test progress.
14
+ include MinitestVisible
15
+
16
+ def test_the_stack_class_exists
17
+ foorth_equal('Stack', [XfOOrth::XfOOrth_Stack])
18
+ foorth_equal('Stack .name', ['Stack'])
19
+ foorth_equal('Stack .new .class', [XfOOrth::XfOOrth_Stack])
20
+ foorth_equal('Stack .new .name', ['Stack instance'])
21
+ end
22
+
23
+ def test_some_stack_operations
24
+ foorth_run('Stack .new val$: $s')
25
+ foorth_equal('$s .empty?', [true])
26
+ foorth_equal('$s .length', [0])
27
+
28
+ foorth_equal('5 $s .push', [])
29
+ foorth_equal('$s .peek', [5])
30
+ foorth_equal('$s .empty?', [false])
31
+ foorth_equal('$s .length', [1])
32
+
33
+ foorth_equal('6 $s .push', [])
34
+ foorth_equal('$s .peek', [6])
35
+ foorth_equal('$s .empty?', [false])
36
+ foorth_equal('$s .length', [2])
37
+
38
+ foorth_equal('$s .pop', [6])
39
+ foorth_equal('$s .peek', [5])
40
+ foorth_equal('$s .empty?', [false])
41
+ foorth_equal('$s .length', [1])
42
+
43
+ foorth_equal('$s .pop', [5])
44
+ foorth_equal('$s .empty?', [true])
45
+ foorth_equal('$s .length', [0])
46
+
47
+ end
48
+
49
+ def test_that_it_catches_underflows
50
+ foorth_run('Stack .new val$: $s')
51
+
52
+ foorth_raises('$s .pop')
53
+ foorth_raises('$s .peek')
54
+
55
+ end
56
+
57
+ def test_stack_clear
58
+ foorth_run('Stack .new val$: $s')
59
+
60
+ foorth_run('42 $s .push')
61
+ foorth_equal('$s .empty?', [false])
62
+ foorth_equal('$s .peek', [42])
63
+
64
+ foorth_run('$s .clear')
65
+
66
+ foorth_equal('$s .empty?', [true])
67
+ foorth_raises('$s .peek')
68
+ end
69
+
70
+ end
@@ -0,0 +1,208 @@
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 StandardLibraryTester < Minitest::Test
11
+
12
+ include XfOOrthTestExtensions
13
+
14
+ #Track mini-test progress.
15
+ include MinitestVisible
16
+
17
+ def test_basic_constants
18
+ refute(Thread.current[:vm].nil?)
19
+
20
+ foorth_equal("self", [XfOOrth::VirtualMachine.vm])
21
+ foorth_equal("true", [true])
22
+ foorth_equal("false", [false])
23
+ foorth_equal("nil", [nil])
24
+
25
+ foorth_equal("true .class .to_s", ['True'])
26
+ foorth_equal("false .class .to_s", ['False'])
27
+ foorth_equal("nil .class .to_s", ['Nil'])
28
+
29
+ foorth_equal("epsilon", [Float::EPSILON])
30
+ foorth_equal("infinity", [Float::INFINITY]) #and beyond...
31
+ foorth_equal("-infinity", [-Float::INFINITY])
32
+ foorth_equal("max_float", [Float::MAX])
33
+ foorth_equal("min_float", [Float::MIN])
34
+ foorth_equal("nan", [Float::NAN])
35
+ end
36
+
37
+ def test_stack_manipulation
38
+ foorth_equal("1 2", [1, 2])
39
+
40
+ foorth_equal("1 2 drop", [1])
41
+ foorth_raises("drop")
42
+
43
+ foorth_equal("33 dup", [33,33])
44
+ foorth_raises("dup")
45
+
46
+ foorth_equal("false ?dup", [false])
47
+ foorth_equal("nil ?dup", [nil])
48
+ foorth_equal('"" ?dup', ["", ""])
49
+ foorth_equal("true ?dup", [true, true])
50
+ foorth_equal('"A" ?dup', ["A", "A"])
51
+ foorth_equal("1 ?dup", [1,1])
52
+ foorth_raises("?dup")
53
+
54
+ foorth_equal("1 2 swap", [2,1])
55
+ foorth_raises("1 swap")
56
+ foorth_raises("swap")
57
+
58
+ foorth_equal("1 2 3 rot", [2,3,1])
59
+
60
+ foorth_equal("1 2 over", [1,2,1])
61
+
62
+ foorth_equal("1 2 3 1 pick", [1,2,3,3])
63
+ foorth_equal("1 2 3 2 pick", [1,2,3,2])
64
+ foorth_equal("1 2 3 3 pick", [1,2,3,1])
65
+ foorth_raises("1 2 3 4 pick")
66
+ foorth_raises("1 2 3 -4 pick")
67
+ foorth_raises('1 2 3 "apple" pick')
68
+
69
+ foorth_equal("1 2 nip", [2])
70
+ foorth_raises("1 nip")
71
+
72
+ foorth_equal("1 2 tuck", [2,1,2])
73
+ foorth_raises("1 tuck")
74
+ foorth_raises("tuck")
75
+ end
76
+
77
+ def test_the_double_stack_ops
78
+ foorth_equal('1 2 2drop', [])
79
+ foorth_equal('1 2 2dup', [1,2,1,2])
80
+
81
+ foorth_raises('1 2drop')
82
+ foorth_raises('1 2dup')
83
+ end
84
+
85
+ def test_for_the_bored_identity
86
+ foorth_equal("33 33 identical?", [true])
87
+ foorth_equal("33 33 distinct?", [false])
88
+
89
+ foorth_equal('"33" "33" identical?', [false])
90
+ foorth_equal('"33" "33" distinct?', [true])
91
+
92
+ foorth_equal('"33" dup identical?', [true])
93
+ foorth_equal('"33" dup distinct?', [false])
94
+
95
+ end
96
+
97
+ def test_dyadic_error_recovery
98
+ #Insufficient parameters.
99
+ foorth_equal('try 5 + catch end', [])
100
+
101
+ #Stub action.
102
+ foorth_equal('try false 5 + catch end', [])
103
+
104
+ #Bad parameters.
105
+ foorth_equal('try 5 false > catch end', [])
106
+ foorth_equal('try 5 false < catch end', [])
107
+ foorth_equal('try 5 false >= catch end', [])
108
+ foorth_equal('try 5 false <= catch end', [])
109
+ foorth_equal('try 5 false <=> catch end', [])
110
+ foorth_equal('try 5 false + catch end', [])
111
+ foorth_equal('try 5 false - catch end', [])
112
+ foorth_equal('try 5 false * catch end', [])
113
+ foorth_equal('try 5 false ** catch end', [])
114
+ foorth_equal('try 5 false / catch end', [])
115
+ foorth_equal('try 5 false mod catch end', [])
116
+
117
+ foorth_equal('try now false > catch end', [])
118
+ foorth_equal('try now false < catch end', [])
119
+ foorth_equal('try now false >= catch end', [])
120
+ foorth_equal('try now false <= catch end', [])
121
+ foorth_equal('try now false <=> catch end', [])
122
+ foorth_equal('try now false + catch end', [])
123
+ foorth_equal('try now false - catch end', [])
124
+ foorth_equal('try now false format catch end', [])
125
+
126
+ foorth_equal('try 10 .to_duration false > catch end', [])
127
+ foorth_equal('try 10 .to_duration false < catch end', [])
128
+ foorth_equal('try 10 .to_duration false >= catch end', [])
129
+ foorth_equal('try 10 .to_duration false <= catch end', [])
130
+ foorth_equal('try 10 .to_duration false <=> catch end', [])
131
+ foorth_equal('try 10 .to_duration false + catch end', [])
132
+ foorth_equal('try 10 .to_duration false - catch end', [])
133
+ foorth_equal('try 10 .to_duration false * catch end', [])
134
+ foorth_equal('try 10 .to_duration false / catch end', [])
135
+ foorth_equal('try 10 .to_duration f"%Z" catch end', [])
136
+
137
+ foorth_equal('try 11 false and catch end', [])
138
+ foorth_equal('try 11 false or catch end', [])
139
+ foorth_equal('try 11 false xor catch end', [])
140
+ foorth_equal('try 11 false << catch end', [])
141
+ foorth_equal('try 11 false >> catch end', [])
142
+
143
+ foorth_equal('try 11 false max catch end', [])
144
+ foorth_equal('try 11 false min catch end', [])
145
+
146
+
147
+ foorth_equal('try 11 false format catch end', [])
148
+ foorth_equal('try "a" false * catch end', [])
149
+
150
+ end
151
+
152
+ def test_some_logical_and
153
+ foorth_equal("false false &&", [false])
154
+ foorth_equal("false true &&", [false])
155
+ foorth_equal("true false &&", [false])
156
+ foorth_equal("true true &&", [true ])
157
+
158
+ foorth_equal("nil false &&", [false])
159
+ foorth_equal("nil true &&", [false])
160
+ foorth_equal("true nil &&", [false])
161
+ foorth_equal("42 true &&", [true ])
162
+ end
163
+
164
+ def test_some_logical_or
165
+ foorth_equal("false false ||", [false])
166
+ foorth_equal("false true ||", [true ])
167
+ foorth_equal("true false ||", [true ])
168
+ foorth_equal("true true ||", [true ])
169
+
170
+ foorth_equal("nil false ||", [false])
171
+ foorth_equal("nil true ||", [true ])
172
+ foorth_equal("true nil ||", [true ])
173
+ foorth_equal("42 true ||", [true ])
174
+ end
175
+
176
+ def test_some_logical_xor
177
+ foorth_equal("false false ^^", [false])
178
+ foorth_equal("false true ^^", [true ])
179
+ foorth_equal("true false ^^", [true ])
180
+ foorth_equal("true true ^^", [false])
181
+
182
+ foorth_equal("nil false ^^", [false])
183
+ foorth_equal("nil true ^^", [true ])
184
+ foorth_equal("true nil ^^", [true ])
185
+ foorth_equal("42 true ^^", [false])
186
+ end
187
+
188
+ def test_some_logical_not
189
+ foorth_equal("false not", [true ])
190
+ foorth_equal("true not", [false])
191
+ end
192
+
193
+ def test_is_nil
194
+ foorth_equal("false nil=", [false])
195
+ foorth_equal("true nil=", [false])
196
+ foorth_equal("42 nil=", [false])
197
+ foorth_equal("nil nil=", [true])
198
+ end
199
+
200
+ def test_is_not_nil
201
+ foorth_equal("false nil<>", [true])
202
+ foorth_equal("true nil<>", [true])
203
+ foorth_equal("42 nil<>", [true])
204
+ foorth_equal("nil nil<>", [false])
205
+ end
206
+
207
+
208
+ end
@@ -0,0 +1,52 @@
1
+ # coding: utf-8
2
+
3
+ require_relative './support/foorth_testing'
4
+ gem 'minitest'
5
+ require 'minitest/autorun'
6
+ require 'minitest_visible'
7
+
8
+ #Test the standard fOOrth library.
9
+ class StdioLibraryTester < Minitest::Test
10
+
11
+ include XfOOrthTestExtensions
12
+
13
+ #Track mini-test progress.
14
+ include MinitestVisible
15
+
16
+ def test_the_dot
17
+ foorth_output('4 .', "4")
18
+ foorth_output('-4 .', "-4")
19
+ foorth_output('"test" .', "test")
20
+ foorth_output('Object .name .', "Object")
21
+ end
22
+
23
+ def test_the_dot_quote
24
+ foorth_output('."test"', "test")
25
+ end
26
+
27
+ def test_the_dot_cr
28
+ foorth_output('cr', "\n")
29
+ end
30
+
31
+ def test_the_space
32
+ foorth_output('space', " ")
33
+ end
34
+
35
+ def test_the_spaces
36
+ foorth_output('1 spaces', " ")
37
+ foorth_output('2 spaces', " ")
38
+ foorth_output('0 spaces', "")
39
+ foorth_raises('"apple" spaces')
40
+ end
41
+
42
+ def test_the_emit
43
+ foorth_output(' 65 .emit', "A")
44
+ foorth_output('126 .emit', "~")
45
+
46
+ foorth_utf8_output('255 .emit', [195, 191])
47
+
48
+ foorth_output(' "A123" .emit', "A")
49
+ foorth_raises('1+1i .emit')
50
+ end
51
+
52
+ end