#!perl
use Cassandane::Tiny;

sub test_cmd_id_nil_cant_unget ($self)
{
    # Purge any syslog lines before this test runs.
    $self->{instance}->getsyslog();

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

    # Construct an ID command where the 'N' in NULL is the 4096'th character
    # in the prot buffer.
    # This will require a new read to get the rest of the command,
    # but will also prohibit calling prot_ungetc('N').
    # Successful execution of the command will verify that we have fixed the
    # parsing issue.
    # If the previous bug returns, imapd will fatal() attempting to prot_unget()
    my $x = 'x' x 1014;
    $imaptalk->{CmdId} = 'XX';
    $imaptalk->_imap_cmd('ID', 0, {},
                         qq{("a" "$x" "b" "$x" "c" "$x" "d" "$x" "e" NIL)});
    $self->assert_str_equals('ok', $imaptalk->get_last_completion_response());
}
