yarbf 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +29 -0
  3. data/.gitignore +1 -1
  4. data/.rubocop.yml +1168 -0
  5. data/bin/yarbf +2 -2
  6. data/lib/yarbf.rb +147 -73
  7. data/lib/yarbf/version.rb +1 -1
  8. data/test/bf/hello-world.bf +15 -0
  9. data/test/bf/pi.bf +229 -0
  10. data/test/bf/show-bf.bf +17 -0
  11. data/test/bf/square.bf +79 -0
  12. data/test/helper.rb +40 -0
  13. data/test/input/cell_size/pi-10 +0 -0
  14. data/test/input/cell_size/pi-11 +0 -0
  15. data/test/input/cell_size/pi-12 +0 -0
  16. data/test/input/cell_size/pi-16 +0 -0
  17. data/test/input/cell_size/pi-8 +0 -0
  18. data/test/input/cell_size/pi-9 +0 -0
  19. data/test/input/debug/hello-world +0 -0
  20. data/test/input/debug/pi +0 -0
  21. data/test/input/debug/show-bf +1 -0
  22. data/test/input/debug/square +0 -0
  23. data/test/input/hello-world +0 -0
  24. data/test/input/input_mode/show-bf-buffered +1 -0
  25. data/test/input/input_mode/show-bf-raw +1 -0
  26. data/test/input/pi +0 -0
  27. data/test/input/show-bf +1 -0
  28. data/test/input/square +0 -0
  29. data/test/input/wrap_around/pi +0 -0
  30. data/test/output/cell_size/pi-10-1 +1 -0
  31. data/test/output/cell_size/pi-10-2 +1 -0
  32. data/test/output/cell_size/pi-11-1 +1 -0
  33. data/test/output/cell_size/pi-11-2 +0 -0
  34. data/test/output/cell_size/pi-12-1 +1 -0
  35. data/test/output/cell_size/pi-12-2 +0 -0
  36. data/test/output/cell_size/pi-16-1 +1 -0
  37. data/test/output/cell_size/pi-16-2 +0 -0
  38. data/test/output/cell_size/pi-32-1 +1 -0
  39. data/test/output/cell_size/pi-32-2 +0 -0
  40. data/test/output/cell_size/pi-8-1 +0 -0
  41. data/test/output/cell_size/pi-8-2 +1 -0
  42. data/test/output/cell_size/pi-9-1 +1 -0
  43. data/test/output/cell_size/pi-9-2 +1 -0
  44. data/test/output/construct_program_units/hello-world-1 +106 -0
  45. data/test/output/construct_program_units/pi-1 +648 -0
  46. data/test/output/construct_program_units/show-bf-1 +49 -0
  47. data/test/output/construct_program_units/square-1 +191 -0
  48. data/test/output/debug/hello-world-1 +1 -0
  49. data/test/output/debug/hello-world-2 +1 -0
  50. data/test/output/debug/pi-1 +0 -0
  51. data/test/output/debug/pi-2 +1 -0
  52. data/test/output/debug/show-bf-1 +1 -0
  53. data/test/output/debug/show-bf-2 +1 -0
  54. data/test/output/debug/square-1 +101 -0
  55. data/test/output/debug/square-2 +1 -0
  56. data/test/output/hello-world-1 +1 -0
  57. data/test/output/hello-world-2 +0 -0
  58. data/test/output/input_mode/show-bf-buffered-1 +1 -0
  59. data/test/output/input_mode/show-bf-buffered-2 +0 -0
  60. data/test/output/input_mode/show-bf-raw-1 +0 -0
  61. data/test/output/input_mode/show-bf-raw-2 +1 -0
  62. data/test/output/match_brackets/hello-world-1 +106 -0
  63. data/test/output/match_brackets/pi-1 +648 -0
  64. data/test/output/match_brackets/show-bf-1 +49 -0
  65. data/test/output/match_brackets/square-1 +191 -0
  66. data/test/output/pi-1 +0 -0
  67. data/test/output/pi-2 +1 -0
  68. data/test/output/show-bf-1 +1 -0
  69. data/test/output/show-bf-2 +0 -0
  70. data/test/output/square-1 +101 -0
  71. data/test/output/square-2 +0 -0
  72. data/test/output/wrap_around/pi-1 +1 -0
  73. data/test/output/wrap_around/pi-2 +0 -0
  74. data/test/test_bf_interpreter.rb +116 -0
  75. data/test/test_cell_size.rb +29 -0
  76. data/test/test_debug.rb +25 -0
  77. data/test/test_default.rb +19 -0
  78. data/test/test_input_mode.rb +29 -0
  79. data/test/test_wrap_around.rb +25 -0
  80. data/yarbf.gemspec +1 -1
  81. metadata +76 -2
