App-Nag

 view release on metacpan or  search on metacpan

t/arg_validation.t  view on Meta::CPAN

#!/usr/bin/perl

use Modern::Perl;
use App::Nag;
use DateTime;
use DateTime::TimeZone;

use Test::More;
use Test::Fatal;

# this all could be cleaned up a bit

my (
    $opt,      $usage,   $name, $verbosity, $text,
    $synopsis, $seconds, $time, $true_seconds
);
local @ARGV;

subtest '1s delta' => sub {
    @ARGV = qw(1s this is the text);
    ( $opt, $usage, $name ) = App::Nag->validate_args;
    ( $verbosity, $text, $synopsis, $seconds ) =
      App::Nag->validate_time( $opt, $usage, @ARGV );
    ok( $verbosity == 1, 'right verbosity' );
    ok( $seconds == 1,   '1s' );
};

subtest '1h delta' => sub {
    @ARGV = qw(--slap 1h this is the text);
    ( $opt, $usage, $name ) = App::Nag->validate_args;
    ( $verbosity, $text, $synopsis, $seconds ) =
      App::Nag->validate_time( $opt, $usage, @ARGV );
    ok( $verbosity == 3,     'right verbosity --slap' );
    ok( $seconds == 60 * 60, '1h' );
};

subtest '1H delta' => sub {
    @ARGV = qw(--slap 1H this is the text);
    ( $opt, $usage, $name ) = App::Nag->validate_args;
    ( $verbosity, $text, $synopsis, $seconds ) =
      App::Nag->validate_time( $opt, $usage, @ARGV );
    ok( $verbosity == 3,     'right verbosity --slap' );
    ok( $seconds == 60 * 60, '1h' );
};

my $tz = DateTime::TimeZone->new( name => 'local' );

subtest '10am' => sub {
    $time         = '10am';
    $true_seconds = get_time( 10, 0, 'am' );
    @ARGV         = ( $time, qw(this is the text) );
    ( $opt, $usage, $name ) = App::Nag->validate_args;
    ( $verbosity, $text, $synopsis, $seconds ) =
      App::Nag->validate_time( $opt, $usage, @ARGV );
    ok( $seconds == $true_seconds, "time: $time" );
};

subtest '10AM' => sub {
    $time         = '10AM';
    $true_seconds = get_time( 10, 0, 'am' );
    @ARGV         = ( $time, qw(this is the text) );
    ( $opt, $usage, $name ) = App::Nag->validate_args;
    ( $verbosity, $text, $synopsis, $seconds ) =
      App::Nag->validate_time( $opt, $usage, @ARGV );
    ok( $seconds == $true_seconds, "time: $time" );
};

subtest '10A.M.' => sub {
    $time         = '10A.M.';
    $true_seconds = get_time( 10, 0, 'am' );
    @ARGV         = ( $time, qw(this is the text) );
    ( $opt, $usage, $name ) = App::Nag->validate_args;
    ( $verbosity, $text, $synopsis, $seconds ) =
      App::Nag->validate_time( $opt, $usage, @ARGV );
    ok( $seconds == $true_seconds, "time: $time" );
};

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.742 second using v1.00-cache-2.02-grep-82fe00e-cpan-9e6bc14194b )