Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
more prompt tests
  • Loading branch information
kraih committed Oct 15, 2012
1 parent e0d45df commit 100ecda
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Changes
Expand Up @@ -3,7 +3,7 @@
- Added prompt method to Mojo::ByteStream.
- Added prompt function to Mojo::Util.
- Improved Mojo::Content performance slightly.
- Improved cpanify command to prompt for password if necessary.
- Improved cpanify command to prompt for password if necessary. (jberger)
- Fixed memory leak in Mojo::Headers.

3.47 2012-10-13
Expand Down
2 changes: 2 additions & 0 deletions lib/Mojo/ByteStream.pm
Expand Up @@ -216,6 +216,8 @@ Generate MD5 checksum for bytestream with L<Mojo::Util/"md5_sum">.
Prompt user with L<Mojo::Util/"prompt">.
b('Password: ')->prompt->xor_encode('s3cret')->say;
=head2 C<punycode_decode>
$stream = $stream->punycode_decode;
Expand Down
5 changes: 3 additions & 2 deletions lib/Mojo/Util.pm
Expand Up @@ -537,8 +537,9 @@ Generate MD5 checksum for string.
my $string = prompt 'Password: ';
Print string to C<STDOUT>, wait for user to type something and finish with an
C<ENTER> and return the string typed in wihout the trailing newline.
Print string to C<STDOUT>, wait for user to type something on C<STDIN> and
finish with an C<ENTER>, then return the string typed in wihout the trailing
newline.
=head2 C<punycode_decode>
Expand Down
23 changes: 19 additions & 4 deletions t/mojo/util.t
Expand Up @@ -2,7 +2,7 @@ use Mojo::Base -strict;

use utf8;

use Test::More tests => 154;
use Test::More tests => 156;

use File::Spec::Functions qw(catfile splitdir);
use File::Temp 'tempdir';
Expand All @@ -11,9 +11,9 @@ use FindBin;
use Mojo::Util
qw(b64_decode b64_encode camelize class_to_file class_to_path decamelize),
qw(decode encode get_line hmac_md5_sum hmac_sha1_sum html_escape),
qw(html_unescape md5_bytes md5_sum punycode_decode punycode_encode quote),
qw(squish trim unquote secure_compare sha1_bytes sha1_sum slurp spurt),
qw(url_escape url_unescape xml_escape xor_encode);
qw(html_unescape md5_bytes md5_sum prompt punycode_decode punycode_encode),
qw(quote squish trim unquote secure_compare sha1_bytes sha1_sum slurp),
qw(spurt url_escape url_unescape xml_escape xor_encode);

# camelize
is camelize('foo_bar_baz'), 'FooBarBaz', 'right camelized result';
Expand Down Expand Up @@ -376,6 +376,21 @@ is xor_encode("\x10\x1d\x14\x14\x17\x58\x0f\x17\x0a\x14\x1c", 'x'),
is xor_encode('hello', '123456789'), "\x59\x57\x5f\x58\x5a", 'right result';
is xor_encode("\x59\x57\x5f\x58\x5a", '123456789'), 'hello', 'right result';

# prompt
my $input = "test123\n";
open my $in, '<', \$input;
my $output = '';
open my $out, '>', \$output;
my $stdin = *STDIN;
*STDIN = $in;
my $stdout = *STDOUT;
*STDOUT = $out;
my $string = prompt 'Password: ';
*STDIN = $stdin;
*STDOUT = $stdout;
is $output, 'Password: ', 'right output';
is $string, 'test123', 'right input';

# slurp
is slurp(catfile(splitdir($FindBin::Bin), qw(templates exception.mt))),
"test\n% die;\n123\n", 'right content';
Expand Down

0 comments on commit 100ecda

Please sign in to comment.