[Bps-public-commit] r14516 - in Prophet/trunk: . t

sartak at bestpractical.com sartak at bestpractical.com
Fri Jul 25 07:04:24 EDT 2008


Author: sartak
Date: Fri Jul 25 07:04:24 2008
New Revision: 14516

Modified:
   Prophet/trunk/   (props changed)
   Prophet/trunk/lib/Prophet/CLI.pm
   Prophet/trunk/t/search.t

Log:
 r65203 at onn:  sartak | 2008-07-25 06:44:54 -0400
 First pass at making "summary =~ foo" work


Modified: Prophet/trunk/lib/Prophet/CLI.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI.pm	(original)
+++ Prophet/trunk/lib/Prophet/CLI.pm	Fri Jul 25 07:04:24 2008
@@ -186,6 +186,8 @@
 
 =cut
 
+sub cmp_regex { '!=|<>|=~|!~|=|\bne\b' }
+
 sub parse_args {
     my $self = shift;
 
@@ -199,6 +201,7 @@
     );
 
     $self->primary_commands( \@primary );
+    my $cmp_re = $self->cmp_regex;
 
     while (my $name = shift @ARGV) {
         die "$name doesn't look like --argument"
@@ -213,13 +216,22 @@
         my $val;
 
         ($name, $cmp, $val) = ($1, $2, $3)
-            if $name =~ /^(.*?)(!=|<>|=~|!~|=)(.*)$/;
+            if $name =~ /^(.*?)($cmp_re)(.*)$/;
         $name =~ s/^--//;
 
         # no value specified, pull it from the next argument, unless the next
         # argument is another option
-        $val = shift @ARGV
-            if !defined($val) && @ARGV && $ARGV[0] !~ /^--/;
+        if (!defined($val)) {
+            $val = shift @ARGV
+                if @ARGV && $ARGV[0] !~ /^--/;
+
+            # but wait! does the value look enough like a comparator? if so,
+            # shift off another one (if we can)
+            if ($val =~ /^(?:$cmp_re)$/ && @ARGV && $ARGV[0] !~ /^--/) {
+                $cmp = $val;
+                $val = shift @ARGV;
+            }
+        }
 
         if ($sep == 1) {
             $self->add_to_prop_set({

Modified: Prophet/trunk/t/search.t
==============================================================================
--- Prophet/trunk/t/search.t	(original)
+++ Prophet/trunk/t/search.t	Fri Jul 25 07:04:24 2008
@@ -1,12 +1,12 @@
 #!/usr/bin/env perl
 use strict;
 use warnings;
-use Prophet::Test tests => 13;
+use Prophet::Test tests => 14;
 
 as_alice {
     run_ok('prophet', [qw(create --type=Bug --), 'summary=first ticket summary', 'status=new'], "created a record as alice");
     run_ok('prophet', [qw(create --type=Bug --), 'summary=other ticket summary', 'status=open'], "created a record as alice");
-    run_ok('prophet', [qw(create --type=Bug --), 'summary=bad ticket summary', 'status=stalled'], "created a record as alice");
+    run_ok('prophet', [qw(create --type=Bug --), 'summary=bad ticket summary', 'status=stalled', 'cmp=ne'], "created a record as alice");
 
     run_output_matches('prophet', [qw(search --type Bug --regex .)],
         [qr/first ticket summary/,
@@ -60,10 +60,15 @@
 
     TODO: {
         local $TODO = "regex comparisons not implemented yet";
-        run_output_matches('prophet', [qw(search --type Bug -- status != new summary =~ first|bad)],
+        run_output_matches('prophet', [qw(search --type Bug -- status ne new summary =~ first|bad)],
             [qr/bad ticket summary/],
             "found two tickets with status=~first|bad",
         );
     };
+
+    run_output_matches('prophet', [qw(search --type Bug -- cmp ne)],
+        [qr/bad ticket summary/],
+        "found the ticket with cmp=ne (which didn't treat 'ne' as a comparator)",
+    );
 };
 



More information about the Bps-public-commit mailing list