summaryrefslogtreecommitdiff
path: root/lib/Term
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Term')
-rw-r--r--lib/Term/UI.pm8
-rw-r--r--lib/Term/UI/t/02_ui.t20
2 files changed, 23 insertions, 5 deletions
diff --git a/lib/Term/UI.pm b/lib/Term/UI.pm
index c7cd4cd5b1..4b20faad9c 100644
--- a/lib/Term/UI.pm
+++ b/lib/Term/UI.pm
@@ -11,7 +11,7 @@ use strict;
BEGIN {
use vars qw[$VERSION $AUTOREPLY $VERBOSE $INVALID];
$VERBOSE = 1;
- $VERSION = '0.16';
+ $VERSION = '0.18';
$INVALID = loc('Invalid selection, please try again: ');
}
@@ -404,9 +404,9 @@ sub parse_options {
my $return = {};
### there's probably a more elegant way to do this... ###
- while ( $input =~ s/(?:\s+)--?([-\w]+=("|').+?\2)(?=\Z|\s+)// or
- $input =~ s/(?:\s+)--?([-\w]+=\S+)(?=\Z|\s+)// or
- $input =~ s/(?:\s+)--?([-\w]+)(?=\Z|\s+)//
+ while ( $input =~ s/(?:^|\s+)--?([-\w]+=("|').+?\2)(?=\Z|\s+)// or
+ $input =~ s/(?:^|\s+)--?([-\w]+=\S+)(?=\Z|\s+)// or
+ $input =~ s/(?:^|\s+)--?([-\w]+)(?=\Z|\s+)//
) {
my $match = $1;
diff --git a/lib/Term/UI/t/02_ui.t b/lib/Term/UI/t/02_ui.t
index 874ffc8d5b..6e0b34ae32 100644
--- a/lib/Term/UI/t/02_ui.t
+++ b/lib/Term/UI/t/02_ui.t
@@ -2,7 +2,7 @@
use strict;
use lib qw[../lib lib];
-use Test::More tests => 13;
+use Test::More tests => 19;
use Term::ReadLine;
use_ok( 'Term::UI' );
@@ -124,3 +124,21 @@ my $tmpl = {
is_deeply($href, $expected, qq[Parsing options] );
is($rest, $munged, qq[Remaining unparsed string '$munged'] );
}
+
+### more parse_options tests
+{ my @map = (
+ [ 'x --update_source' => 'x', { update_source => 1 } ],
+ [ '--update_source' => '', { update_source => 1 } ],
+ );
+
+ for my $aref ( @map ) {
+ my( $input, $munged, $expect ) = @$aref;
+
+ my($href,$rest) = $term->parse_options( $input );
+
+ ok( $href, "Parsed '$input'" );
+ is_deeply( $href, $expect,
+ " Options parsed correctly" );
+ is( $rest, $munged, " Command parsed correctly" );
+ }
+}