Source

Kephra / t / 610-api-command.t

#!usr/bin/perl

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

package probe;
use Test::More tests => 9;
use Test::NoWarnings;

use Wx;
use Kephra;
use Kephra::App::Util;

Kephra::load_libs();
Kephra::Log::mode('text');

sub one     { 'one' }
sub true    { 'true' }
sub channel { $_[0] }

package C;
sub color   { Kephra::App::Util::create_color("blue") }

package Kephra::API;              # only from here you can register a switch var
Kephra::API::Command::switch_variables({
 '$color'    => { switch => 'colour',   class => 'C' },
});
sub colour{ C::color() }

package probe;



eval { Kephra::API::Command::register({
	'test-one' => {sub => 'probe::one',   label => 'one'},
	'test-true'=> {sub => 'true',         label => 'true'},
	'test-color'=>{sub => 'C::color',     label => 'color'},
	'test-gc'=>   {sub => '$color->IsOk', label => 'gc'},
	'test-chan'=> {sub => 'channel',      label => 'channel', parameter => 4},
})};
is($@, '', 'registered commands');


my $data = Kephra::API::Command::all_properties('test-one');
is(ref $data,                             'HASH', 'command entry created in list');
is($data->{'label'},                       'one', 'command data retrieved');
is( Kephra::API::Command::run('test-one'), 'one', 'run command');


my $data = Kephra::API::Command::all_properties('test-true');
my $blue = Kephra::App::Util::create_color("blue");
is( ref $data,                                          'HASH', 'package completion when omiting current package name');
is( Kephra::API::Command::run('test-color')->Blue, $blue->Blue, 'calling different package');
is( Kephra::API::Command::run('test-gc'),                    1, 'named switch var substitution');
is( Kephra::API::Command::run('test-chan'),                  4, 'parameter insertion');


exit(0);