@@ -0,0 +1,49 @@
1
+ { ins: '+', pos: 0, next: 1 }
2
+ { ins: '+', pos: 1, next: 2 }
3
+ { ins: '+', pos: 2, next: 3 }
4
+ { ins: '+', pos: 3, next: 4 }
5
+ { ins: '+', pos: 4, next: 5 }
6
+ { ins: '[', pos: 5, next: 6, match: 18 }
7
+ { ins: '>', pos: 6, next: 7 }
8
+ { ins: '+', pos: 7, next: 8 }
9
+ { ins: '+', pos: 8, next: 9 }
10
+ { ins: '+', pos: 9, next: 10 }
11
+ { ins: '+', pos: 10, next: 11 }
12
+ { ins: '+', pos: 11, next: 12 }
13
+ { ins: '+', pos: 12, next: 13 }
14
+ { ins: '+', pos: 13, next: 14 }
15
+ { ins: '+', pos: 14, next: 15 }
16
+ { ins: '+', pos: 15, next: 16 }
17
+ { ins: '<', pos: 16, next: 17 }
18
+ { ins: '-', pos: 17, next: 18 }
19
+ { ins: ']', pos: 18, next: 19, match: 5 }
20
+ { ins: ',', pos: 19, next: 20 }
21
+ { ins: '[', pos: 20, next: 21, match: 48 }
22
+ { ins: '[', pos: 21, next: 22, match: 33 }
23
+ { ins: '>', pos: 22, next: 23 }
24
+ { ins: '-', pos: 23, next: 24 }
25
+ { ins: '-', pos: 24, next: 25 }
26
+ { ins: '.', pos: 25, next: 26 }
27
+ { ins: '+', pos: 26, next: 27 }
28
+ { ins: '+', pos: 27, next: 28 }
29
+ { ins: '>', pos: 28, next: 29 }
30
+ { ins: '+', pos: 29, next: 30 }
31
+ { ins: '<', pos: 30, next: 31 }
32
+ { ins: '<', pos: 31, next: 32 }
33
+ { ins: '-', pos: 32, next: 33 }
34
+ { ins: ']', pos: 33, next: 34, match: 21 }
35
+ { ins: '>', pos: 34, next: 35 }
36
+ { ins: '+', pos: 35, next: 36 }
37
+ { ins: '.', pos: 36, next: 37 }
38
+ { ins: '-', pos: 37, next: 38 }
39
+ { ins: '>', pos: 38, next: 39 }
40
+ { ins: '[', pos: 39, next: 40, match: 44 }
41
+ { ins: '<', pos: 40, next: 41 }
42
+ { ins: '.', pos: 41, next: 42 }
43
+ { ins: '>', pos: 42, next: 43 }
44
+ { ins: '-', pos: 43, next: 44 }
45
+ { ins: ']', pos: 44, next: 45, match: 39 }
46
+ { ins: '<', pos: 45, next: 46 }
47
+ { ins: '<', pos: 46, next: 47 }
48
+ { ins: ',', pos: 47, next: 48 }
49
+ { ins: ']', pos: 48, match: 20 }
@@ -0,0 +1,191 @@
1
+ { ins: '+', pos: 0, next: 1 }
2
+ { ins: '+', pos: 1, next: 2 }
3
+ { ins: '+', pos: 2, next: 3 }
4
+ { ins: '+', pos: 3, next: 4 }
5
+ { ins: '[', pos: 4, next: 5, match: 13 }
6
+ { ins: '>', pos: 5, next: 6 }
7
+ { ins: '+', pos: 6, next: 7 }
8
+ { ins: '+', pos: 7, next: 8 }
9
+ { ins: '+', pos: 8, next: 9 }
10
+ { ins: '+', pos: 9, next: 10 }
11
+ { ins: '+', pos: 10, next: 11 }
12
+ { ins: '<', pos: 11, next: 12 }
13
+ { ins: '-', pos: 12, next: 13 }
14
+ { ins: ']', pos: 13, next: 14, match: 4 }
15
+ { ins: '>', pos: 14, next: 15 }
16
+ { ins: '[', pos: 15, next: 16, match: 24 }
17
+ { ins: '<', pos: 16, next: 17 }
18
+ { ins: '+', pos: 17, next: 18 }
19
+ { ins: '+', pos: 18, next: 19 }
20
+ { ins: '+', pos: 19, next: 20 }
21
+ { ins: '+', pos: 20, next: 21 }
22
+ { ins: '+', pos: 21, next: 22 }
23
+ { ins: '>', pos: 22, next: 23 }
24
+ { ins: '-', pos: 23, next: 24 }
25
+ { ins: ']', pos: 24, next: 25, match: 15 }
26
+ { ins: '+', pos: 25, next: 26 }
27
+ { ins: '<', pos: 26, next: 27 }
28
+ { ins: '+', pos: 27, next: 28 }
29
+ { ins: '[', pos: 28, next: 29, match: 190 }
30
+ { ins: '>', pos: 29, next: 30 }
31
+ { ins: '[', pos: 30, next: 31, match: 38 }
32
+ { ins: '>', pos: 31, next: 32 }
33
+ { ins: '+', pos: 32, next: 33 }
34
+ { ins: '>', pos: 33, next: 34 }
35
+ { ins: '+', pos: 34, next: 35 }
36
+ { ins: '<', pos: 35, next: 36 }
37
+ { ins: '<', pos: 36, next: 37 }
38
+ { ins: '-', pos: 37, next: 38 }
39
+ { ins: ']', pos: 38, next: 39, match: 30 }
40
+ { ins: '+', pos: 39, next: 40 }
41
+ { ins: '+', pos: 40, next: 41 }
42
+ { ins: '>', pos: 41, next: 42 }
43
+ { ins: '>', pos: 42, next: 43 }
44
+ { ins: '[', pos: 43, next: 44, match: 50 }
45
+ { ins: '<', pos: 44, next: 45 }
46
+ { ins: '<', pos: 45, next: 46 }
47
+ { ins: '+', pos: 46, next: 47 }
48
+ { ins: '>', pos: 47, next: 48 }
49
+ { ins: '>', pos: 48, next: 49 }
50
+ { ins: '-', pos: 49, next: 50 }
51
+ { ins: ']', pos: 50, next: 51, match: 43 }
52
+ { ins: '>', pos: 51, next: 52 }
53
+ { ins: '>', pos: 52, next: 53 }
54
+ { ins: '>', pos: 53, next: 54 }
55
+ { ins: '[', pos: 54, next: 55, match: 56 }
56
+ { ins: '-', pos: 55, next: 56 }
57
+ { ins: ']', pos: 56, next: 57, match: 54 }
58
+ { ins: '+', pos: 57, next: 58 }
59
+ { ins: '+', pos: 58, next: 59 }
60
+ { ins: '>', pos: 59, next: 60 }
61
+ { ins: '[', pos: 60, next: 61, match: 62 }
62
+ { ins: '-', pos: 61, next: 62 }
63
+ { ins: ']', pos: 62, next: 63, match: 60 }
64
+ { ins: '+', pos: 63, next: 64 }
65
+ { ins: '>', pos: 64, next: 65 }
66
+ { ins: '>', pos: 65, next: 66 }
67
+ { ins: '>', pos: 66, next: 67 }
68
+ { ins: '+', pos: 67, next: 68 }
69
+ { ins: '[', pos: 68, next: 69, match: 81 }
70
+ { ins: '[', pos: 69, next: 70, match: 71 }
71
+ { ins: '-', pos: 70, next: 71 }
72
+ { ins: ']', pos: 71, next: 72, match: 69 }
73
+ { ins: '+', pos: 72, next: 73 }
74
+ { ins: '+', pos: 73, next: 74 }
75
+ { ins: '+', pos: 74, next: 75 }
76
+ { ins: '+', pos: 75, next: 76 }
77
+ { ins: '+', pos: 76, next: 77 }
78
+ { ins: '+', pos: 77, next: 78 }
79
+ { ins: '>', pos: 78, next: 79 }
80
+ { ins: '>', pos: 79, next: 80 }
81
+ { ins: '>', pos: 80, next: 81 }
82
+ { ins: ']', pos: 81, next: 82, match: 68 }
83
+ { ins: '<', pos: 82, next: 83 }
84
+ { ins: '<', pos: 83, next: 84 }
85
+ { ins: '<', pos: 84, next: 85 }
86
+ { ins: '[', pos: 85, next: 86, match: 117 }
87
+ { ins: '[', pos: 86, next: 87, match: 102 }
88
+ { ins: '<', pos: 87, next: 88 }
89
+ { ins: '+', pos: 88, next: 89 }
90
+ { ins: '+', pos: 89, next: 90 }
91
+ { ins: '+', pos: 90, next: 91 }
92
+ { ins: '+', pos: 91, next: 92 }
93
+ { ins: '+', pos: 92, next: 93 }
94
+ { ins: '+', pos: 93, next: 94 }
95
+ { ins: '+', pos: 94, next: 95 }
96
+ { ins: '+', pos: 95, next: 96 }
97
+ { ins: '<', pos: 96, next: 97 }
98
+ { ins: '+', pos: 97, next: 98 }
99
+ { ins: '+', pos: 98, next: 99 }
100
+ { ins: '>', pos: 99, next: 100 }
101
+ { ins: '>', pos: 100, next: 101 }
102
+ { ins: '-', pos: 101, next: 102 }
103
+ { ins: ']', pos: 102, next: 103, match: 86 }
104
+ { ins: '+', pos: 103, next: 104 }
105
+ { ins: '<', pos: 104, next: 105 }
106
+ { ins: '.', pos: 105, next: 106 }
107
+ { ins: '<', pos: 106, next: 107 }
108
+ { ins: '[', pos: 107, next: 108, match: 115 }
109
+ { ins: '>', pos: 108, next: 109 }
110
+ { ins: '-', pos: 109, next: 110 }
111
+ { ins: '-', pos: 110, next: 111 }
112
+ { ins: '-', pos: 111, next: 112 }
113
+ { ins: '-', pos: 112, next: 113 }
114
+ { ins: '<', pos: 113, next: 114 }
115
+ { ins: '-', pos: 114, next: 115 }
116
+ { ins: ']', pos: 115, next: 116, match: 107 }
117
+ { ins: '<', pos: 116, next: 117 }
118
+ { ins: ']', pos: 117, next: 118, match: 85 }
119
+ { ins: '<', pos: 118, next: 119 }
120
+ { ins: '<', pos: 119, next: 120 }
121
+ { ins: '[', pos: 120, next: 121, match: 186 }
122
+ { ins: '>', pos: 121, next: 122 }
123
+ { ins: '>', pos: 122, next: 123 }
124
+ { ins: '>', pos: 123, next: 124 }
125
+ { ins: '>', pos: 124, next: 125 }
126
+ { ins: '>', pos: 125, next: 126 }
127
+ { ins: '[', pos: 126, next: 127, match: 182 }
128
+ { ins: '>', pos: 127, next: 128 }
129
+ { ins: '>', pos: 128, next: 129 }
130
+ { ins: '>', pos: 129, next: 130 }
131
+ { ins: '[', pos: 130, next: 131, match: 132 }
132
+ { ins: '-', pos: 131, next: 132 }
133
+ { ins: ']', pos: 132, next: 133, match: 130 }
134
+ { ins: '+', pos: 133, next: 134 }
135
+ { ins: '+', pos: 134, next: 135 }
136
+ { ins: '+', pos: 135, next: 136 }
137
+ { ins: '+', pos: 136, next: 137 }
138
+ { ins: '+', pos: 137, next: 138 }
139
+ { ins: '+', pos: 138, next: 139 }
140
+ { ins: '+', pos: 139, next: 140 }
141
+ { ins: '+', pos: 140, next: 141 }
142
+ { ins: '+', pos: 141, next: 142 }
143
+ { ins: '<', pos: 142, next: 143 }
144
+ { ins: '[', pos: 143, next: 144, match: 148 }
145
+ { ins: '>', pos: 144, next: 145 }
146
+ { ins: '-', pos: 145, next: 146 }
147
+ { ins: '<', pos: 146, next: 147 }
148
+ { ins: '-', pos: 147, next: 148 }
149
+ { ins: ']', pos: 148, next: 149, match: 143 }
150
+ { ins: '+', pos: 149, next: 150 }
151
+ { ins: '+', pos: 150, next: 151 }
152
+ { ins: '+', pos: 151, next: 152 }
153
+ { ins: '+', pos: 152, next: 153 }
154
+ { ins: '+', pos: 153, next: 154 }
155
+ { ins: '+', pos: 154, next: 155 }
156
+ { ins: '+', pos: 155, next: 156 }
157
+ { ins: '+', pos: 156, next: 157 }
158
+ { ins: '+', pos: 157, next: 158 }
159
+ { ins: '>', pos: 158, next: 159 }
160
+ { ins: '[', pos: 159, next: 160, match: 173 }
161
+ { ins: '-', pos: 160, next: 161 }
162
+ { ins: '[', pos: 161, next: 162, match: 166 }
163
+ { ins: '<', pos: 162, next: 163 }
164
+ { ins: '-', pos: 163, next: 164 }
165
+ { ins: '>', pos: 164, next: 165 }
166
+ { ins: '-', pos: 165, next: 166 }
167
+ { ins: ']', pos: 166, next: 167, match: 161 }
168
+ { ins: '+', pos: 167, next: 168 }
169
+ { ins: '[', pos: 168, next: 169, match: 172 }
170
+ { ins: '<', pos: 169, next: 170 }
171
+ { ins: '<', pos: 170, next: 171 }
172
+ { ins: '<', pos: 171, next: 172 }
173
+ { ins: ']', pos: 172, next: 173, match: 168 }
174
+ { ins: ']', pos: 173, next: 174, match: 159 }
175
+ { ins: '<', pos: 174, next: 175 }
176
+ { ins: '[', pos: 175, next: 176, match: 180 }
177
+ { ins: '>', pos: 176, next: 177 }
178
+ { ins: '+', pos: 177, next: 178 }
179
+ { ins: '<', pos: 178, next: 179 }
180
+ { ins: '-', pos: 179, next: 180 }
181
+ { ins: ']', pos: 180, next: 181, match: 175 }
182
+ { ins: '>', pos: 181, next: 182 }
183
+ { ins: ']', pos: 182, next: 183, match: 126 }
184
+ { ins: '<', pos: 183, next: 184 }
185
+ { ins: '<', pos: 184, next: 185 }
186
+ { ins: '-', pos: 185, next: 186 }
187
+ { ins: ']', pos: 186, next: 187, match: 120 }
188
+ { ins: '<', pos: 187, next: 188 }
189
+ { ins: '<', pos: 188, next: 189 }
190
+ { ins: '-', pos: 189, next: 190 }
191
+ { ins: ']', pos: 190, match: 28 }
File without changes
@@ -0,0 +1 @@
1
+ yarbf: Overflow or underflow happened while forbidden!
@@ -0,0 +1 @@
1
+ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------------------------------------------------------------------------------------------------------------------------+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.-------------------------------------------------------------------------------------------------++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.------------------------------------------------------------------------------------------------------------------++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.--------------------------------------------------------------------------------------------------++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.------------------------------------------------------------------------------------------------------++++++++++.----------
File without changes
@@ -0,0 +1,101 @@
1
+ 0
2
+ 1
3
+ 4
4
+ 9
5
+ 16
6
+ 25
7
+ 36
8
+ 49
9
+ 64
10
+ 81
11
+ 100
12
+ 121
13
+ 144
14
+ 169
15
+ 196
16
+ 225
17
+ 256
18
+ 289
19
+ 324
20
+ 361
21
+ 400
22
+ 441
23
+ 484
24
+ 529
25
+ 576
26
+ 625
27
+ 676
28
+ 729
29
+ 784
30
+ 841
31
+ 900
32
+ 961
33
+ 1024
34
+ 1089
35
+ 1156
36
+ 1225
37
+ 1296
38
+ 1369
39
+ 1444
40
+ 1521
41
+ 1600
42
+ 1681
43
+ 1764
44
+ 1849
45
+ 1936
46
+ 2025
47
+ 2116
48
+ 2209
49
+ 2304
50
+ 2401
51
+ 2500
52
+ 2601
53
+ 2704
54
+ 2809
55
+ 2916
56
+ 3025
57
+ 3136
58
+ 3249
59
+ 3364
60
+ 3481
61
+ 3600
62
+ 3721
63
+ 3844
64
+ 3969
65
+ 4096
66
+ 4225
67
+ 4356
68
+ 4489
69
+ 4624
70
+ 4761
71
+ 4900
72
+ 5041
73
+ 5184
74
+ 5329
75
+ 5476
76
+ 5625
77
+ 5776
78
+ 5929
79
+ 6084
80
+ 6241
81
+ 6400
82
+ 6561
83
+ 6724
84
+ 6889
85
+ 7056
86
+ 7225
87
+ 7396
88
+ 7569
89
+ 7744
90
+ 7921
91
+ 8100
92
+ 8281
93
+ 8464
94
+ 8649
95
+ 8836
96
+ 9025
97
+ 9216
98
+ 9409
99
+ 9604
100
+ 9801
101
+ 10000
File without changes
@@ -0,0 +1 @@
1
+ 3.14070455282885
File without changes
@@ -0,0 +1,116 @@
1
+ require 'helper' # for TestBase
2
+
3
+ class TestBfInterpreter < TestBase
4
+ def setup
5
+ super
6
+
7
+ # default options for this test
8
+ @options = {
9
+ :debug => true,
10
+ :wrap_around => true,
11
+ :cell_size => 7,
12
+ :input_mode => :raw
13
+ }
14
+ end
15
+
16
+ # test BfInterpreter#initialize
17
+ def test_initialize
18
+ initialize_with_invalid_type
19
+ initialize_missing_options
20
+ initialize_with_other_options
21
+ end
22
+
23
+ def initialize_with_invalid_type
24
+ options = 'debug: true, wrap_around: true, cell_size: 7, input_mode: raw'
25
+ assert_raises do
26
+ Yarbf::BfInterpreter.new(options)
27
+ end
28
+ end
29
+
30
+ def initialize_missing_options
31
+ @options.each_key do |key|
32
+ options = @options.reject { |k| k == key }
33
+ assert_raises do
34
+ Yarbf::BfInterpreter.new(options)
35
+ end
36
+ end
37
+ end
38
+
39
+ def initialize_with_other_options
40
+ options = {
41
+ :debug => true,
42
+ :wrap_around => true,
43
+ :cell_size => 7,
44
+ :input_mode => :raw,
45
+
46
+ # other options
47
+ :just_a_test => 'yes'
48
+ }
49
+ expected = {
50
+ :debug => true,
51
+ :wrap_around => true,
52
+ :cell_size => 7,
53
+ :input_mode => :raw
54
+ }
55
+ actual = Yarbf::BfInterpreter.new(options).instance_variable_get(:@options)
56
+ assert_equal(expected, actual)
57
+ end
58
+
59
+ private :initialize_with_invalid_type, :initialize_missing_options,
60
+ :initialize_with_other_options
61
+
62
+ # test BfInterpreter#*?
63
+ def test_option_accessors
64
+ interpreter = Yarbf::BfInterpreter.new(@options)
65
+
66
+ # debug accessor
67
+ assert_raises { interpreter.debug = :debug }
68
+ assert_equal(@options[:debug], interpreter.debug?)
69
+ assert_equal(false, interpreter.debug = false)
70
+ # wrap around accessor
71
+ assert_raises { interpreter.wrap_around = 'no' }
72
+ assert_equal(@options[:wrap_around], interpreter.wrap_around?)
73
+ assert_equal(false, interpreter.wrap_around = false)
74
+ # cell size accessor
75
+ assert_raises { interpreter.cell_size = 8.0 }
76
+ assert_equal(@options[:cell_size], interpreter.cell_size?)
77
+ assert_equal(9, interpreter.cell_size = 9)
78
+ # input mode accessor
79
+ assert_raises { interpreter.input_mode = :some_other_mode }
80
+ assert_equal(@options[:input_mode], interpreter.input_mode?)
81
+ assert_equal(:buffered, interpreter.input_mode = :buffered)
82
+ end
83
+
84
+ # test BfInterpreter#construct_program_units and BfInterpreter#match_brackets
85
+ def test_construct_program_units
86
+ interpreter = Yarbf::BfInterpreter.new(@options)
87
+
88
+ out_dir_1 = File.join(@output_dir, 'construct_program_units')
89
+ out_dir_2 = File.join(@output_dir, 'match_brackets')
90
+
91
+ Dir.foreach(@bf_src_sir) do |src|
92
+ next if src.eql?('.') || src.eql?('..')
93
+
94
+ filename = /(.*)\.bf$/.match(src)[1]
95
+ File.open(File.join(@bf_src_sir, src)) do |file|
96
+ units = interpreter.send(:construct_program_units, file)
97
+ expected = File.join(out_dir_1, "#{filename}-1")
98
+ assert_equal(File.read(expected), capture_stdout { puts units })
99
+
100
+ interpreter.send(:match_brackets, units)
101
+ expected = File.join(out_dir_2, "#{filename}-1")
102
+ assert_equal(File.read(expected), capture_stdout { puts units })
103
+ end
104
+ end
105
+ end
106
+
107
+ def capture_stdout
108
+ prev, $stdout = $stdout, StringIO.new
109
+ yield
110
+ $stdout.string
111
+ ensure
112
+ $stdout = prev
113
+ end
114
+
115
+ private :capture_stdout
116
+ end