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,116 @@
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 ClassLibraryTester < Minitest::Test
11
+
12
+ include XfOOrthTestExtensions
13
+
14
+ #Track mini-test progress.
15
+ include MinitestVisible
16
+
17
+ def test_that_the_class_class_is_available
18
+ foorth_equal("Class", [Class])
19
+ end
20
+
21
+ def test_that_we_can_tell_classes_from_non_classes
22
+ foorth_equal("Class .is_class?", [true])
23
+ foorth_equal("Object .is_class?", [true])
24
+ foorth_equal("Object .new .is_class?", [false])
25
+
26
+ foorth_equal("Numeric .is_class?", [true])
27
+ foorth_equal("42 .is_class?", [false])
28
+ end
29
+
30
+ def test_that_we_can_find_the_class_of_a_thing
31
+ foorth_equal("Class .class", [Class])
32
+ foorth_equal("Object .class", [Class])
33
+
34
+ foorth_equal("Object .new .class", [Object])
35
+ foorth_equal("42 .class", [Fixnum])
36
+ foorth_equal('"foobar" .class', [String])
37
+ end
38
+
39
+ def test_that_we_can_find_the_parent_of_a_class
40
+ foorth_equal("Class .parent_class", [Object])
41
+ foorth_equal("Object .parent_class", [nil])
42
+
43
+ foorth_run('class: TTWCFTPC')
44
+ foorth_equal("TTWCFTPC .parent_class", [Object])
45
+ end
46
+
47
+ def test_the_creation_of_a_class
48
+ foorth_equal("class: T1", [])
49
+
50
+ foorth_equal("T1", [XfOOrth::XfOOrth_T1])
51
+ foorth_equal("T1 .parent_class", [Object])
52
+ foorth_equal("T1 .name", ['T1'])
53
+ foorth_equal("T1 .new .name", ['T1 instance'])
54
+ end
55
+
56
+ def test_deferred_class_creation
57
+ foorth_run(" true if class: T1B then ")
58
+ foorth_equal("T1B .name", ["T1B"])
59
+ end
60
+
61
+ def test_deferred_subclass_creation
62
+ foorth_run(" true if Object .subclass: T1C then ")
63
+ foorth_equal("T1C .name", ["T1C"])
64
+ end
65
+
66
+ def test_the_creation_of_a_sub_class
67
+ foorth_equal("class: T2", [])
68
+ foorth_equal("T2 .subclass: T3", [])
69
+
70
+ foorth_equal("T3", [XfOOrth::XfOOrth_T3])
71
+ foorth_equal("T3 .parent_class", [XfOOrth::XfOOrth_T2])
72
+ foorth_equal("T3 .name", ['T3'])
73
+ foorth_equal("T3 .new .name", ['T3 instance'])
74
+ end
75
+
76
+ def test_creating_an_init_method
77
+ foorth_equal("class: T4", [])
78
+ foorth_equal("T4 .: .init 2 4 6 8 ;", [])
79
+
80
+ foorth_equal("T4 .new .name", [2, 4, 6, 8, 'T4 instance'])
81
+ end
82
+
83
+ def test_creating_an_instance_var
84
+ foorth_equal("class: T5", [])
85
+ foorth_equal("T5 .: .init var@: @a ;", [])
86
+ foorth_equal("T5 .: .a@ @a @ ;", [])
87
+
88
+ foorth_equal("10 T5 .new .a@", [10])
89
+ end
90
+
91
+ def test_creating_an_accessor
92
+ foorth_equal("class: T6", [])
93
+ foorth_equal("T6 .: .init var@: @a ;", [])
94
+ foorth_equal("T6 .: .a@ @a @ ;", [])
95
+ foorth_equal("T6 .: .a! @a ! ;", [])
96
+
97
+ foorth_equal("nil T6 .new dup 100 swap .a! .a@", [100])
98
+ end
99
+
100
+ def test_creating_an_instance_val
101
+ foorth_equal("class: T7", [])
102
+ foorth_equal("T7 .: .init val@: @a ;", [])
103
+ foorth_equal("T7 .: .a@ @a ;", [])
104
+
105
+ foorth_equal("10 T7 .new .a@", [10])
106
+ end
107
+
108
+ def test_the_checking_of_classes
109
+ foorth_equal('12 Numeric .check', [12])
110
+ foorth_equal('"12" Numeric .check', [nil])
111
+
112
+ foorth_equal('12 Numeric .check!', [12])
113
+ foorth_raises('"12" Numeric .check!')
114
+ end
115
+
116
+ end
@@ -0,0 +1,108 @@
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 CloneLibraryTester < Minitest::Test
11
+
12
+ include XfOOrthTestExtensions
13
+
14
+ #Track mini-test progress.
15
+ include MinitestVisible
16
+
17
+ def test_some_cloning_around
18
+ foorth_equal("33 clone", [33,33])
19
+ foorth_equal("33 .clone", [33])
20
+
21
+ foorth_equal("33 clone identical?", [true])
22
+ foorth_equal("33 clone distinct?", [false])
23
+
24
+ foorth_equal('"33" clone identical?', [false])
25
+ foorth_equal('"33" clone distinct?', [true])
26
+
27
+ foorth_equal('"33" dup .clone identical?', [false])
28
+ foorth_equal('"33" dup .clone distinct?', [true])
29
+
30
+ foorth_equal('[ "33" ] clone distinct?', [true])
31
+ foorth_equal('[ "33" ] clone @ swap @ distinct?', [true])
32
+
33
+ end
34
+
35
+ def test_some_clone_exclusion
36
+ foorth_run('class: Tscx')
37
+ foorth_run('Tscx .: .init "a" val@: @a "b" val@: @b ;')
38
+ foorth_run('Tscx .: .a @a ;')
39
+ foorth_run('Tscx .: .b @b ;')
40
+ foorth_run('Tscx .: .clone_exclude [ "@b" ] ;')
41
+ foorth_run('Tscx .new val$: $tscx1')
42
+ foorth_run('$tscx1 .clone val$: $tscx2')
43
+
44
+ foorth_equal('$tscx1 .clone_exclude', [["@b"]])
45
+
46
+ foorth_equal('$tscx1 .a', ["a"])
47
+ foorth_equal('$tscx1 .b', ["b"])
48
+ foorth_equal('$tscx2 .a', ["a"])
49
+ foorth_equal('$tscx2 .b', ["b"])
50
+
51
+ foorth_run('$tscx1 .a "1" <<')
52
+ foorth_run('$tscx1 .b "1" <<')
53
+
54
+ foorth_equal('$tscx1 .a', ["a1"])
55
+ foorth_equal('$tscx1 .b', ["b1"])
56
+ foorth_equal('$tscx2 .a', ["a"])
57
+ foorth_equal('$tscx2 .b', ["b1"])
58
+
59
+ end
60
+
61
+ def test_array_clone_exclusion
62
+ foorth_run('[ "a" "b" ] val$: $tacx1')
63
+ foorth_run('$tacx1 .:: .clone_exclude [ 1 ] ;')
64
+ foorth_run('$tacx1 .clone val$: $tacx2')
65
+
66
+ foorth_equal('$tacx1 .clone_exclude', [[1]])
67
+ foorth_equal('$tacx2 .clone_exclude', [[1]])
68
+
69
+ foorth_equal('$tacx1', [["a", "b"]])
70
+ foorth_equal('$tacx2', [["a", "b"]])
71
+
72
+ foorth_run('0 $tacx1 .[]@ "1" <<')
73
+ foorth_run('1 $tacx1 .[]@ "1" <<')
74
+
75
+ foorth_equal('$tacx1', [["a1", "b1"]])
76
+ foorth_equal('$tacx2', [["a", "b1"]])
77
+ end
78
+
79
+ def test_hash_clone_exclusion
80
+ foorth_run('{ 0 "a" -> 1 "b" -> } val$: $thcx1')
81
+ foorth_run('$thcx1 .:: .clone_exclude [ 1 ] ;')
82
+ foorth_run('$thcx1 .clone val$: $thcx2')
83
+
84
+ foorth_equal('$thcx1 .clone_exclude', [[1]])
85
+ foorth_equal('$thcx2 .clone_exclude', [[1]])
86
+
87
+ foorth_equal('$thcx1', [{0=>"a", 1=>"b"}])
88
+ foorth_equal('$thcx2', [{0=>"a", 1=>"b"}])
89
+
90
+ foorth_run('0 $thcx1 .[]@ "1" <<')
91
+ foorth_run('1 $thcx1 .[]@ "1" <<')
92
+
93
+ foorth_equal('$thcx1', [{0=>"a1", 1=>"b1"}])
94
+ foorth_equal('$thcx2', [{0=>"a", 1=>"b1"}])
95
+ end
96
+
97
+ def test_some_copying_too
98
+ foorth_equal("33 copy", [33,33])
99
+ foorth_equal("33 .copy", [33])
100
+
101
+ foorth_equal('"33" copy identical?', [false])
102
+ foorth_equal('"33" copy distinct?', [true])
103
+
104
+ foorth_equal('[ "33" ] copy distinct?', [true])
105
+ foorth_equal('[ "33" ] copy @ swap @ distinct?', [false])
106
+ end
107
+
108
+ end
@@ -0,0 +1,132 @@
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 ComparisonTester < Minitest::Test
11
+
12
+ include XfOOrthTestExtensions
13
+
14
+ #Track mini-test progress.
15
+ include MinitestVisible
16
+
17
+ def test_greater_than
18
+ foorth_raises("Object .new 4 > ")
19
+ end
20
+
21
+ def test_max_and_min
22
+ foorth_equal("4 2 max", [4])
23
+
24
+ foorth_equal("4 2 min", [2])
25
+
26
+ foorth_equal('"4" "2" max', ["4"])
27
+ foorth_equal('"4" "2" min', ["2"])
28
+ end
29
+
30
+ def test_more_holistically
31
+ foorth_equal("[ 2 4 -2 1/2 555 8 -33 17 ] val$: $tmw", [])
32
+
33
+ foorth_equal("infinity $tmw .each{{ v min }} ", [-33])
34
+ foorth_equal("-infinity $tmw .each{{ v max }} ", [555])
35
+ end
36
+
37
+ def test_greater_than
38
+ foorth_equal('4 4 > ', [false])
39
+ foorth_equal('4 5 > ', [false])
40
+ foorth_equal('5 4 > ', [true])
41
+
42
+ foorth_equal('"4" "4" > ', [false])
43
+ foorth_equal('"4" 4 > ', [false])
44
+ foorth_equal('"4" "5" > ', [false])
45
+ foorth_equal('"4" 5 > ', [false])
46
+ foorth_equal('"5" "4" > ', [true])
47
+ foorth_equal('"5" 4 > ', [true])
48
+ end
49
+
50
+ def test_less_than
51
+ foorth_equal('4 4 < ', [false])
52
+ foorth_equal('4 5 < ', [true])
53
+ foorth_equal('5 4 < ', [false])
54
+
55
+ foorth_equal('"4" "4" < ', [false])
56
+ foorth_equal('"4" 4 < ', [false])
57
+ foorth_equal('"4" "5" < ', [true])
58
+ foorth_equal('"4" 5 < ', [true])
59
+ foorth_equal('"5" "4" < ', [false])
60
+ foorth_equal('"5" 4 < ', [false])
61
+ end
62
+
63
+ def test_greater_or_equal
64
+ foorth_equal('4 4 >= ', [true])
65
+ foorth_equal('4 5 >= ', [false])
66
+ foorth_equal('5 4 >= ', [true])
67
+
68
+ foorth_equal('"4" "4" >= ', [true])
69
+ foorth_equal('"4" 4 >= ', [true])
70
+ foorth_equal('"4" "5" >= ', [false])
71
+ foorth_equal('"4" 5 >= ', [false])
72
+ foorth_equal('"5" "4" >= ', [true])
73
+ foorth_equal('"5" 4 >= ', [true])
74
+ end
75
+
76
+ def test_less_or_equal
77
+ foorth_equal('4 4 <= ', [true])
78
+ foorth_equal('4 5 <= ', [true])
79
+ foorth_equal('5 4 <= ', [false])
80
+
81
+ foorth_equal('"4" "4" <= ', [true])
82
+ foorth_equal('"4" 4 <= ', [true])
83
+ foorth_equal('"4" "5" <= ', [true])
84
+ foorth_equal('"4" 5 <= ', [true])
85
+ foorth_equal('"5" "4" <= ', [false])
86
+ foorth_equal('"5" 4 <= ', [false])
87
+ end
88
+
89
+ def test_the_compare_operator
90
+ foorth_equal('4 4 <=>', [0])
91
+ foorth_equal('4 5 <=>', [-1])
92
+ foorth_equal('5 4 <=>', [1])
93
+
94
+ foorth_equal('"4" "4" <=>', [0])
95
+ foorth_equal('"4" 4 <=>', [0])
96
+ foorth_equal('"4" "5" <=>', [-1])
97
+ foorth_equal('"4" 5 <=>', [-1])
98
+ foorth_equal('"5" "4" <=>', [1])
99
+ foorth_equal('"5" 4 <=>', [1])
100
+ end
101
+
102
+ def test_some_comparisons_with_zero
103
+ foorth_equal('-2 0= ', [false])
104
+ foorth_equal('0 0= ', [true])
105
+ foorth_equal('4 0= ', [false])
106
+
107
+ foorth_equal('-4 0<> ', [true])
108
+ foorth_equal('0 0<> ', [false])
109
+ foorth_equal('5 0<> ', [true])
110
+
111
+ foorth_equal('-1 0> ', [false])
112
+ foorth_equal('0 0> ', [false])
113
+ foorth_equal('4 0> ', [true])
114
+
115
+ foorth_equal('4 0< ', [false])
116
+ foorth_equal('-5 0< ', [true])
117
+ foorth_equal('0 0< ', [false])
118
+
119
+ foorth_equal('4 0>= ', [true])
120
+ foorth_equal('-5 0>= ', [false])
121
+ foorth_equal('0 0>= ', [true])
122
+
123
+ foorth_equal('-4 0<= ', [true])
124
+ foorth_equal('0 0<= ', [true])
125
+ foorth_equal('4 0<= ', [false])
126
+
127
+ foorth_equal('0 0<=>', [0])
128
+ foorth_equal('-5 0<=>', [-1])
129
+ foorth_equal('4 0<=>', [1])
130
+ end
131
+
132
+ end
@@ -0,0 +1,190 @@
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 fOOrth compile library.
10
+ class CompileLibraryTester < Minitest::Test
11
+
12
+ include XfOOrthTestExtensions
13
+
14
+ #Track mini-test progress.
15
+ include MinitestVisible
16
+
17
+ def test_creating_simple_words
18
+ foorth_equal(': dbl dup + ; 4 dbl', [8])
19
+ foorth_equal('9 dbl', [18])
20
+ end
21
+
22
+ def test_creating_immediate_words
23
+ foorth_equal('!: five 5 ;', [])
24
+ foorth_equal('five', [5])
25
+
26
+ foorth_equal(': six five 6 ;', [5])
27
+ foorth_equal('six', [6])
28
+ end
29
+
30
+ def test_simple_word_override
31
+ foorth_equal(': foo 3 * ; 4 foo', [12])
32
+ foorth_equal('5 foo', [15])
33
+ foorth_equal(': foo 4 * ; 4 foo', [16])
34
+ foorth_equal('5 foo', [20])
35
+ end
36
+
37
+ def test_creating_methods
38
+ foorth_equal('Numeric .: .dbl self dup + ; 4 .dbl', [8])
39
+ foorth_equal('9 .dbl', [18])
40
+ end
41
+
42
+ def test_methods_override
43
+ foorth_equal('Numeric .: .foo self 3 * ; 4 .foo', [12])
44
+ foorth_equal('5 .foo', [15])
45
+ foorth_equal('Numeric .: .foo self 4 * ; 4 .foo', [16])
46
+ foorth_equal('5 .foo', [20])
47
+ end
48
+
49
+ def test_words_with_local_vars
50
+ foorth_equal(': lvt1 dup var: lv lv @ * ;' , [])
51
+ foorth_equal('10 lvt1 ' , [100])
52
+
53
+ foorth_equal(': lvt2 val: lv lv 10 * ;' , [])
54
+ foorth_equal('10 lvt2 ' , [100])
55
+ end
56
+
57
+ def test_private_methods
58
+ foorth_equal('class: PMTC', [])
59
+ foorth_equal('PMTC .: ~t10 10 * ; ', [])
60
+ foorth_equal('PMTC .: .t11 dup ~t10 + ; ', [])
61
+ foorth_equal('5 PMTC .new .t11 ', [55])
62
+ end
63
+
64
+ def test_some_invalid_names
65
+ foorth_run('class: TSIN')
66
+
67
+ foorth_raises('TSIN .: Bad ."wow" ; ')
68
+ foorth_raises('TSIN .: @ad ."wow" ; ')
69
+ foorth_raises('TSIN .: $ad ."wow" ; ')
70
+ foorth_raises('TSIN .: #ad ."wow" ; ')
71
+
72
+ end
73
+
74
+ def test_spec_mapping
75
+ foorth_run('class: TempClass')
76
+ foorth_run('TempClass .: .hi_aaa 42 ; ')
77
+
78
+ foorth_run('class: TempOther')
79
+ foorth_run('TempOther .: .hi_aaa 69 ; ')
80
+
81
+ foorth_equal('TempClass .new .hi_aaa', [42] )
82
+ foorth_equal('TempOther .new .hi_aaa', [69] )
83
+
84
+ foorth_run('TempClass .: + 42 + ; ')
85
+ foorth_run('TempOther .: + 69 + ; ')
86
+
87
+ foorth_equal('TempClass .new 10 + ', [52] )
88
+ foorth_equal('TempOther .new 10 + ', [79] )
89
+
90
+ foorth_run('TempClass .: add 42 + ; ')
91
+ foorth_run('TempOther .: add 69 + ; ')
92
+
93
+ foorth_equal('TempClass .new 10 add ', [52] )
94
+ foorth_equal('TempOther .new 10 add ', [79] )
95
+
96
+ foorth_run(': booboo 5 ;')
97
+ foorth_raises('TempClass .: booboo 6 ;')
98
+
99
+ foorth_run('TempClass .: bambam 6 ;')
100
+ foorth_raises(': bambam 5 ;')
101
+
102
+ foorth_raises('TempClass .: .seesaw" 6 ;')
103
+
104
+ foorth_equal('String .: .seesaw" self 2 * ; ', [])
105
+ foorth_equal(' .seesaw"ab" ', ['abab'])
106
+
107
+ end
108
+
109
+ def test_methods_with_local_vars
110
+ foorth_equal('Object .: .lvt5 dup var: lv lv @ * ;' , [])
111
+ foorth_equal('10 Object .new .lvt5 ' , [100])
112
+
113
+ foorth_equal('Object .: .lvt6 val: lv lv 10 * ;' , [])
114
+ foorth_equal('10 Object .new .lvt6 ' , [100])
115
+
116
+ end
117
+
118
+ def test_exclusive_methods
119
+ foorth_equal('class: X1 ' , [])
120
+ foorth_equal('X1 .new var$: $a' , [])
121
+ foorth_equal('X1 .new var$: $b' , [])
122
+
123
+ foorth_equal('X1 .: .foobar "foo" ; ' , [])
124
+
125
+ foorth_equal('$a @ .foobar' , ['foo'])
126
+ foorth_equal('$b @ .foobar' , ['foo'])
127
+
128
+ foorth_equal('$b @ .:: .foobar "bar" ;' , [])
129
+
130
+ foorth_equal('$a @ .foobar' , ['foo'])
131
+ foorth_equal('$b @ .foobar' , ['bar'])
132
+ end
133
+
134
+ def test_the_super_method
135
+ foorth_equal('class: X2 ' , [])
136
+ foorth_equal('X2 .new var$: $c' , [])
137
+ foorth_equal('X2 .: .foo 1 ; ' , [])
138
+ foorth_equal('$c @ .foo' , [1])
139
+
140
+ foorth_equal('X2 .subclass: X3 ' , [])
141
+ foorth_equal('X3 .new var$: $d' , [])
142
+ foorth_equal('X3 .: .foo if super else 2 then ; ' , [])
143
+
144
+ foorth_equal('true $d @ .foo' , [1])
145
+ foorth_equal('false $d @ .foo' , [2])
146
+
147
+ foorth_equal('$c @ .foo' , [1])
148
+ end
149
+
150
+ def test_for_unbalanced_code
151
+ foorth_raises('true if ')
152
+ foorth_raises('true if : blah ')
153
+
154
+ end
155
+
156
+ def test_for_delayed_compile
157
+ foorth_run('true if : tfdc_foo "foo" ; then')
158
+ foorth_equal('tfdc_foo', ["foo"])
159
+
160
+ foorth_run('false if : tfdc_bar "bar" ; then')
161
+ foorth_raises('tfdc_bar')
162
+
163
+ foorth_run('true if !: tfdd_foo "foo" ; then')
164
+ foorth_equal('tfdd_foo', ["foo"])
165
+
166
+ foorth_run('false if !: tfdd_bar "bar" ; then')
167
+ foorth_raises('tfdd_bar')
168
+
169
+ foorth_run('true if Object .: .tfde_foo "foo" ; then')
170
+ foorth_equal('Object .new .tfde_foo', ["foo"])
171
+
172
+ foorth_run('false if Object .: .tfde_bar "bar" ; then')
173
+ foorth_raises('Object .new .tfde_bar')
174
+
175
+ foorth_run('Object .new val$: $tfdf_obj')
176
+ foorth_run('true if $tfdf_obj .:: .tfdf_foo "foo" ; then')
177
+ foorth_equal('$tfdf_obj .tfdf_foo', ["foo"])
178
+
179
+ foorth_run('false if $tfdf_obj .:: .tfdf_bar "bar" ; then')
180
+ foorth_raises('$tfdf_obj .tfdf_bar')
181
+ end
182
+
183
+ def test_for_FILE_method
184
+ foorth_equal('_FILE_', ['A string.'])
185
+
186
+ nm = File.absolute_path('integration/_FILE_test.foorth')
187
+ foorth_equal('"integration/_FILE_test.foorth" .load ', [nm, 7, nm])
188
+ end
189
+
190
+ end