Permalink
Browse files

r4414@rimmer: kane | 2007-11-04 18:29:30 +0100

 * up version to 0.18
 * fix parsing regex to deal with options at the beginning of line, without a 'rest'


git-svn-id: http://oss.dwim.org/term-ui@2220 4dccba1d-3c1b-0410-aec4-feb514a8dabc
  • Loading branch information...
1 parent e68774e commit a254a4b579b213f3ef37cb6d67dd29ffca3d985f Jos Boumans committed Nov 4, 2007
Showing with 23 additions and 5 deletions.
  1. +4 −4 lib/Term/UI.pm
  2. +19 −1 t/02_ui.t
View
@@ -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;
View
@@ -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" );
+ }
+}

0 comments on commit a254a4b

Please sign in to comment.