App-MtAws
view release on metacpan or search on metacpan
t/unit/config_engine_new.t view on Meta::CPAN
};
};
describe "seen" => sub {
it "should work" => sub {
localize sub {
option 'o1';
App::MtAws::ConfigEngine::seen('o1');
cmp_deeply Context->{options}->{o1}, { name => 'o1', seen => 1 };
};
};
it 'should work with \$_' => sub {
localize sub {
option 'o1';
App::MtAws::ConfigEngine::seen for ('o1');
cmp_deeply Context->{options}->{o1}, { name => 'o1', seen => 1 };
};
};
it "should not work twice" => sub {
localize sub {
positional 'o1';
Context->{positional_tail} = ['a'];
App::MtAws::ConfigEngine::seen('o1');
cmp_deeply Context->{positional_tail}, [];
cmp_deeply Context->{options}->{o1}, { name => 'o1', seen => 1, value => 'a', positional => 1, source => 'positional' };
App::MtAws::ConfigEngine::seen('o1');
cmp_deeply Context->{positional_tail}, [];
cmp_deeply Context->{options}->{o1}, { name => 'o1', seen => 1, value => 'a', positional => 1, source => 'positional' };
};
};
it "should die if option undeclared" => sub {
localize sub {
option 'o1';
ok ! defined eval { App::MtAws::ConfigEngine::seen('o2'); 1 };
};
};
it "should work with positional option" => sub {
localize sub {
positional 'o1';
Context->{positional_tail} = ['a'];
App::MtAws::ConfigEngine::seen('o1');
cmp_deeply Context->{options}->{o1}, { name => 'o1', seen => 1, value => 'a', positional => 1, source => 'positional' };
};
};
it "should work with positional option if value missed" => sub {
localize sub {
positional 'o1';
Context->{positional_tail} = [];
App::MtAws::ConfigEngine::seen('o1');
cmp_deeply Context->{options}->{o1}, { name => 'o1', seen => 1, positional => 1};
};
};
it "should decode UTF-8" => sub {
localize sub {
positional 'o1';
Context->{positional_tail} = [encode("UTF-8", 'ÑеÑÑ')];
App::MtAws::ConfigEngine::seen('o1');
cmp_deeply Context->{options}->{o1}, { name => 'o1', seen => 1, positional => 1, source => 'positional', value => 'ÑеÑÑ'};
};
};
it "should throw error if broken UTF found" => sub {
localize sub {
positional 'o1';
message 'options_encoding_error', 'bad coding';
Context->{positional_tail} = ["\xA0"];
App::MtAws::ConfigEngine::seen('o1');
cmp_deeply Context->{errors}, [{format => 'options_encoding_error', encoding => 'UTF-8'}];
cmp_deeply Context->{options}->{o1}, { name => 'o1', seen => 1, positional => 1 };
};
};
};
describe 'unflatten_scope' => sub {
it "should work" => sub {
my $c = create_engine();
$c->{options} = {
a => { value => 1, seen => 1},
b => { value => 2, scope => ['x'], seen => 1},
};
$c->unflatten_scope();
cmp_deeply $c->{data}, { a => 1, x => { b => 2 }};
cmp_deeply $c->{options}->{a}, { value => 1, seen => 1}, "it should not autovivify scope";
};
it "should not work if option not seen, and we have scope" => sub {
my $c = create_engine();
$c->{options} = {
a => { value => 1, seen => 1},
b => { value => 2, scope => ['x']},
};
$c->unflatten_scope();
cmp_deeply $c->{data}, { a => 1};
cmp_deeply $c->{options}->{a}, { value => 1, seen => 1}, "it should not autovivify scope";
};
it "should not work if option not seen" => sub {
my $c = create_engine();
$c->{options} = {
a => { value => 1 },
b => { value => 2, scope => ['x'], seen => 1},
};
$c->unflatten_scope();
cmp_deeply $c->{data}, { x => { b => 2 }};
cmp_deeply $c->{options}->{a}, { value => 1 }, "it should not autovivify scope";
};
it "should not work if option has no value" => sub {
my $c = create_engine();
$c->{options} = {
a => { name => 'a', seen => 1 },
b => { name => 'b', value => 2, scope => ['x'], seen => 1},
};
$c->unflatten_scope();
cmp_deeply $c->{data}, { x => { b => 2 }};
cmp_deeply $c->{options}->{a}, { name => 'a', seen => 1 }, "it should not autovivify scope";
};
it "should work with nested scopes" => sub {
my $c = create_engine();
$c->{options} = {
a => { value => 1, seen => 1},
b => { value => 2, scope => ['x', 'y'], seen => 1},
};
$c->unflatten_scope();
cmp_deeply $c->{data}, { a => 1, x => { y => { b => 2 }}};
( run in 0.890 second using v1.01-cache-2.11-cpan-f56aa216473 )