<commit_before>#include <catch/catch.hpp>

#include "../src/modseclog/section.hpp"

// clang-format off
// Example:
// --1dc01a0d-A--
// ...
// --1dc01a0d-Z--
//
// clang-format on

namespace vmod = vidya::modseclog;

SCENARIO( "Section parser", "[parser,section]" )
{
    GIVEN( "A string containing modsecurity log section A" )
    {
        const std::string log( "--1dc01a0d-A--\n" );

        WHEN( "the parser is invoked" )
        {
            vmod::Section section;
            auto itr_begin = log.begin();
            auto itr_end   = log.end();

            bool result = section.parse( itr_begin, itr_end );

            THEN( "result should be true" )
            {
                REQUIRE( result == true );
            }

            THEN( "iterators must differ" )
            {
                REQUIRE( itr_begin != log.begin() );
            }

            THEN( "should parse hash" )
            {
                REQUIRE( section.hash == "1dc01a0d" );
            }

            THEN( "should parse name" )
            {
                REQUIRE( section.name == 'A' );
            }
        }
    }

    GIVEN( "A string missing the last two dashes" )
    {
        const std::string log( "--1dc01a0d-A\n" );

        WHEN( "the parser is invoked" )
        {
            vmod::Section section;
            auto itr_begin = log.begin();
            auto itr_end   = log.end();

            bool result = section.parse( itr_begin, itr_end );

            THEN( "result should be false" )
            {
                REQUIRE( result == false );
            }
        }
    }
}<commit_msg>Ensure section parser leaves iterator on the start of next line<commit_after>#include <catch/catch.hpp>

#include "../src/modseclog/section.hpp"

// clang-format off
// Example:
// --1dc01a0d-A--
// ...
// --1dc01a0d-Z--
//
// clang-format on

namespace vmod = vidya::modseclog;

SCENARIO( "Section parser", "[parser,section]" )
{
    GIVEN( "A string containing modsecurity log section A" )
    {
        const std::string log( "--1dc01a0d-A--\n" );

        WHEN( "the parser is invoked" )
        {
            vmod::Section section;
            auto itr_begin = log.begin();
            auto itr_end   = log.end();

            bool result = section.parse( itr_begin, itr_end );

            THEN( "result should be true" )
            {
                REQUIRE( result == true );
            }

            THEN( "iterators must differ" )
            {
                REQUIRE( itr_begin != log.begin() );
            }

            THEN( "should parse hash" )
            {
                REQUIRE( section.hash == "1dc01a0d" );
            }

            THEN( "should parse name" )
            {
                REQUIRE( section.name == 'A' );
            }
        }
    }

    GIVEN( "A string missing the last two dashes" )
    {
        const std::string log( "--1dc01a0d-A\n" );

        WHEN( "the parser is invoked" )
        {
            vmod::Section section;
            auto itr_begin = log.begin();
            auto itr_end   = log.end();

            bool result = section.parse( itr_begin, itr_end );

            THEN( "result should be false" )
            {
                REQUIRE( result == false );
            }
        }
    }

    GIVEN( "A string containing a section and the start of it's contents" )
    {
        const std::string log( "--1dc01a0d-A--\np" );

        WHEN( "the parser is invoked" )
        {
            vmod::Section section;
            auto itr_begin = log.begin();
            auto itr_end   = log.end();

            bool result = section.parse( itr_begin, itr_end );

            THEN( "result should be false" )
            {
                REQUIRE( *itr_begin == 'p' );
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.1285449244632918, 'fraction_numerical': 0.011661807580174927, 'mean_word_length': 1.3440993788819875, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4250050', 'n_tokens_mistral': 1228, 'n_tokens_neox': 1168, 'n_words': 282}