Kephra / t / 610-commandlist.t


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

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

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


sub one     { 'one' }
sub true    { 'true' }
sub color   { Kephra::App::Util::create_color("blue") }
sub channel { $_[0] }

eval { Kephra::API::Command::register_namespace('test') };
is($@, '', 'registered cmd namespace');

eval { Kephra::API::Command::register_context_var('color') };
is($@, '', 'registered package switch var');

eval { Kephra::API::Command::register_switch_var({ '$color' => 'color'}) };
is($@, '', 'registered named switch var');

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

eval { Kephra::API::Command::init() };
is($@, '', 'initialized command list');

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

my $data = Kephra::API::Command::all_properties('test-true');
is(ref $data, 'HASH', 'command ID prefix completion');
is( Kephra::API::Command::run('test-true'), 'true', 'sub prefix completion (module name)');
is( Kephra::API::Command::run('test-blue'), 1, 'package switch var substitution');
is( Kephra::API::Command::run('test-gc'), 1, 'named switch var substitution');
is( Kephra::API::Command::run('test-chan'), 4, 'parameter insertion');

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.