<commit_before>#include <x0/message_parser.hpp>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>

#include <iostream>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <strings.h>

using namespace x0;
using namespace std::placeholders;

#if !CC_SUPPORTS_LAMBDA
#	warning "Compiler does not support lambda expressions. Cannot unit-test message_parser"
#else

class message_parser_test :
	public CPPUNIT_NS::TestFixture
{
public:
	CPPUNIT_TEST_SUITE(message_parser_test);
		CPPUNIT_TEST(request_simple);
		CPPUNIT_TEST(request_chunked_body);
		//CPPUNIT_TEST(request_content_length);

#if 0
		CPPUNIT_TEST(response_simple);
		CPPUNIT_TEST(response_sample_304);
		CPPUNIT_TEST(response_no_status_text);
		CPPUNIT_TEST(response_no_header);
		CPPUNIT_TEST(response_chunked_body);
		CPPUNIT_TEST(response_content_length);
#endif
	CPPUNIT_TEST_SUITE_END();

private:
	void request_simple()
	{
		message_parser rp; // (message_parser::REQUEST);

		rp.on_request = [&](buffer_ref&& method, buffer_ref&& entity, buffer_ref&& protocol, int major, int minor) {
			printf("on_response('%s', '%s', '%s', %d, %d)\n",
			       method.str().c_str(), entity.str().c_str(), protocol.str().c_str(), major, minor);<commit_msg>added complex-LWS test<commit_after>#include <x0/message_parser.hpp>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>

#include <iostream>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <strings.h>

using namespace x0;
using namespace std::placeholders;

#if !CC_SUPPORTS_LAMBDA
#	warning "Compiler does not support lambda expressions. Cannot unit-test message_parser"
#else

class message_parser_test :
	public CPPUNIT_NS::TestFixture
{
public:
	CPPUNIT_TEST_SUITE(message_parser_test);
		CPPUNIT_TEST(request_simple);
		CPPUNIT_TEST(request_complex_lws_headers);
		CPPUNIT_TEST(request_chunked_body);
		//CPPUNIT_TEST(request_content_length);

#if 0
		CPPUNIT_TEST(response_simple);
		CPPUNIT_TEST(response_sample_304);
		CPPUNIT_TEST(response_no_status_text);
		CPPUNIT_TEST(response_no_header);
		CPPUNIT_TEST(response_chunked_body);
		CPPUNIT_TEST(response_content_length);
#endif
	CPPUNIT_TEST_SUITE_END();

private:
	void request_complex_lws_headers()
	{
		message_parser rp; // (message_parser::REQUEST);

		buffer r(
			"GET /foo HTTP/1.1\r\n"
			"Single-Line: single value\r\n"            // simple LWS at the beginning & middle
			"Multi-Line-1: multi\r\n\tvalue 1\r\n"     // complex LWS in the middle
			"Multi-Line-2:\r\n \t \tmulti value 2\r\n" // complex LWS at the beginning
			"\r\n"
		);
		std::error_code ec;
		std::size_t nparsed = rp.parse(r, ec);
		printf("nparsed: %ld; error: %s\n", nparsed, ec.message().c_str());
	}

	void request_simple()
	{
		message_parser rp; // (message_parser::REQUEST);

		rp.on_request = [&](buffer_ref&& method, buffer_ref&& entity, buffer_ref&& protocol, int major, int minor) {
			printf("on_response('%s', '%s', '%s', %d, %d)\n",
			       method.str().c_str(), entity.str().c_str(), protocol.str().c_str(), major, minor);
{'fraction_non_alphanumeric': 0.13684548666880822, 'fraction_numerical': 0.0057822036620623195, 'mean_word_length': 5.711206896551724, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '4600507', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1115, 'n_words': 216}