<commit_before>
#include <test.hpp>

TEST_CASE("default constructed pbf_reader is okay") {
    protozero::pbf_reader item;

    REQUIRE(item.length() == 0);
    REQUIRE_FALSE(item); // test operator bool()
    REQUIRE_FALSE(item.next());
}

TEST_CASE("empty buffer in pbf_reader is okay") {
    const std::string buffer;
    protozero::pbf_reader item{buffer};

    REQUIRE(item.length() == 0);
    REQUIRE_FALSE(item); // test operator bool()
    REQUIRE_FALSE(item.next());
}

TEST_CASE("check every possible value for single byte in buffer") {
    char buffer;
    for (int i = 0; i <= 255; ++i) {
        buffer = static_cast<char>(i);
        protozero::pbf_reader item{&buffer, 1};

        REQUIRE(item.length() == 1);
        REQUIRE_FALSE(!item); // test operator bool()
        REQUIRE_THROWS((item.next(), item.skip()));
    }
}

TEST_CASE("next() should throw when illegal wire type is encountered") {
    const char buffer = 1u << 3u | 7u;

    protozero::pbf_reader item{&buffer, 1};
    REQUIRE_THROWS_AS(item.next(), const protozero::unknown_pbf_wire_type_exception&);
}

TEST_CASE("next() should throw when illegal tag is encountered") {
    std::string data;

    SECTION("tag 0") {
        protozero::write_varint(std::back_inserter(data), 0u << 3u | 1u);
    }

    SECTION("tag 19000") {
        protozero::write_varint(std::back_inserter(data), 19000u << 3u | 1u);
    }

    SECTION("tag 19001") {
        protozero::write_varint(std::back_inserter(data), 19001u << 3u | 1u);
    }

    SECTION("tag 19999") {
        protozero::write_varint(std::back_inserter(data), 19999u << 3u | 1u);
    }

    protozero::pbf_reader item{data};
    REQUIRE_THROWS_AS(item.next(), const protozero::invalid_tag_exception&);
}

TEST_CASE("next() works when a legal tag is encountered") {
    std::string data;

    SECTION("tag 1") {
        protozero::write_varint(std::back_inserter(data), 1u << 3u | 1u);
    }

    SECTION("tag 18999") {
        protozero::write_varint(std::back_inserter(data), 18999u << 3u | 1u);
    }

    SECTION("tag 20000") {
        protozero::write_varint(std::back_inserter(data), 20000u << 3u | 1u);
    }

    SECTION("tag 1^29 - 1") {
        protozero::write_varint(std::back_inserter(data), ((1u << 29u) - 1u) << 3u | 1u);
    }
<commit_msg>Use TEST_CASEs instead of SECTIOs in some tests.<commit_after>
#include <test.hpp>

TEST_CASE("default constructed pbf_reader is okay") {
    protozero::pbf_reader item;

    REQUIRE(item.length() == 0);
    REQUIRE_FALSE(item); // test operator bool()
    REQUIRE_FALSE(item.next());
}

TEST_CASE("empty buffer in pbf_reader is okay") {
    const std::string buffer;
    protozero::pbf_reader item{buffer};

    REQUIRE(item.length() == 0);
    REQUIRE_FALSE(item); // test operator bool()
    REQUIRE_FALSE(item.next());
}

TEST_CASE("check every possible value for single byte in buffer") {
    char buffer;
    for (int i = 0; i <= 255; ++i) {
        buffer = static_cast<char>(i);
        protozero::pbf_reader item{&buffer, 1};

        REQUIRE(item.length() == 1);
        REQUIRE_FALSE(!item); // test operator bool()
        REQUIRE_THROWS((item.next(), item.skip()));
    }
}

TEST_CASE("next() should throw when illegal wire type is encountered") {
    const char buffer = 1u << 3u | 7u;

    protozero::pbf_reader item{&buffer, 1};
    REQUIRE_THROWS_AS(item.next(), const protozero::unknown_pbf_wire_type_exception&);
}

TEST_CASE("next() should throw when illegal tag 0 is encountered") {
    std::string data;
    protozero::write_varint(std::back_inserter(data), 0u << 3u | 1u);
    protozero::pbf_reader item{data};
    REQUIRE_THROWS_AS(item.next(), const protozero::invalid_tag_exception&);
}

TEST_CASE("next() should throw when illegal tag 19000 is encountered") {
    std::string data;
    protozero::write_varint(std::back_inserter(data), 19000u << 3u | 1u);
    protozero::pbf_reader item{data};
    REQUIRE_THROWS_AS(item.next(), const protozero::invalid_tag_exception&);
}

TEST_CASE("next() should throw when illegal tag 19001 is encountered") {
    std::string data;
    protozero::write_varint(std::back_inserter(data), 19001u << 3u | 1u);
    protozero::pbf_reader item{data};
    REQUIRE_THROWS_AS(item.next(), const protozero::invalid_tag_exception&);
}

TEST_CASE("next() should throw when illegal tag 19999 is encountered") {
    std::string data;
    protozero::write_varint(std::back_inserter(data), 19999u << 3u | 1u);
    protozero::pbf_reader item{data};
    REQUIRE_THROWS_AS(item.next(), const protozero::invalid_tag_exception&);
}

TEST_CASE("next() works when legal tag 1 is encountered") {
    std::string data;
    protozero::write_varint(std::back_inserter(data), 1u << 3u | 1u);
    protozero::pbf_reader item{data};
    REQUIRE(item.next());
}

TEST_CASE("next() works when legal tag 18999 is encountered") {
    std::string data;
    protozero::write_varint(std::back_inserter(data), 18999u << 3u | 1u);
    protozero::pbf_reader item{data};
    REQUIRE(item.next());
}

TEST_CASE("next() works when legal tag 20000 is encountered") {
    std::string data;
    protozero::write_varint(std::back_inserter(data), 20000u << 3u | 1u);
    protozero::pbf_reader item{data};
    REQUIRE(item.next());
}

TEST_CASE("next() works when legal tag 1^29 - 1 is encountered") {
    std::string data;
    protozero::write_varint(std::back_inserter(data), ((1ul << 29u) - 1u) << 3u | 1u);
{'fraction_non_alphanumeric': 0.1503328402366864, 'fraction_numerical': 0.03328402366863906, 'mean_word_length': 4.0884289746001885, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1845588', 'n_tokens_mistral': 2083, 'n_tokens_neox': 1881, 'n_words': 405}