|
1 | 1 | var test = require('tap').test; |
2 | 2 | var Thread = require('../../src/engine/thread'); |
| 3 | +var RenderedTarget = require('../../src/sprites/rendered-target'); |
| 4 | +var Sprite = require('../../src/sprites/sprite'); |
3 | 5 |
|
4 | 6 | test('spec', function (t) { |
5 | 7 | t.type(Thread, 'function'); |
@@ -111,3 +113,165 @@ test('PushGetParam', function (t) { |
111 | 113 |
|
112 | 114 | t.end(); |
113 | 115 | }); |
| 116 | + |
| 117 | +test('goToNextBlock', function (t) { |
| 118 | + var th = new Thread('arbitraryString'); |
| 119 | + var s = new Sprite(); |
| 120 | + var rt = new RenderedTarget(s, null); |
| 121 | + var block1 = {fields: Object, |
| 122 | + id: 'arbitraryString', |
| 123 | + inputs: Object, |
| 124 | + STEPS: Object, |
| 125 | + block: 'fakeBlock', |
| 126 | + name: 'STEPS', |
| 127 | + next: 'secondString', |
| 128 | + opcode: 'motion_movesteps', |
| 129 | + parent: null, |
| 130 | + shadow: false, |
| 131 | + topLevel: true, |
| 132 | + x: 0, |
| 133 | + y: 0 |
| 134 | + }; |
| 135 | + var block2 = {fields: Object, |
| 136 | + id: 'secondString', |
| 137 | + inputs: Object, |
| 138 | + STEPS: Object, |
| 139 | + block: 'fakeBlock', |
| 140 | + name: 'STEPS', |
| 141 | + next: null, |
| 142 | + opcode: 'procedures_callnoreturn', |
| 143 | + mutation: {proccode: 'fakeCode'}, |
| 144 | + parent: null, |
| 145 | + shadow: false, |
| 146 | + topLevel: true, |
| 147 | + x: 0, |
| 148 | + y: 0 |
| 149 | + }; |
| 150 | + |
| 151 | + rt.blocks.createBlock(block1); |
| 152 | + rt.blocks.createBlock(block2); |
| 153 | + rt.blocks.createBlock(block2); |
| 154 | + th.target = rt; |
| 155 | + |
| 156 | + t.strictEquals(th.peekStack(), null); |
| 157 | + th.pushStack('secondString'); |
| 158 | + t.strictEquals(th.peekStack(), 'secondString'); |
| 159 | + th.goToNextBlock(); |
| 160 | + t.strictEquals(th.peekStack(), null); |
| 161 | + th.pushStack('secondString'); |
| 162 | + th.pushStack('arbitraryString'); |
| 163 | + t.strictEquals(th.peekStack(), 'arbitraryString'); |
| 164 | + th.goToNextBlock(); |
| 165 | + t.strictEquals(th.peekStack(), 'secondString'); |
| 166 | + th.goToNextBlock(); |
| 167 | + t.strictEquals(th.peekStack(), null); |
| 168 | + |
| 169 | + t.end(); |
| 170 | +}); |
| 171 | + |
| 172 | +test('stopThisScript', function (t) { |
| 173 | + var th = new Thread('arbitraryString'); |
| 174 | + var s = new Sprite(); |
| 175 | + var rt = new RenderedTarget(s, null); |
| 176 | + var block1 = {fields: Object, |
| 177 | + id: 'arbitraryString', |
| 178 | + inputs: Object, |
| 179 | + STEPS: Object, |
| 180 | + block: 'fakeBlock', |
| 181 | + name: 'STEPS', |
| 182 | + next: null, |
| 183 | + opcode: 'motion_movesteps', |
| 184 | + parent: null, |
| 185 | + shadow: false, |
| 186 | + topLevel: true, |
| 187 | + x: 0, |
| 188 | + y: 0 |
| 189 | + }; |
| 190 | + var block2 = {fields: Object, |
| 191 | + id: 'secondString', |
| 192 | + inputs: Object, |
| 193 | + STEPS: Object, |
| 194 | + block: 'fakeBlock', |
| 195 | + name: 'STEPS', |
| 196 | + next: null, |
| 197 | + opcode: 'procedures_callnoreturn', |
| 198 | + mutation: {proccode: 'fakeCode'}, |
| 199 | + parent: null, |
| 200 | + shadow: false, |
| 201 | + topLevel: true, |
| 202 | + x: 0, |
| 203 | + y: 0 |
| 204 | + }; |
| 205 | + |
| 206 | + rt.blocks.createBlock(block1); |
| 207 | + rt.blocks.createBlock(block2); |
| 208 | + th.target = rt; |
| 209 | + |
| 210 | + th.stopThisScript(); |
| 211 | + t.strictEquals(th.peekStack(), null); |
| 212 | + th.pushStack('arbitraryString'); |
| 213 | + t.strictEquals(th.peekStack(), 'arbitraryString'); |
| 214 | + th.stopThisScript(); |
| 215 | + t.strictEquals(th.peekStack(), null); |
| 216 | + th.pushStack('arbitraryString'); |
| 217 | + th.pushStack('secondString'); |
| 218 | + th.stopThisScript(); |
| 219 | + t.strictEquals(th.peekStack(), 'secondString'); |
| 220 | + |
| 221 | + t.end(); |
| 222 | +}); |
| 223 | + |
| 224 | +test('isRecursiveCall', function (t) { |
| 225 | + var th = new Thread('arbitraryString'); |
| 226 | + var s = new Sprite(); |
| 227 | + var rt = new RenderedTarget(s, null); |
| 228 | + var block1 = {fields: Object, |
| 229 | + id: 'arbitraryString', |
| 230 | + inputs: Object, |
| 231 | + STEPS: Object, |
| 232 | + block: 'fakeBlock', |
| 233 | + name: 'STEPS', |
| 234 | + next: null, |
| 235 | + opcode: 'motion_movesteps', |
| 236 | + parent: null, |
| 237 | + shadow: false, |
| 238 | + topLevel: true, |
| 239 | + x: 0, |
| 240 | + y: 0 |
| 241 | + }; |
| 242 | + var block2 = {fields: Object, |
| 243 | + id: 'secondString', |
| 244 | + inputs: Object, |
| 245 | + STEPS: Object, |
| 246 | + block: 'fakeBlock', |
| 247 | + name: 'STEPS', |
| 248 | + next: null, |
| 249 | + opcode: 'procedures_callnoreturn', |
| 250 | + mutation: {proccode: 'fakeCode'}, |
| 251 | + parent: null, |
| 252 | + shadow: false, |
| 253 | + topLevel: true, |
| 254 | + x: 0, |
| 255 | + y: 0 |
| 256 | + }; |
| 257 | + |
| 258 | + rt.blocks.createBlock(block1); |
| 259 | + rt.blocks.createBlock(block2); |
| 260 | + th.target = rt; |
| 261 | + |
| 262 | + t.strictEquals(th.isRecursiveCall('fakeCode'), false); |
| 263 | + th.pushStack('secondString'); |
| 264 | + t.strictEquals(th.isRecursiveCall('fakeCode'), false); |
| 265 | + th.pushStack('arbitraryString'); |
| 266 | + t.strictEquals(th.isRecursiveCall('fakeCode'), true); |
| 267 | + th.pushStack('arbitraryString'); |
| 268 | + t.strictEquals(th.isRecursiveCall('fakeCode'), true); |
| 269 | + th.popStack(); |
| 270 | + t.strictEquals(th.isRecursiveCall('fakeCode'), true); |
| 271 | + th.popStack(); |
| 272 | + t.strictEquals(th.isRecursiveCall('fakeCode'), false); |
| 273 | + th.popStack(); |
| 274 | + t.strictEquals(th.isRecursiveCall('fakeCode'), false); |
| 275 | + |
| 276 | + t.end(); |
| 277 | +}); |
0 commit comments