File: 06tree-iter-item.t

package info (click to toggle)
libhtml-widgets-navmenu-perl 1.1000-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 636 kB
  • sloc: perl: 8,051; makefile: 9
file content (119 lines) | stat: -rw-r--r-- 3,971 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
#!/usr/bin/perl -w

use Test::More tests => 33;

use strict;

BEGIN
{
    use_ok('HTML::Widgets::NavMenu::Tree::Iterator::Item');    # TEST
}

# Let's test the constructor:
# see if it's throwing exceptions when it should.

sub does_throw_exception
{
    my $args = shift;
    my $new_item;
    eval {
        $new_item =
            HTML::Widgets::NavMenu::Tree::Iterator::Item->new( {@$args} );
    };
    if ($@)
    {
        return ( 1, undef );
    }
    else
    {
        return ( 0, $new_item );
    }
}

{
    my @args_components = (
        [ 'node'        => +{ 'hello' => 'world', }, ],
        [ 'subs'        => [], ],
        [ 'accum_state' => +{ 'yes' => "sir", }, ],
    );

    # TEST*2*2*2
    for ( my $i = 0 ; $i < ( 2**@args_components ) ; ++$i )
    {
        my @args =
            ( map { ( $i & ( 1 << $_ ) ) ? ( @{ $args_components[$_] } ) : () }
                ( 0 .. $#args_components ) );
        my ( $exception_thrown, $new_item ) = does_throw_exception( \@args );
        if ( $i == ( 2**@args_components ) - 1 )
        {
            ok( ( ( !$exception_thrown ) && $new_item ),
                "Checking for constructor success with good arguments" );
        }
        else
        {
            ok( $exception_thrown,
                "Checking for constructor failure - No. $i" );
        }
    }
}

{
    my $item = HTML::Widgets::NavMenu::Tree::Iterator::Item->new(
        {
            'node'        => "Hello",
            'subs'        => [],
            'accum_state' => 5,
        }
    );

    # TEST
    is( $item->_node(), "Hello", "Getting the node()" );
}

{
    my $item = HTML::Widgets::NavMenu::Tree::Iterator::Item->new(
        {
            'node'        => "Hello",
            'subs'        => [],
            'accum_state' => "Foobardom",
        }
    );

    # TEST
    is( $item->_accum_state(), "Foobardom", "Getting Foobardom" );
}

{
    my $item = HTML::Widgets::NavMenu::Tree::Iterator::Item->new(
        {
            'node'        => "Hello",
            'subs'        => [ "ONE", "Two", "threE3", "4.0" ],
            'accum_state' => 5,
        }
    );

    ok( ( !$item->_is_visited() ), "Item is not visited at start" );     # TEST
    is( $item->_num_subs_to_go(), 4,     "Num subs to go at start" );    # TEST
    is( $item->_num_subs(),       4,     "Num subs at start" );          # TEST
    is( $item->_visit(),          "ONE", "First sub" );                  # TEST
    is( $item->_num_subs_to_go(), 3,     "Num subs to go after first visit" )
        ;                                                                # TEST
    ok( $item->_is_visited(), "Item is visited after first visit" );     # TEST
    is( $item->_visit(), "Two", "Second sub" );                          # TEST
    ok( $item->_is_visited(), "Item is visited after second visit" );    # TEST
    is( $item->_num_subs_to_go(), 2,        "Num subs to go (3)" );      # TEST
    is( $item->_num_subs(),       4,        "Num subs at middle" );      # TEST
    is( $item->_visit(),          "threE3", "Third sub" );               # TEST
    ok( $item->_is_visited(), "Item is visited after third visit" );     # TEST
    is( $item->_num_subs_to_go(), 1,     "Num subs to go (4)" );         # TEST
    is( $item->_visit(),          "4.0", "Fourth sub" );                 # TEST
    ok( $item->_is_visited(), "Item is visited after fourth visit" );    # TEST
    is( $item->_num_subs_to_go(), 0, "Num subs to go (end)" );           # TEST
    ok( ( !defined( $item->_visit() ) ), "No more subs" );               # TEST
    ok( $item->_is_visited(), "Item is visited after no more subs" );    # TEST
    is( $item->_num_subs_to_go(), 0, "Num subs to go (end 2)" );         # TEST
    is( $item->_num_subs(),       4, "Num subs at finish" );             # TEST
    ok( ( !defined( $item->_visit() ) ), "No more subs (2)" );           # TEST
    is( $item->_node(), "Hello", "item->_node() is correct" );           # TEST

}