[Bps-public-commit] Config-GitLike branch, master, updated. 3df0a00ef787e9cc52850eeef9258124edd8a8d8

spang at bestpractical.com spang at bestpractical.com
Tue Jun 9 05:17:08 EDT 2009


The branch, master has been updated
       via  3df0a00ef787e9cc52850eeef9258124edd8a8d8 (commit)
       via  c772f2d7a67ebfb8fb857d4f39caddcd7160e5d8 (commit)
       via  773703d0fc9614c12e9a04b59e9245901c4e93bd (commit)
       via  cd0df030aa45ce6fc00e831aa89686906ee92c34 (commit)
       via  1f6198d3f035696ca98818e4753e2d26b5effcab (commit)
      from  aebcc16538e7c736bb6bfb8744b8237983fc884e (commit)

Summary of changes:
 lib/Config/GitLike.pm |  117 +++++++++++++++++----
 t/t1300-repo-config.t |  285 +++++++++++++++++++++---------------------------
 2 files changed, 223 insertions(+), 179 deletions(-)

- Log -----------------------------------------------------------------
commit 1f6198d3f035696ca98818e4753e2d26b5effcab
Author: Christine Spang <spang at mit.edu>
Date:   Mon Jun 8 21:48:18 2009 +0300

    casting on set

diff --git a/lib/Config/GitLike.pm b/lib/Config/GitLike.pm
index b0a5129..e9a9d7d 100644
--- a/lib/Config/GitLike.pm
+++ b/lib/Config/GitLike.pm
@@ -421,13 +421,15 @@ sub define {
     }
 }
 
-=head2 cast( value => 'foo', as => 'int' )
+=head2 cast( value => 'foo', as => 'int', human => 1 )
 
 Return C<value> cast into the type specified by C<as>.
 
 Valid values for C<as> are C<bool>, C<int>, or C<num>. For C<bool>, C<true>,
-C<yes>, C<on>, C<1>, and undef are translated into a true value; anything else
-is false.
+C<yes>, C<on>, C<1>, and undef are translated into a true value (for Perl);
+anything else is false. Specifying a true value for the C<human>
+arg will get you a human-readable 'true' or 'false' rather than a
+value that plays along with Perl's definition of truthiness.
 
 For C<int>s and C<num>s, if C<value> ends in C<k>, C<m>, or C<g>, it will be
 multiplied by 1024, 1048576, and 1073741824, respectively, before being
