diff options
author | isaacs <i@izs.me> | 2012-07-13 11:40:38 -0700 |
---|---|---|
committer | isaacs <i@izs.me> | 2012-07-13 12:08:17 -0700 |
commit | 9d4362403c10dd28b5644b947945f853cd354f28 (patch) | |
tree | c08bf8dd199ee4231a28bd2bb7d5e93c80b43123 /deps/npm/node_modules/read | |
parent | acbfc408880a12c32ccc9d69bca91aad4e93e879 (diff) | |
download | node-new-9d4362403c10dd28b5644b947945f853cd354f28.tar.gz |
npm: upgrade to 1.1.41
Diffstat (limited to 'deps/npm/node_modules/read')
-rw-r--r-- | deps/npm/node_modules/read/example/example.js | 18 | ||||
-rw-r--r-- | deps/npm/node_modules/read/test/basic.js | 54 |
2 files changed, 72 insertions, 0 deletions
diff --git a/deps/npm/node_modules/read/example/example.js b/deps/npm/node_modules/read/example/example.js new file mode 100644 index 0000000000..6800dff65e --- /dev/null +++ b/deps/npm/node_modules/read/example/example.js @@ -0,0 +1,18 @@ +var read = require("../lib/read.js") + +read({prompt: "Username: ", default: "test-user" }, function (er, user) { + read({prompt: "Password: ", default: "test-pass", silent: true }, function (er, pass) { + read({prompt: "Enter 4 characters: ", num: 4 }, function (er, four) { + read({prompt: "Password again: ", default: "test-pass", silent: true }, function (er, pass2) { + console.error({user: user, + pass: pass, + verify: pass2, + four:four, + passMatch: (pass === pass2)}) + console.error("If the program doesn't end right now,\n" + +"then you may be experiencing this bug:\n" + +"https://github.com/joyent/node/issues/2257") + }) + }) + }) +}) diff --git a/deps/npm/node_modules/read/test/basic.js b/deps/npm/node_modules/read/test/basic.js new file mode 100644 index 0000000000..7f195362af --- /dev/null +++ b/deps/npm/node_modules/read/test/basic.js @@ -0,0 +1,54 @@ +var tap = require('tap') +var read = require('../lib/read.js') + +if (process.argv[2] === 'child') { + return child() +} + +var spawn = require('child_process').spawn + +tap.test('basic', function (t) { + var child = spawn(process.execPath, [__filename, 'child']) + var output = '' + child.stdout.on('data', function (c) { + console.error('data %s', c) + output += c + if (output.match(/Username: \(test-user\) $/)) { + child.stdin.write('a user\n') + } else if (output.match(/Password: \(<default hidden>\) $/)) { + child.stdin.write('a password\n') + } else if (output.match(/characters: $/)) { + child.stdin.write('asdf\n') + } else if (output.match(/Password again: \(<default hidden>\) $/)) { + child.stdin.write('a password\n') + } + }) + + var result = '' + child.stderr.on('data', function (c) { + result += c + }) + + child.on('close', function () { + result = JSON.parse(result) + t.same(result, {"user":"a user","pass":"a password","verify":"a password","four":"asdf","passMatch":true}) + t.equal(output, 'Username: (test-user) Password: (<default hidden>) Enter 4 characters: Password again: (<default hidden>) ') + t.end() + }) +}) + +function child () { + read({prompt: "Username: ", default: "test-user" }, function (er, user) { + read({prompt: "Password: ", default: "test-pass", silent: true }, function (er, pass) { + read({prompt: "Enter 4 characters: ", num: 4 }, function (er, four) { + read({prompt: "Password again: ", default: "test-pass", silent: true }, function (er, pass2) { + console.error(JSON.stringify({user: user, + pass: pass, + verify: pass2, + four:four, + passMatch: (pass === pass2)})) + }) + }) + }) + }) +} |