Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit a254a4b579b213f3ef37cb6d67dd29ffca3d985f 1 parent e68774e
Jos Boumans authored

Showing 2 changed files with 23 additions and 5 deletions. Show diff stats Hide diff stats

  1. +4 4 lib/Term/UI.pm
  2. +19 1 t/02_ui.t
8 lib/Term/UI.pm
@@ -11,7 +11,7 @@ use strict;
11 11 BEGIN {
12 12 use vars qw[$VERSION $AUTOREPLY $VERBOSE $INVALID];
13 13 $VERBOSE = 1;
14   - $VERSION = '0.16';
  14 + $VERSION = '0.18';
15 15 $INVALID = loc('Invalid selection, please try again: ');
16 16 }
17 17
@@ -404,9 +404,9 @@ sub parse_options {
404 404 my $return = {};
405 405
406 406 ### there's probably a more elegant way to do this... ###
407   - while ( $input =~ s/(?:\s+)--?([-\w]+=("|').+?\2)(?=\Z|\s+)// or
408   - $input =~ s/(?:\s+)--?([-\w]+=\S+)(?=\Z|\s+)// or
409   - $input =~ s/(?:\s+)--?([-\w]+)(?=\Z|\s+)//
  407 + while ( $input =~ s/(?:^|\s+)--?([-\w]+=("|').+?\2)(?=\Z|\s+)// or
  408 + $input =~ s/(?:^|\s+)--?([-\w]+=\S+)(?=\Z|\s+)// or
  409 + $input =~ s/(?:^|\s+)--?([-\w]+)(?=\Z|\s+)//
410 410 ) {
411 411 my $match = $1;
412 412
20 t/02_ui.t
@@ -2,7 +2,7 @@
2 2
3 3 use strict;
4 4 use lib qw[../lib lib];
5   -use Test::More tests => 13;
  5 +use Test::More tests => 19;
6 6 use Term::ReadLine;
7 7
8 8 use_ok( 'Term::UI' );
@@ -124,3 +124,21 @@ my $tmpl = {
124 124 is_deeply($href, $expected, qq[Parsing options] );
125 125 is($rest, $munged, qq[Remaining unparsed string '$munged'] );
126 126 }
  127 +
  128 +### more parse_options tests
  129 +{ my @map = (
  130 + [ 'x --update_source' => 'x', { update_source => 1 } ],
  131 + [ '--update_source' => '', { update_source => 1 } ],
  132 + );
  133 +
  134 + for my $aref ( @map ) {
  135 + my( $input, $munged, $expect ) = @$aref;
  136 +
  137 + my($href,$rest) = $term->parse_options( $input );
  138 +
  139 + ok( $href, "Parsed '$input'" );
  140 + is_deeply( $href, $expect,
  141 + " Options parsed correctly" );
  142 + is( $rest, $munged, " Command parsed correctly" );
  143 + }
  144 +}

0 comments on commit a254a4b

Please sign in to comment.
Something went wrong with that request. Please try again.