Source

Kephra / t / 200-app-util.t

Full commit
#!usr/bin/perl

# making local lib favoured
BEGIN { unshift @INC, -d 't' ? 'lib' : '../lib' }

use Test::More tests => 26  ;
#use Text::Exception;
use Test::NoWarnings;

use Wx;
use Kephra::App::Util qw(is_widget is_panel is_sizer is_color is_font create_color lounch_browser);


# testing the function that gives references to the helper functions
my $testcolor = Kephra::App::Util::get('is_color');
my @chref = Kephra::App::Util::get('is_color', 'create_color');
is( $testcolor, \&Kephra::App::Util::is_color, 'get a helper function reference');
is_deeply( \@chref, [ \&Kephra::App::Util::is_color, \&Kephra::App::Util::create_color ], 
    'get several helper references');
is_deeply( \@chref, [ \&is_color, \&create_color ], 'import via Exporter works too');
my $color = $chref[1];


my $text  = Wx::StaticText->new( undef, -1, '');
my $btn   = Wx::Button->new( undef, -1, '');
my $panel = Wx::Panel->new( undef );
my $sizer = Wx::BoxSizer->new( &Wx::wxHORIZONTAL );


# object type checker
is( is_widget(0),      0, 'can detect that a number is not widget');
is( is_widget([]),     0, 'can detect that ref is not a widget');
is( is_widget($sizer), 0, 'can detect that sizer is not a widget');
is( is_widget($text),  1, 'can detect what is a widget');
is( is_widget($panel), 1, 'panel are widgets too');

is( is_panel(0),       0, 'can detect what is not a panel');
is( is_panel({}),      0, 'can detect that a ref is not a panel');
is( is_panel($sizer),  0, 'can detect that sizer is not a panel');
is( is_panel($panel),  1, 'can detect what is a panel');

is( is_sizer(3),       0, 'can detect that number are no sizer');
is( is_sizer(sub{}),   0, 'can detect that ref are no sizer');
is( is_sizer($panel),  0, 'can detect that panel are no sizer');
is( is_sizer($sizer),  1, 'can detect what is a sizer');



# color helper
my $white = Wx::Colour->new(255, 255, 255);
is( is_color(0),                     0, 'can detect what is not a color object');
is( is_color($white),                1, 'can detect what is a color object');
is( $testcolor->($white),            1, 'refernce works too');
is( is_color( $color->(0,0,255) ),   1, 'R,G,B input layout works ');
is( is_color( $color->("0,0,255") ), 1, '"R,G,B" input layout works');
is( is_color( $color->("#0000FF") ), 1, '"#RRGGBB" input layout works');
is( is_color( $color->("0000ff") ),  1, '"RRGGBB" input layout works');
is( is_color( $color->("blue") ),    1, '"colorname" input layout works');
is( is_color( $color->("WHEAT") ),   1, '"colorname" input layout works with db names');

exit(0);