Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
repl: Test _ behavior in REPL_MODE_MAGIC mode.
Add a test based on feedback from @cjihrig. Ensures that when used
in 'magic' mode, the behavior of `_` assignment is consistent with
other modes and user expectations.
  • Loading branch information
lance committed Mar 15, 2016
commit 428cef65eeafe61f23c32997ceaaec5d4ae91060
34 changes: 34 additions & 0 deletions test/parallel/test-repl-underscore.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const stream = require('stream');
testSloppyMode();
testStrictMode();
testResetContext();
testMagicMode();

function testSloppyMode() {
const r = initRepl(repl.REPL_MODE_SLOPPY);
Expand Down Expand Up @@ -75,6 +76,39 @@ function testStrictMode() {
]);
}

function testMagicMode() {
const r = initRepl(repl.REPL_MODE_MAGIC);

r.write(`_; // initial value undefined
x = 10; //
_; // last eval - 10
let _ = 20; // undefined
_; // 20 from user input
_ = 30; // make sure we can set it twice and no prompt
_; // 30 from user input
var y = 40; // make sure eval doesn't change _
_; // remains 30 from user input
function f() { let _ = 50; return _; } // undefined
f(); // 50
_; // remains 30 from user input
`);

assertOutput(r.output, [
'undefined',
'10',
'10',
'undefined',
'20',
'30',
'30',
'undefined',
'30',
'undefined',
'50',
'30'
]);
}

function testResetContext() {
const r = initRepl(repl.REPL_MODE_SLOPPY);

Expand Down