Config-Model
view release on metacpan or search on metacpan
t/dump_tree.t view on Meta::CPAN
# -*- cperl -*-
use ExtUtils::testlib;
use Test::More;
use Test::Memory::Cycle;
use Test::Differences;
use Config::Model;
use Config::Model::Tester::Setup qw/init_test/;
use warnings;
use strict;
use lib "t/lib";
my ($model, $trace) = init_test();
my $inst = $model->instance(
root_class_name => 'Master',
model_file => 'dump_load_model.pl',
instance_name => 'test1'
);
ok( $inst, "created dummy instance" );
my $root = $inst->config_root;
ok( $root, "Config root created" );
$inst->preset_start;
$root->fetch_element( name => 'hidden_string', accept_hidden => 1 )->store('hidden value');
my $step = 'std_id:ab X=Bv ' . '! lista:=a,b listb:=b ';
ok( $root->load( step => $step ), "preset data in tree with '$step'" );
$inst->preset_stop;
$step =
'std_id:ab X=Bv - std_id:bc X=Av - std_id:"b d " X=Av '
. '- a_string="toto \"titi\" tata" another_string="foobar" a_string2=dod@foo.com '
. 'a_string_to_test_newline="foo\nbar\\\\nbaz" '
. 'lista:=a,b,c,d olist:0 X=Av - olist:1 X=Bv - listb:=b,"c c2",d listc:="dod@foo.com" '
. '! hash_a:X2=x hash_a:Y2=xy hash_b:X3=xy my_check_list=X2,X3 hash_b:comment_test="#"'
. ' hash_a:"~"="~/bar" ';
ok( $root->load( step => $step ), "set up data in tree" );
eq_or_diff(
[ sort $root->fetch_element('std_id')->fetch_all_indexes ],
[ 'ab', 'b d ', 'bc' ],
"check std_id keys"
);
eq_or_diff( [ sort $root->fetch_element('lista')->fetch_all_values( mode => 'custom' ) ],
[qw/c d/], "check lista custom values" );
my $cds = $root->dump_tree;
print "cds string:\n$cds" if $trace;
subtest "test round trip" => sub {
my $load_inst = $model->instance(
root_class_name => 'Master',
model_file => 'dump_load_model.pl',
instance_name => 'round_trip'
);
my $round_root = $load_inst->config_root;
ok($round_root->load($cds), "test round trip: load");
my $new_cds = $round_root->dump_tree;
eq_or_diff(
( run in 1.670 second using v1.01-cache-2.11-cpan-39bf76dae61 )