#!perl
use Cassandane::Tiny;

sub test_list_subscribed_return_children
    :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 )] ],
    ]);

    xlog $self, "listing...";
    my $subdata = $imaptalk->list([qw(SUBSCRIBED)], "", "*", "RETURN", [qw(CHILDREN)]);

    xlog $self, "subscribed to: " . Dumper $subdata;
    $self->assert_mailbox_structure($subdata, '/', {
        'INBOX'                 => [qw( \\Subscribed \\HasNoChildren )],
        'Fruit/Banana'          => [qw( \\Subscribed \\HasNoChildren )],
        'Fruit/Peach'           => [qw( \\NonExistent \\Subscribed \\HasNoChildren )],
        'Vegetable'             => [qw( \\Subscribed \\HasChildren )],
    }, 'strict');
}