@@ -444,6 +446,7 @@ sub cast {
     my %args = (
         value => undef,
         as    => undef, # bool, int, or num
+        human => undef, # true value / false value
         @_,
     );
     my $v = $args{value};
@@ -451,9 +454,17 @@ sub cast {
     if ($args{as} =~ /bool/i) {
         return 1 unless defined $v;
         if ( $v =~ /^(?:true|yes|on|-?0*1)$/i ) {
-            return 1;
+            if ( $args{human} ) {
+                return 'true';
+            } else {
+                return 1;
+            }
         } elsif ($v =~ /^(?:false|no|off|0*)$/i) {
-            return 0;
+            if ( $args{human} ) {
+                return 'false';
+            } else {
+                return 0;
+            }
         } else {
             die "Invalid bool $args{value}\n";
         }
@@ -636,17 +647,22 @@ sub format_definition {
     return $ret;
 }
 
-=head2 set( key => "section.foo", value => "bar", filename => File::Spec->catfile(qw/home user/, "." . $config->confname, filter => qr/regex/ )
+=head2 set( key => "section.foo", value => "bar", filename => File::Spec->catfile(qw/home user/, "." . $config->confname, filter => qr/regex/, as => 'bool' )
 
-Sets the key C<foo> in the configuration section C<section> to the value C<bar> in the
-given filename. It's necessary to specify the filename since the C<confname> attribute
-is not unambiguous enough to determine where to write to. (There may be multiple config
-files in different directories which inherit.)
+Sets the key C<foo> in the configuration section C<section> to the value C<bar>
+in the given filename. It's necessary to specify the filename since the
+C<confname> attribute is not unambiguous enough to determine where to write to.
+(There may be multiple config files in different directories which inherit.)
 
 Replaces values if C<key> already exists.
 
 To unset a key, pass in C<key> but not C<value>.
 
+If C<as> is specified as C<bool>, 'true' or 'false' will be written to the
+config file if the given value is a valid bool. If C<int> or C<num> are
+specified, only valid ints or nums will be written. An exception is
+thrown otherwise.
+
 Returns true on success, false if the filename was unopenable and thus no
 set was performed.
 
@@ -662,6 +678,7 @@ sub set {
         value    => undef,
         filename => undef,
         filter   => undef,
+        as       => undef,
         @_
     );
 
@@ -679,6 +696,10 @@ sub set {
 
     die "Invalid key $key\n" if $self->_invalid_key($key);
 
+    $args{value} = $self->cast(value => $args{value}, as => $args{as},
+        human => 1)
+        if defined $args{value} && defined $args{as};
+
     unless (-f $args{filename}) {
         die "No occurrence of $args{key} found to unset in $args{filename}\n"
             unless defined $args{value};
diff --git a/t/t1300-repo-config.t b/t/t1300-repo-config.t
index a06c0fd..e4b99ab 100644
--- a/t/t1300-repo-config.t
+++ b/t/t1300-repo-config.t
@@ -2,7 +2,7 @@ use strict;
 use warnings;
 
 use File::Copy;
-use Test::More tests => 65;
+use Test::More tests => 74;
 use Test::Exception;
 use File::Spec;
 use File::Temp;
@@ -582,7 +582,8 @@ is($config->get( key => 'mega.ton', as => 'int' ), 1048576,
 
 # units that aren't k/m/g should throw an error
 
-$config->set( key => 'aninvalid.unit', value => '1auto', filename => $config_filename );
+$config->set( key => 'aninvalid.unit', value => '1auto', filename =>
+    $config_filename );
 $config->load;
 throws_ok { $config->get( key => 'aninvalid.unit', as => 'int' ) }
     qr/invalid unit/i, 'invalid unit';
@@ -608,9 +609,9 @@ my $b = 1;
 @results = reverse @results;
 while (@results) {
     if ($b) {
-        ok(pop @results, 'bool');
+        ok(pop @results, 'correct true bool from get');
     } else {
-        ok(!pop @results, 'bool');
+        ok(!pop @results, 'correct false bool from get');
     }
     $b = !$b;
 }
@@ -621,67 +622,70 @@ $config->load;
 throws_ok { $config->get( key => 'bool.nobool', as => 'bool' ) }
     qr/invalid bool/i, 'invalid bool (get)';
 
-# TODO currently the interface doesn't support casting for set. does that make sense?
-# test_expect_success 'invalid bool (set)' '
-#
-# 	test_must_fail git config --bool bool.nobool foobar'
-#
-# unlink $config_filename;
-#
-# $expect = <<'EOF'
-# [bool]
-# 	true1 = true
-# 	true2 = true
-# 	true3 = true
-# 	true4 = true
-# 	false1 = false
-# 	false2 = false
-# 	false3 = false
-# 	false4 = false
-# EOF
-#
-# test_expect_success 'set --bool' '
-#
-# 	git config --bool bool.true1 01 &&
-# 	git config --bool bool.true2 -1 &&
-# 	git config --bool bool.true3 YeS &&
-# 	git config --bool bool.true4 true &&
-# 	git config --bool bool.false1 000 &&
-# 	git config --bool bool.false2 "" &&
-# 	git config --bool bool.false3 nO &&
-# 	git config --bool bool.false4 FALSE &&
-# 	cmp expect .git/config'
-#
-# unlink $config_filename;
-#
-# $expect = <<'EOF'
-# [int]
-# 	val1 = 1
-# 	val2 = -1
-# 	val3 = 5242880
-# EOF
-#
+# test casting with set
+throws_ok { $config->set( key => 'bool.nobool', value => 'foobar',
+        as => 'bool', filename => $config_filename ) }
+        qr/invalid bool/i, 'invalid bool (set)';
+
+unlink $config_filename;
+
+for my $key (keys %pairs) {
+    $config->set( key => "bool.$key", value => $pairs{$key},
+        filename => $config_filename, as => 'bool' );
+}
+$config->load;
+
+ at results = ();
+
+for my $i (1..4) {
+    push(@results, $config->get( key => "bool.true$i" ),
+        $config->get( key => "bool.false$i" ));
+}
+
+$b = 1;
+
+ at results = reverse @results;
+while (@results) {
+    if ($b) {
+        is(pop @results, 'true', 'correct true bool from set');
+    } else {
+        is(pop @results, 'false', 'correct false bool from set');
+    }
+    $b = !$b;
+}
+
+unlink $config_filename;
+
+$expect = <<'EOF'
+[int]
+	val1 = 1
+	val2 = -1
+	val3 = 5242880
+EOF
+;
+
 # test_expect_success 'set --int' '
-#
-# 	git config --int int.val1 01 &&
-# 	git config --int int.val2 -1 &&
-# 	git config --int int.val3 5m &&
-# 	cmp expect .git/config'
-#
+
+#     git config --int int.val1 01 &&
+#     git config --int int.val2 -1 &&
+#     git config --int int.val3 5m &&
+#     cmp expect .git/config'
+
 # unlink $config_filename;
-#
+
 # $expect = <<'EOF'
 # [bool]
-# 	true1 = true
-# 	true2 = true
-# 	false1 = false
-# 	false2 = false
+#     true1 = true
+#     true2 = true
+#     false1 = false
+#     false2 = false
 # [int]
-# 	int1 = 0
-# 	int2 = 1
-# 	int3 = -1
+#     int1 = 0
+#     int2 = 1
+#     int3 = -1
 # EOF
-#
+# ;
+
 # TODO interface doesn't support bool-or-int (does it want to?)
 # test_expect_success 'get --bool-or-int' '
 # 	(

commit cd0df030aa45ce6fc00e831aa89686906ee92c34
Author: Christine Spang <spang at mit.edu>
Date:   Mon Jun 8 21:49:08 2009 +0300

    kill commented-out NUL-byte termination tests; we're not going to implement that feature

diff --git a/t/t1300-repo-config.t b/t/t1300-repo-config.t
index e4b99ab..60f315c 100644
--- a/t/t1300-repo-config.t
+++ b/t/t1300-repo-config.t
@@ -779,40 +779,6 @@ EOF
 $config->load;
 is($config->dump, $expect, 'value continued on next line');
 
-# TODO NUL-byte termination is not supported by the current interface and I'm
-# not sure it would be useful to do so
-# burp($config_filename,
-# '[section "sub=section"]
-# 	val1 = foo=bar
-# 	val2 = foo\nbar
-# 	val3 = \n\n
-# 	val4 =
-# 	val5
-# ');
-
-# $expect = <<'EOF'
-# section.sub=section.val1
-# foo=barQsection.sub=section.val2
-# foo
-# barQsection.sub=section.val3
-#
-#
-# Qsection.sub=section.val4
-# Qsection.sub=section.val5Q
-# EOF
-#
-#
-# -- kill the tests or implement the null flag
-#git config --null --list | perl -pe 'y/\000/Q/' > result
-#echo >>result
-#
-#is(slurp($result), $expect, '--null --list');
-#
-#git config --null --get-regexp 'val[0-9]' | perl -pe 'y/\000/Q/' > result
-#echo >>result
-#
-#is(slurp($result), $expect, '--null --get-regexp');
-
 # testing symlinked configuration
 symlink File::Spec->catfile($config_dir, 'notyet'),
     File::Spec->catfile($config_dir, 'myconfig');

commit 773703d0fc9614c12e9a04b59e9245901c4e93bd
Author: Christine Spang <spang at mit.edu>
Date:   Mon Jun 8 22:04:53 2009 +0300

    int casting on set

diff --git a/lib/Config/GitLike.pm b/lib/Config/GitLike.pm
index e9a9d7d..d1a9d0f 100644
--- a/lib/Config/GitLike.pm
+++ b/lib/Config/GitLike.pm
@@ -470,7 +470,7 @@ sub cast {
         }
     } elsif ($args{as} =~ /int|num/) {
         die "Invalid unit while casting to $args{as}\n"
-            unless $v =~ /^[0-9]*\.?[0-9]*[kmg]?$/;
+            unless $v =~ /^-?[0-9]*\.?[0-9]*[kmg]?$/;
 
         if ($v =~ s/([kmg])$//) {
             $v *= 1024 if $1 eq "k";
diff --git a/t/t1300-repo-config.t b/t/t1300-repo-config.t
index 60f315c..1a61548 100644
--- a/t/t1300-repo-config.t
+++ b/t/t1300-repo-config.t
@@ -664,14 +664,16 @@ $expect = <<'EOF'
 EOF
 ;
 
-# test_expect_success 'set --int' '
+$config->set( key => 'int.val1', value => '01', filename => $config_filename,
+    as => 'int' );
+$config->set( key => 'int.val2', value => '-1', filename => $config_filename,
+    as => 'int' );
+$config->set( key => 'int.val3', value => '5m', filename => $config_filename,
+    as => 'int' );
 
-#     git config --int int.val1 01 &&
-#     git config --int int.val2 -1 &&
-#     git config --int int.val3 5m &&
-#     cmp expect .git/config'
+is(slurp($config_filename), $expect, 'set --int');
 
-# unlink $config_filename;
+unlink $config_filename;
 
 # $expect = <<'EOF'
 # [bool]

commit c772f2d7a67ebfb8fb857d4f39caddcd7160e5d8
Author: Christine Spang <spang at mit.edu>
Date:   Tue Jun 9 10:44:50 2009 +0300

    bool-or-int

diff --git a/lib/Config/GitLike.pm b/lib/Config/GitLike.pm
index d1a9d0f..f135ccf 100644
--- a/lib/Config/GitLike.pm
+++ b/lib/Config/GitLike.pm
@@ -425,22 +425,31 @@ sub define {
 
 Return C<value> cast into the type specified by C<as>.
 
-Valid values for C<as> are C<bool>, C<int>, or C<num>. For C<bool>, C<true>,
-C<yes>, C<on>, C<1>, and undef are translated into a true value (for Perl);
-anything else is false. Specifying a true value for the C<human>
-arg will get you a human-readable 'true' or 'false' rather than a
+Valid values for C<as> are C<bool>, C<int>, C<num>, or C<bool-or-int>. For
+C<bool>, C<true>, C<yes>, C<on>, C<1>, and undef are translated into a true
+value (for Perl); anything else is false. Specifying a true value for the
+C<human> arg will get you a human-readable 'true' or 'false' rather than a
 value that plays along with Perl's definition of truthiness.
 
 For C<int>s and C<num>s, if C<value> ends in C<k>, C<m>, or C<g>, it will be
 multiplied by 1024, 1048576, and 1073741824, respectively, before being
 returned.
 
+C<bool-or-int>, as you might have guessed, gives you either
+a bool or an int depending on which one applies.
+
 TODO should numbers be truncated if C<int> is specified?
 
 If C<as> is unspecified, C<value> is returned unchanged.
 
 =cut
 
+use constant {
+    BOOL_TRUE_REGEX => qr/^(?:true|yes|on|-?0*1)$/i,
+    BOOL_FALSE_REGEX => qr/^(?:false|no|off|0*)$/i,
+    NUM_REGEX => qr/^-?[0-9]*\.?[0-9]*[kmg]?$/,
+};
+
 sub cast {
     my $self = shift;
     my %args = (
@@ -449,28 +458,42 @@ sub cast {
         human => undef, # true value / false value
         @_,
     );
+
+    if (defined $args{as} && $args{as} eq 'bool-or-int') {
+        if ( $args{value} =~ NUM_REGEX ) {
+            $args{as} = 'int';
+        } elsif ( $args{value} =~ BOOL_TRUE_REGEX ||
+            $args{value} =~ BOOL_FALSE_REGEX ) {
+            $args{as} = 'bool';
+        } elsif ( !defined $args{value} ) {
+            $args{as} = 'bool';
+        } else {
+            die "Invalid bool-or-int '$args{value}'\n";
+        }
+    }
+
     my $v = $args{value};
     return $v unless defined $args{as};
     if ($args{as} =~ /bool/i) {
         return 1 unless defined $v;
-        if ( $v =~ /^(?:true|yes|on|-?0*1)$/i ) {
+        if ( $v =~  BOOL_TRUE_REGEX ) {
             if ( $args{human} ) {
                 return 'true';
             } else {
                 return 1;
             }
-        } elsif ($v =~ /^(?:false|no|off|0*)$/i) {
+        } elsif ($v =~ BOOL_FALSE_REGEX ) {
             if ( $args{human} ) {
                 return 'false';
             } else {
                 return 0;
             }
         } else {
-            die "Invalid bool $args{value}\n";
+            die "Invalid bool '$args{value}'\n";
         }
     } elsif ($args{as} =~ /int|num/) {
         die "Invalid unit while casting to $args{as}\n"
-            unless $v =~ /^-?[0-9]*\.?[0-9]*[kmg]?$/;
+            unless $v =~ NUM_REGEX;
 
         if ($v =~ s/([kmg])$//) {
             $v *= 1024 if $1 eq "k";
@@ -510,6 +533,7 @@ sub get {
     my %args = (
         key => undef,
         as  => undef,
+        human  => undef,
         @_,
     );
     $self->load unless $self->is_loaded;
@@ -521,7 +545,8 @@ sub get {
     if (ref $v) {
         die "Multiple values";
     } else {
-        return $self->cast( value => $v, as => $args{as} );
+        return $self->cast( value => $v, as => $args{as},
+            human => $args{human} );
     }
 }
 
diff --git a/t/t1300-repo-config.t b/t/t1300-repo-config.t
index 1a61548..982ab93 100644
--- a/t/t1300-repo-config.t
+++ b/t/t1300-repo-config.t
@@ -2,7 +2,7 @@ use strict;
 use warnings;
 
 use File::Copy;
-use Test::More tests => 74;
+use Test::More tests => 83;
 use Test::Exception;
 use File::Spec;
 use File::Temp;
@@ -675,63 +675,58 @@ is(slurp($config_filename), $expect, 'set --int');
 
 unlink $config_filename;
 
-# $expect = <<'EOF'
-# [bool]
-#     true1 = true
-#     true2 = true
-#     false1 = false
-#     false2 = false
-# [int]
-#     int1 = 0
-#     int2 = 1
-#     int3 = -1
-# EOF
-# ;
-
-# TODO interface doesn't support bool-or-int (does it want to?)
-# test_expect_success 'get --bool-or-int' '
-# 	(
-# 		echo "[bool]"
-# 		echo true1
-# 		echo true2 = true
-# 		echo false = false
-# 		echo "[int]"
-# 		echo int1 = 0
-# 		echo int2 = 1
-# 		echo int3 = -1
-# 	) >>.git/config &&
-# 	test $(git config --bool-or-int bool.true1) = true &&
-# 	test $(git config --bool-or-int bool.true2) = true &&
-# 	test $(git config --bool-or-int bool.false) = false &&
-# 	test $(git config --bool-or-int int.int1) = 0 &&
-# 	test $(git config --bool-or-int int.int2) = 1 &&
-# 	test $(git config --bool-or-int int.int3) = -1
-#
-# '
-#
-# unlink $config_filename;
-# $expect = <<'EOF'
-# [bool]
-# 	true1 = true
-# 	false1 = false
-# 	true2 = true
-# 	false2 = false
-# [int]
-# 	int1 = 0
-# 	int2 = 1
-# 	int3 = -1
-# EOF
-#
-# test_expect_success 'set --bool-or-int' '
-# 	git config --bool-or-int bool.true1 true &&
-# 	git config --bool-or-int bool.false1 false &&
-# 	git config --bool-or-int bool.true2 yes &&
-# 	git config --bool-or-int bool.false2 no &&
-# 	git config --bool-or-int int.int1 0 &&
-# 	git config --bool-or-int int.int2 1 &&
-# 	git config --bool-or-int int.int3 -1 &&
-# 	test_cmp expect .git/config
-# '
+burp($config_filename,
+'[bool]
+    true1 = on
+    true2 = yes
+    false1 = off
+    false2 = no
+[int]
+    int1 = 00
+    int2 = 01
+    int3 = -01
+');
+
+$config->load;
+is($config->get( key => 'bool.true1', as => 'bool-or-int', human => 1 ),
+    'true', 'get bool-or-int');
+is($config->get( key => 'bool.true2', as => 'bool-or-int', human => 1 ),
+    'true', 'get bool-or-int');
+is($config->get( key => 'bool.false1', as => 'bool-or-int', human => 1 ),
+    'false', 'get bool-or-int');
+is($config->get( key => 'bool.false2', as => 'bool-or-int', human => 1 ),
+    'false', 'get bool-or-int');
+is($config->get( key => 'int.int1', as => 'bool-or-int' ), 0,
+    'get bool-or-int');
+is($config->get( key => 'int.int2', as => 'bool-or-int' ), 1,
+    'get bool-or-int');
+is($config->get( key => 'int.int3', as => 'bool-or-int' ), -1,
+    'get bool-or-int');
+
+unlink $config_filename;
+
+$expect = <<'EOF'
+[bool]
+	true1 = true
+	false1 = false
+	true2 = true
+	false2 = false
+[int]
+	int1 = 0
+	int2 = 1
+	int3 = -1
+EOF
+;
+
+$config->set( key => 'bool.true1', value => 'true', as => 'bool-or-int', filename => $config_filename );
+$config->set( key => 'bool.false1', value => 'false', as => 'bool-or-int', filename => $config_filename );
+$config->set( key => 'bool.true2', value => 'yes', as => 'bool-or-int', filename => $config_filename );
+$config->set( key => 'bool.false2', value => 'no', as => 'bool-or-int', filename => $config_filename );
+$config->set( key => 'int.int1', value => '0', as => 'bool-or-int', filename => $config_filename );
+$config->set( key => 'int.int2', value => '1', as => 'bool-or-int', filename => $config_filename );
+$config->set( key => 'int.int3', value => '-1', as => 'bool-or-int', filename => $config_filename );
+
+is(slurp($config_filename), $expect, 'set bool-or-int');
 
 unlink $config_filename;
 

commit 3df0a00ef787e9cc52850eeef9258124edd8a8d8
Author: Christine Spang <spang at mit.edu>
Date:   Tue Jun 9 12:14:59 2009 +0300

    get_regexp (didn't implement this in ->get after all since it needs to return something completely different)

diff --git a/lib/Config/GitLike.pm b/lib/Config/GitLike.pm
index f135ccf..6cc592c 100644
--- a/lib/Config/GitLike.pm
+++ b/lib/Config/GitLike.pm
@@ -538,7 +538,7 @@ sub get {
     );
     $self->load unless $self->is_loaded;
 
-    $args{key} = $self->_remove_balanced_quotes($args{key});
+    $args{key} = lc $self->_remove_balanced_quotes($args{key});
 
     return undef unless exists $self->data->{$args{key}};
     my $v = $self->data->{$args{key}};
@@ -583,12 +583,45 @@ sub get_all {
         @_,
     );
     $self->load unless $self->is_loaded;
-    $args{key} = $self->_remove_balanced_quotes($args{key});
+    $args{key} = lc $self->_remove_balanced_quotes($args{key});
 
     return undef unless exists $self->data->{$args{key}};
     my $v = $self->data->{$args{key}};
     my @v = ref $v ? @{$v} : ($v);
-    return map {$self->cast( value => $v, as => $args{as} )} @v;
+    return map {$self->cast( value => $_, as => $args{as} )} @v;
+}
+
+=head2 get_regexp( key => 'regex', filter => 'regex', as => 'bool' )
+
+Similar to C<get_all>, but searches for values based on a key regex.
+
+Returns a hash of name/value pairs, with values cast as C<as> if C<as> is
+specified.
+
+TODO implement filter
+
+=cut
+
+sub get_regexp {
+    my $self = shift;
+
+    my %args = (
+        key => undef,
+        as  => undef,
+        @_,
+    );
+
+    $self->load unless $self->is_loaded;
+
+    $args{key} = lc $args{key};
+
+    my %results;
+    for my $key (keys %{$self->data}) {
+        $results{$key} = $self->data->{$key}
+            if lc $key =~ $args{key};
+    }
+    return map { ($_, $self->cast( value => $results{$_}, as => $args{as} )) }
+        keys %results;
 }
 
 =head2 dump
diff --git a/t/t1300-repo-config.t b/t/t1300-repo-config.t
index 982ab93..bf8b02b 100644
--- a/t/t1300-repo-config.t
+++ b/t/t1300-repo-config.t
@@ -373,18 +373,14 @@ EOF
 $config->load;
 is($config->dump, $expect, 'working dump');
 
-# TODO perhaps regexps could just be supported by the get interface
-TODO: {
-    local $TODO = 'get_regexp is not implemented';
+$expect = {'beta.noindent', 'sillyValue', 'nextsection.nonewline',
+    'wow2 for me'};
 
-    $expect = <<'EOF'
-beta.noindent sillyValue
-nextsection.nonewline wow2 for me
-EOF
-    ;
+# test get_regexp
 
-    lives_and { is($config->get_regexp( 'in' ), $expect) } '--get-regexp';
-}
+my %results = $config->get_regexp( key => 'in' );
+
+lives_and { is_deeply(\%results, $expect) } '--get-regexp';
 
 TODO: {
     local $TODO = 'cannot set multiple values yet';
@@ -416,15 +412,17 @@ lives_and { is($config->get( key => 'novalue.variable', filter => qr/^$/ ),
 lives_and { is($config->get( key => 'emptyvalue.variable', filter => qr/^$/ ),
     '') } 'get variable with empty value';
 
-TODO: {
-    local $TODO = "get_regexp is not implemented";
+# more get_regexp
 
-    lives_and { is($config->get_regexp( qr/novalue/ ), '') }
-        'get_regexp variable with no value';
+%results = $config->get_regexp( key => 'novalue' );
+lives_and { is_deeply(\%results, { 'novalue.variable' => undef } ) }
+    'get_regexp variable with no value';
 
-    lives_and { is($config->get_regexp( qr/novalue/ ), '') }
-        'get_regexp variable with empty value';
-}
+%results = $config->get_regexp( key => qr/emptyvalue/ );
+lives_and { is_deeply(\%results, { 'emptyvalue.variable' => '' } ) }
+    'get_regexp variable with empty value';
+
+# TODO: test get_regexp with casting
 
 # should evaluate to a true value
 ok($config->get( key => 'novalue.variable', as => 'bool' ),

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list