diff options
author | Olivier Thauvin <nanardon@mandriva.org> | 2006-08-18 14:09:44 +0000 |
---|---|---|
committer | Olivier Thauvin <nanardon@mandriva.org> | 2006-08-18 14:09:44 +0000 |
commit | 50bf20203670b3b3a1fd050c588231761f588c5b (patch) | |
tree | d0d8af8038b1acf6d78e7dde52b626d18378847b | |
parent | 43f19b38993c3f57cebaff4cc10425900f7d5246 (diff) | |
download | perl-MDV-Distribconf-50bf20203670b3b3a1fd050c588231761f588c5b.tar perl-MDV-Distribconf-50bf20203670b3b3a1fd050c588231761f588c5b.tar.gz perl-MDV-Distribconf-50bf20203670b3b3a1fd050c588231761f588c5b.tar.bz2 perl-MDV-Distribconf-50bf20203670b3b3a1fd050c588231761f588c5b.tar.xz perl-MDV-Distribconf-50bf20203670b3b3a1fd050c588231761f588c5b.zip |
- more test, provide basic functions
-rw-r--r-- | lib/MDV/Distribconf/MediaCFG.pm | 32 | ||||
-rw-r--r-- | t/03mediacfg.t | 13 |
2 files changed, 41 insertions, 4 deletions
diff --git a/lib/MDV/Distribconf/MediaCFG.pm b/lib/MDV/Distribconf/MediaCFG.pm index 46b3dc5..0566f3c 100644 --- a/lib/MDV/Distribconf/MediaCFG.pm +++ b/lib/MDV/Distribconf/MediaCFG.pm @@ -117,7 +117,21 @@ added to the config (urpmi). =cut -$value->{size} = {}; +$value->{size} = { + validation => sub { + my ($v) = @_; + if ($v =~ /^(\d+)(\w)?$/) { + if ($2) { + if (! grep { lc($2) eq $_ } qw(k m g t p)) { + return("wrong unit"); + } + } + return; + } else { + return ("malformed value"); + } + }, +}; =head3 size @@ -125,7 +139,11 @@ The size of the media. The value is suffixed by the unit. =cut -sub valid_param { +# valid_param($media, $var, $val) +# +# Return a list of errors (if any) about having such value in the config + +sub _valid_param { my ($media, $var, $val) = @_[-3..-1]; if (!exists($value->{$var})) { return ("unknow var"); @@ -141,4 +159,14 @@ sub valid_param { return @errors; } +# Retun a hash containing information about $var + +sub _value_info { + my ($var) = $_[-1]; + if (exists($value->{$var})) { + return $value->{$var} + } + return; +} + 1; diff --git a/t/03mediacfg.t b/t/03mediacfg.t index 0c3f58a..48d6a16 100644 --- a/t/03mediacfg.t +++ b/t/03mediacfg.t @@ -2,8 +2,17 @@ use strict; use warnings; -use Test::More tests => 2; +use Test::More tests => 6; use_ok('MDV::Distribconf::MediaCFG'); -is(MDV::Distribconf::MediaCFG::valid_param('foo', 'name', 'toto'), 0, +is(MDV::Distribconf::MediaCFG::_valid_param('foo', 'name', 'toto'), 0, "Valid value return no error"); + +is(MDV::Distribconf::MediaCFG::_valid_param('foo', 'size', '1'), 0, + "valide size value"); +is(MDV::Distribconf::MediaCFG::_valid_param('foo', 'size', '1k'), 0, + "valide size value"); +is(MDV::Distribconf::MediaCFG::_valid_param('foo', 'size', '1d'), 1, + "non valide size value"); +is(MDV::Distribconf::MediaCFG::_valid_param('foo', 'size', 'coin'), 1, + "non valide size value"); |