![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /usr/local/lib/node_modules/forever/node_modules/prompt/test/ |
Upload File : |
/* * helpers.js: test helpers for the prompt tests. * * (C) 2010, Nodejitsu Inc. * */ var stream = require('stream'), util = require('util'), prompt = require('../lib/prompt'); var helpers = exports; var MockReadWriteStream = helpers.MockReadWriteStream = function () { // // No need to do anything here, it's just a mock. // var self = this; this.on('pipe', function (src) { var _emit = src.emit; src.emit = function () { //console.dir(arguments); _emit.apply(src, arguments); }; src.on('data', function (d) { self.emit('data', d + ''); }) }) }; util.inherits(MockReadWriteStream, stream.Stream); ['resume', 'pause', 'setEncoding', 'flush', 'end'].forEach(function (method) { MockReadWriteStream.prototype[method] = function () { /* Mock */ }; }); MockReadWriteStream.prototype.write = function (msg) { this.emit('data', msg); return true; }; MockReadWriteStream.prototype.writeNextTick = function (msg) { var self = this process.nextTick(function () { self.write(msg); }); }; // // Create some mock streams for asserting against // in our prompt teSts. // helpers.stdin = new MockReadWriteStream(); helpers.stdout = new MockReadWriteStream(); helpers.stderr = new MockReadWriteStream(); // // Because `read` uses a `process.nextTick` for reading from // stdin, it is necessary to write sequences of input with extra // `process.nextTick` calls // helpers.stdin.writeSequence = function (lines) { if (!lines || !lines.length) { return; } helpers.stdin.writeNextTick(lines.shift()); prompt.once('prompt', function () { process.nextTick(function () { helpers.stdin.writeSequence(lines); }); }); } // // Monkey punch `util.error` to silence console output // and redirect to helpers.stderr for testing. // process.stderr.write = function () { helpers.stderr.write.apply(helpers.stderr, arguments); } // 1) .properties // 2) warning --> message // 3) Name --> description || key // 4) validator --> conform (fxns), pattern (regexp), format (built-in) // 5) empty --> required helpers.schema = { properties: { oldschema: { message: 'Enter your username', validator: /^[\w|\-]+$/, warning: 'username can only be letters, numbers, and dashes', empty: false }, riffwabbles: { pattern: /^[\w|\-]+$/, message: 'riffwabbles can only be letters, numbers, and dashes', default: 'foobizzles' }, number: { type: 'number', message: 'pick a number, any number', default: 10 }, username: { pattern: /^[\w|\-]+$/, message: 'Username can only be letters, numbers, and dashes' }, notblank: { required: true }, password: { hidden: true, required: true }, badValidator: { pattern: ['cant', 'use', 'array'] }, animal: { description: 'Enter an animal', default: 'dog', pattern: /dog|cat/ }, sound: { description: 'What sound does this animal make?', conform: function (value) { var animal = prompt.history(0).value; return animal === 'dog' && value === 'woof' || animal === 'cat' && value === 'meow'; } }, fnvalidator: { name: 'fnvalidator', validator: function (line) { return line.slice(0,2) == 'fn'; }, message: 'fnvalidator must start with "fn"' }, fnconform: { conform: function (line) { return line.slice(0,2) == 'fn'; }, message: 'fnconform must start with "fn"' }/*, cbvalidator: { conform: function (line, next) { next(line.slice(0,2) == 'cb'); }, message: 'cbvalidator must start with "cb"' }*/ } };