|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +const assert = require('assert'); |
| 4 | +const { startNewREPLServer } = require('../common/repl'); |
| 5 | + |
| 6 | +const dotCommandSyntaxError = |
| 7 | + /Uncaught SyntaxError: Unexpected token '\.'/; |
| 8 | + |
| 9 | + |
| 10 | +function runDotCommand(command, validate) { |
| 11 | + const { replServer, output } = startNewREPLServer(); |
| 12 | + |
| 13 | + replServer.on('exit', common.mustCall()); |
| 14 | + replServer.write('function a() {\n'); |
| 15 | + replServer.write(`${command}\n`); |
| 16 | + validate(replServer, output); |
| 17 | + replServer.write('arr = [1,\n'); |
| 18 | + replServer.write(`${command}\n`); |
| 19 | + validate(replServer, output); |
| 20 | + replServer.close(); |
| 21 | +} |
| 22 | + |
| 23 | +runDotCommand('.break', ((replServer, output) => { |
| 24 | + replServer.write('1 + 1\n'); |
| 25 | + assert.doesNotMatch(output.accumulator, dotCommandSyntaxError); |
| 26 | + assert.match(output.accumulator, /2\n/); |
| 27 | +})); |
| 28 | + |
| 29 | +runDotCommand('.clear', ((replServer, output) => { |
| 30 | + replServer.write('1 + 1\n'); |
| 31 | + assert.doesNotMatch(output.accumulator, dotCommandSyntaxError); |
| 32 | + assert.match(output.accumulator, /2\n/); |
| 33 | +})); |
| 34 | + |
| 35 | +runDotCommand('.help', ((replServer, output) => { |
| 36 | + replServer.write('1 + 1\n'); |
| 37 | + assert.doesNotMatch(output.accumulator, dotCommandSyntaxError); |
| 38 | + assert.match(output.accumulator, /2\n/); |
| 39 | +})); |
0 commit comments