<commit_before>package TestAPR::bucket;

# a mix of APR::Brigade, APR::Bucket abd APR::BucketType tests

use strict;
use warnings FATAL => 'all';

use Apache::Test;
use Apache::TestUtil;

use APR::Brigade ();
use APR::Bucket ();
use APR::BucketType ();
use Apache::Connection ();
use Apache::RequestRec ();

use Apache::Const -compile => 'OK';

use TestAPRlib::bucket;

sub handler {

    my $r = shift;

    plan $r, tests => 18 + TestAPRlib::bucket::num_of_tests();

    TestAPRlib::bucket::test();

    my $ba = $r->connection->bucket_alloc;

    # eos_create / type / length
    {
        my $b = APR::Bucket::eos_create($ba);
        my $type = $b->type;
        ok t_cmp($type->name, 'EOS', "eos_create");

        ok t_cmp($b->length, 0, "eos b->length");

        # buckets with no data to read should return an empty string
        my $rlen = $b->read(my $read);
        ok t_cmp($read, "", 'eos b->read/buffer');
        ok t_cmp($rlen, 0, 'eos b->read/len');
    }

    # flush_create
    {
        my $b = APR::Bucket::flush_create($ba);
        my $type = $b->type;
        ok t_cmp($type->name, 'FLUSH', "flush_create");

        ok t_cmp($b->length, 0, "flush b->length");
    }

    # insert_after / insert_before / is_eos / is_flush
    {
        my $d1 = APR::Bucket->new("d1");
        my $d2 = APR::Bucket->new("d2");
        my $f1 = APR::Bucket::flush_create($ba);
        my $f2 = APR::Bucket::flush_create($ba);
        my $e1 = APR::Bucket::eos_create($ba);

        ### create a chain of buckets
        my $bb = APR::Brigade->new($r->pool, $ba);

        $bb->insert_head($d1);

        # d1->d2
        $d1->insert_after($d2);

        # d1->f1->d2
        $d2->insert_before($f1);

        # d1->f1->d2->f2
        $d2->insert_after($f2);

        # d1->f1->d2->f2->e1
        $bb->insert_tail($e1);

        ### now test

        my $b = $bb->first;
        $b->read(my $read);
        ok t_cmp($read, "d1", "d1 bucket");

        $b = $bb->next($b);
        t_debug("is_flush");
        ok $b->is_flush;

        $b = $bb->next($b);
        $b->read($read);
        ok t_cmp($read, "d2", "d2 bucket");

        $b = $bb->last();
        t_debug("is_eos");
        ok $b->is_eos;

        $b = $bb->prev($b);
        t_debug("is_flush");
        ok $b->is_flush;

        t_debug("not empty");
        ok !$bb->is_empty;<commit_msg>make it easier to visualize what's going on PR: Obtained from: Submitted by: Reviewed by:<commit_after>package TestAPR::bucket;

# a mix of APR::Brigade, APR::Bucket abd APR::BucketType tests

use strict;
use warnings FATAL => 'all';

use Apache::Test;
use Apache::TestUtil;

use APR::Brigade ();
use APR::Bucket ();
use APR::BucketType ();
use Apache::Connection ();
use Apache::RequestRec ();

use Apache::Const -compile => 'OK';

use TestAPRlib::bucket;

sub handler {

    my $r = shift;

    plan $r, tests => 18 + TestAPRlib::bucket::num_of_tests();

    TestAPRlib::bucket::test();

    my $ba = $r->connection->bucket_alloc;

    # eos_create / type / length
    {
        my $b = APR::Bucket::eos_create($ba);
        my $type = $b->type;
        ok t_cmp($type->name, 'EOS', "eos_create");

        ok t_cmp($b->length, 0, "eos b->length");

        # buckets with no data to read should return an empty string
        my $rlen = $b->read(my $read);
        ok t_cmp($read, "", 'eos b->read/buffer');
        ok t_cmp($rlen, 0, 'eos b->read/len');
    }

    # flush_create
    {
        my $b = APR::Bucket::flush_create($ba);
        my $type = $b->type;
        ok t_cmp($type->name, 'FLUSH', "flush_create");

        ok t_cmp($b->length, 0, "flush b->length");
    }

    # insert_after / insert_before / is_eos / is_flush
    {
        my $d1 = APR::Bucket->new("d1");
        my $d2 = APR::Bucket->new("d2");
        my $f1 = APR::Bucket::flush_create($ba);
        my $f2 = APR::Bucket::flush_create($ba);
        my $e1 = APR::Bucket::eos_create($ba);

        ### create a chain of buckets
        my $bb = APR::Brigade->new($r->pool, $ba);

                                 # head->tail
        $bb->insert_head(  $d1); # head->d1->tail
        $d1->insert_after( $d2); # head->d1->d2->tail
        $d2->insert_before($f1); # head->d1->f1->d2->tail
        $d2->insert_after( $f2); # head->d1->f1->d2->f2->tail
        $bb->insert_tail(  $e1); # head->d1->f1->d2->f2->e1->tail

        ### now test
        my $b = $bb->first;
        $b->read(my $read);
        ok t_cmp($read, "d1", "d1 bucket");

        $b = $bb->next($b);
        t_debug("is_flush");
        ok $b->is_flush;

        $b = $bb->next($b);
        $b->read($read);
        ok t_cmp($read, "d2", "d2 bucket");

        $b = $bb->last();
        t_debug("is_eos");
        ok $b->is_eos;

        $b = $bb->prev($b);
        t_debug("is_flush");
        ok $b->is_flush;

        t_debug("not empty");
        ok !$bb->is_empty;
{'fraction_non_alphanumeric': 0.19569672131147542, 'fraction_numerical': 0.015778688524590165, 'mean_word_length': 2.2714477211796247, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 106, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4984360', 'n_tokens_mistral': 1871, 'n_tokens_neox': 1781, 'n_words': 387}