summaryrefslogtreecommitdiff
path: root/test/parallel/test-repl-mode.js
diff options
context:
space:
mode:
authorChris Dickinson <christopher.s.dickinson@gmail.com>2015-04-23 00:35:53 -0700
committerChris Dickinson <christopher.s.dickinson@gmail.com>2015-04-30 19:33:05 -0700
commit0450ce7db22ab4b6f9b2119197389ed7d3eac8c3 (patch)
tree9f9c8444e4370af50a0fa4216fbfa825a737eb0d /test/parallel/test-repl-mode.js
parenta5dcff827a2c7eaec9c20b6271bead8d2225c7c8 (diff)
downloadandroid-node-v8-0450ce7db22ab4b6f9b2119197389ed7d3eac8c3.tar.gz
android-node-v8-0450ce7db22ab4b6f9b2119197389ed7d3eac8c3.tar.bz2
android-node-v8-0450ce7db22ab4b6f9b2119197389ed7d3eac8c3.zip
repl: add mode detection, cli persistent history
this creates a new internal module responsible for providing the repl created via "iojs" or "iojs -i," and adds the following options to the readline and repl subsystems: * "repl mode" - determine whether a repl is strict mode, sloppy mode, or auto-detect mode. * historySize - determine the maximum number of lines a repl will store as history. The built-in repl gains persistent history support when the NODE_REPL_HISTORY_FILE environment variable is set. This functionality is not exposed to userland repl instances. PR-URL: https://github.com/iojs/io.js/pull/1513 Reviewed-By: Fedor Indutny <fedor@indutny.com>
Diffstat (limited to 'test/parallel/test-repl-mode.js')
-rw-r--r--test/parallel/test-repl-mode.js84
1 files changed, 84 insertions, 0 deletions
diff --git a/test/parallel/test-repl-mode.js b/test/parallel/test-repl-mode.js
new file mode 100644
index 0000000000..b71e213647
--- /dev/null
+++ b/test/parallel/test-repl-mode.js
@@ -0,0 +1,84 @@
+var common = require('../common');
+var assert = require('assert');
+var Stream = require('stream');
+var repl = require('repl');
+
+common.globalCheck = false;
+
+var tests = [
+ testSloppyMode,
+ testStrictMode,
+ testAutoMode
+];
+
+tests.forEach(function(test) {
+ test();
+});
+
+function testSloppyMode() {
+ var cli = initRepl(repl.REPL_MODE_SLOPPY);
+
+ cli.input.emit('data', `
+ x = 3
+ `.trim() + '\n');
+ assert.equal(cli.output.accumulator.join(''), '> 3\n> ')
+ cli.output.accumulator.length = 0;
+
+ cli.input.emit('data', `
+ let y = 3
+ `.trim() + '\n');
+ assert.ok(/SyntaxError: Block-scoped/.test(
+ cli.output.accumulator.join('')));
+}
+
+function testStrictMode() {
+ var cli = initRepl(repl.REPL_MODE_STRICT);
+
+ cli.input.emit('data', `
+ x = 3
+ `.trim() + '\n');
+ assert.ok(/ReferenceError: x is not defined/.test(
+ cli.output.accumulator.join('')));
+ cli.output.accumulator.length = 0;
+
+ cli.input.emit('data', `
+ let y = 3
+ `.trim() + '\n');
+ assert.equal(cli.output.accumulator.join(''), 'undefined\n> ');
+}
+
+function testAutoMode() {
+ var cli = initRepl(repl.REPL_MODE_MAGIC);
+
+ cli.input.emit('data', `
+ x = 3
+ `.trim() + '\n');
+ assert.equal(cli.output.accumulator.join(''), '> 3\n> ')
+ cli.output.accumulator.length = 0;
+
+ cli.input.emit('data', `
+ let y = 3
+ `.trim() + '\n');
+ assert.equal(cli.output.accumulator.join(''), 'undefined\n> ');
+}
+
+function initRepl(mode) {
+ var input = new Stream();
+ input.write = input.pause = input.resume = function(){};
+ input.readable = true;
+
+ var output = new Stream();
+ output.write = output.pause = output.resume = function(buf) {
+ output.accumulator.push(buf);
+ };
+ output.accumulator = [];
+ output.writable = true;
+
+ return repl.start({
+ input: input,
+ output: output,
+ useColors: false,
+ terminal: false,
+ replMode: mode
+ });
+}