11cb0ef41Sopenharmony_ci// Flags: --expose-internals
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ciconst readline = require('readline');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst noop = () => {};
81cb0ef41Sopenharmony_ciconst { internalBinding } = require('internal/test/binding');
91cb0ef41Sopenharmony_ciconst TTY = internalBinding('tty_wrap').TTY = function() {};
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciTTY.prototype = {
121cb0ef41Sopenharmony_ci  setBlocking: noop,
131cb0ef41Sopenharmony_ci  getWindowSize: noop
141cb0ef41Sopenharmony_ci};
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ciconst { WriteStream } = require('tty');
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci[
191cb0ef41Sopenharmony_ci  'cursorTo',
201cb0ef41Sopenharmony_ci  'moveCursor',
211cb0ef41Sopenharmony_ci  'clearLine',
221cb0ef41Sopenharmony_ci  'clearScreenDown',
231cb0ef41Sopenharmony_ci].forEach((method) => {
241cb0ef41Sopenharmony_ci  readline[method] = common.mustCall(function() {
251cb0ef41Sopenharmony_ci    const lastArg = arguments[arguments.length - 1];
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci    if (typeof lastArg === 'function') {
281cb0ef41Sopenharmony_ci      process.nextTick(lastArg);
291cb0ef41Sopenharmony_ci    }
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci    return true;
321cb0ef41Sopenharmony_ci  }, 2);
331cb0ef41Sopenharmony_ci});
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ciconst writeStream = new WriteStream(1);
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci// Verify that the corresponding readline methods are called, that the return
381cb0ef41Sopenharmony_ci// values are propagated, and any callbacks are invoked.
391cb0ef41Sopenharmony_ciassert.strictEqual(writeStream.cursorTo(1, 2), true);
401cb0ef41Sopenharmony_ciassert.strictEqual(writeStream.cursorTo(1, 2, common.mustCall()), true);
411cb0ef41Sopenharmony_ciassert.strictEqual(writeStream.moveCursor(1, 2), true);
421cb0ef41Sopenharmony_ciassert.strictEqual(writeStream.moveCursor(1, 2, common.mustCall()), true);
431cb0ef41Sopenharmony_ciassert.strictEqual(writeStream.clearLine(1), true);
441cb0ef41Sopenharmony_ciassert.strictEqual(writeStream.clearLine(1, common.mustCall()), true);
451cb0ef41Sopenharmony_ciassert.strictEqual(writeStream.clearScreenDown(), true);
461cb0ef41Sopenharmony_ciassert.strictEqual(writeStream.clearScreenDown(common.mustCall()), true);
47