#!perl
use Cassandane::Tiny;

sub test_recursivematch
    :UnixHierarchySep :AltNamespace
{
    my ($self) = @_;

    my $imaptalk = $self->{store}->get_client();

    $self->setup_mailbox_structure($imaptalk, [
        [ 'subscribe' => 'INBOX' ],
        [ 'create' => [qw( Fruit Fruit/Apple Fruit/Banana Fruit/Peach)] ],
        [ 'subscribe' => [qw( Fruit/Banana Fruit/Peach )] ],
        [ 'delete' => 'Fruit/Peach' ],
        [ 'create' => [qw( Tofu Vegetable Vegetable/Broccoli Vegetable/Corn )] ],
        [ 'subscribe' => [qw( Vegetable Vegetable/Broccoli )] ],
    ]);

    my $subdata = $imaptalk->list([qw(SUBSCRIBED RECURSIVEMATCH)], "", "*");

    xlog(Dumper $subdata);
    $self->assert_mailbox_structure($subdata, '/', {
        'INBOX'                 => '\\Subscribed',
        'Fruit/Banana'          => '\\Subscribed',
        'Fruit/Peach'           => [qw( \\NonExistent \\Subscribed )],
        'Vegetable'             => [qw( \\Subscribed \\HasChildren )], # HasChildren not required by spec, but cyrus tells us
        'Vegetable/Broccoli'    => '\\Subscribed',
    });
}
