File: filter.t

package info (click to toggle)
libconfig-model-tkui-perl 1.379-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 496 kB
  • sloc: perl: 3,615; makefile: 9
file content (138 lines) | stat: -rw-r--r-- 3,368 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
use Test::More ;
use Test::Differences;
use Test::Log::Log4perl;
use Config::Model 2.137;
use Config::Model::Tester::Setup qw/init_test setup_test_dir/;
use YAML::PP qw/LoadFile/;
use Hash::Merge qw/merge/;

use Config::Model::Tk::Filter qw/apply_filter/;

use strict;
use warnings;


my ($model, $trace, $args) = init_test('show','filter=s');

my $wr_root = setup_test_dir;
my $cmu ;

my @element = (
    # Value constructor args are passed in their specific array ref
    cargo => {
        type       => 'leaf',
        value_type => 'string',
    },
);

$model->create_config_class(
    name    => "TwoStrings",
    element => [
        str_a => {
            type       => 'leaf',
            value_type  => 'string',
        },
        str_b => {
            type       => 'leaf',
            value_type  => 'string',
        },
    ]
);

$model->create_config_class(
    name    => "HashAndCheckList",
    element => [
        hash_a => {
            type       => 'hash',
            index_type  => 'string',
            @element
        },
        check_list => {
            type       => 'check_list',
            choice  => [qw/A B C D/],
        },
    ]
);

$model->create_config_class(
    name    => "HashAndDefaultCheckList",
    element => [
        hash_a => {
            type       => 'hash',
            index_type  => 'string',
            @element
        },
        hash_b => {
            type       => 'hash',
            index_type  => 'string',
            @element
        },
        a_string => {
            type => 'leaf',
            value_type => "uniline",
            default => "blah",
        },
        check_list => {
            type       => 'check_list',
            choice  => [qw/A B C D/],
            default_list => [qw/B C/],
        },
    ]
);

$model->create_config_class(
    name    => "Main",
    element => [
        hcl1 => {
            type       => 'node',
            config_class_name => 'HashAndCheckList'
        },
        hcl2 => {
            type       => 'node',
            config_class_name => 'HashAndCheckList'
        },
        hcld1 => {
            type       => 'node',
            config_class_name => 'HashAndDefaultCheckList'
        },
        hnode => {
            type => 'hash',
            index_type => 'string',
            cargo => {
                type => 'node',
                config_class_name => 'TwoStrings',
            }
        }
    ]
);

use XXX;
my $inst_name = "test001";
my $test_data = LoadFile('t/filter-test.yml');

foreach my $test (@{$test_data->{tests}}) {
    next if ($args->{filter} and $test->{label} !~ /$args->{filter}/);

    my $output = merge($test->{output}, $test_data->{default_output});

    my $inst = $model->instance (
        root_class_name => 'Main',
        instance_name => $inst_name++ ,
        root_dir   => $wr_root,
    );

    $inst->config_root->load_data($test->{load});

    ok($inst,"created test instance for ". $test->{label}) ;

    my %args = %{ $test->{input} // {}};
    my $actions = { "__is_kept" => 1 };
    my $ref = \$actions;
    apply_filter(actions => $actions, instance => $inst, %args);
    YYY $actions if $trace;
    ok(! $actions->{__is_kept},"old entries are deleted");
    ok($$ref eq $actions, "ref is kept through when filtering");
    eq_or_diff( $actions, $output, $test->{label});
}

done_testing;