• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright Joyent, Inc. and other Node contributors.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a
4// copy of this software and associated documentation files (the
5// "Software"), to deal in the Software without restriction, including
6// without limitation the rights to use, copy, modify, merge, publish,
7// distribute, sublicense, and/or sell copies of the Software, and to permit
8// persons to whom the Software is furnished to do so, subject to the
9// following conditions:
10//
11// The above copyright notice and this permission notice shall be included
12// in all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22'use strict';
23const common = require('../common');
24const ArrayStream = require('../common/arraystream');
25const assert = require('assert');
26const repl = require('repl');
27
28common.expectWarning({
29  DeprecationWarning: {
30    DEP0124: 'REPLServer.rli is deprecated'
31  }
32});
33
34// Create a dummy stream that does nothing
35const stream = new ArrayStream();
36
37// 1, mostly defaults
38const r1 = repl.start({
39  input: stream,
40  output: stream,
41  terminal: true
42});
43
44assert.strictEqual(r1.input, stream);
45assert.strictEqual(r1.output, stream);
46assert.strictEqual(r1.input, r1.inputStream);
47assert.strictEqual(r1.output, r1.outputStream);
48assert.strictEqual(r1.terminal, true);
49assert.strictEqual(r1.useColors, r1.terminal);
50assert.strictEqual(r1.useGlobal, false);
51assert.strictEqual(r1.ignoreUndefined, false);
52assert.strictEqual(r1.replMode, repl.REPL_MODE_SLOPPY);
53assert.strictEqual(r1.historySize, 30);
54
55// Test r1 for backwards compact
56assert.strictEqual(r1.rli.input, stream);
57assert.strictEqual(r1.rli.output, stream);
58assert.strictEqual(r1.rli.input, r1.inputStream);
59assert.strictEqual(r1.rli.output, r1.outputStream);
60assert.strictEqual(r1.rli.terminal, true);
61assert.strictEqual(r1.useColors, r1.rli.terminal);
62
63// 2
64function writer() {}
65
66function evaler() {}
67const r2 = repl.start({
68  input: stream,
69  output: stream,
70  terminal: false,
71  useColors: true,
72  useGlobal: true,
73  ignoreUndefined: true,
74  eval: evaler,
75  writer: writer,
76  replMode: repl.REPL_MODE_STRICT,
77  historySize: 50
78});
79assert.strictEqual(r2.input, stream);
80assert.strictEqual(r2.output, stream);
81assert.strictEqual(r2.input, r2.inputStream);
82assert.strictEqual(r2.output, r2.outputStream);
83assert.strictEqual(r2.terminal, false);
84assert.strictEqual(r2.useColors, true);
85assert.strictEqual(r2.useGlobal, true);
86assert.strictEqual(r2.ignoreUndefined, true);
87assert.strictEqual(r2.writer, writer);
88assert.strictEqual(r2.replMode, repl.REPL_MODE_STRICT);
89assert.strictEqual(r2.historySize, 50);
90
91// Test r2 for backwards compact
92assert.strictEqual(r2.rli.input, stream);
93assert.strictEqual(r2.rli.output, stream);
94assert.strictEqual(r2.rli.input, r2.inputStream);
95assert.strictEqual(r2.rli.output, r2.outputStream);
96assert.strictEqual(r2.rli.terminal, false);
97
98// 3, breakEvalOnSigint and eval supplied together should cause a throw
99const r3 = () => repl.start({
100  breakEvalOnSigint: true,
101  eval: true
102});
103
104assert.throws(r3, {
105  code: 'ERR_INVALID_REPL_EVAL_CONFIG',
106  name: 'TypeError',
107  message: 'Cannot specify both "breakEvalOnSigint" and "eval" for REPL'
108});
109
110// 4, Verify that defaults are used when no arguments are provided
111const r4 = repl.start();
112
113assert.strictEqual(r4._prompt, '> ');
114assert.strictEqual(r4.input, process.stdin);
115assert.strictEqual(r4.output, process.stdout);
116assert.strictEqual(r4.terminal, !!r4.output.isTTY);
117assert.strictEqual(r4.useColors, r4.terminal);
118assert.strictEqual(r4.useGlobal, false);
119assert.strictEqual(r4.ignoreUndefined, false);
120assert.strictEqual(r4.replMode, repl.REPL_MODE_SLOPPY);
121assert.strictEqual(r4.historySize, 30);
122r4.close();
123