<commit_before>#include "p0compile/parser.hpp"
#include "p0compile/expression_tree.hpp"
#include "p0compile/scanner.hpp"
#include "p0compile/compiler_error.hpp"
#include <boost/test/unit_test.hpp>


namespace
{
	bool handle_unexpected_error(p0::compiler_error const &error)
	{
		(void)error;
		BOOST_CHECK(nullptr == "No error expected");
		return true;
	}
}

BOOST_AUTO_TEST_CASE(parse_empty_file_test)
{
	std::string const source = "";
	p0::source_range const source_range(
				source.data(),
				source.data() + source.size());
	p0::scanner scanner(source_range);
	p0::parser parser(scanner, handle_unexpected_error);
	auto const ast = parser.parse_unit();
	BOOST_REQUIRE(ast);
}<commit_msg>generalize parser test<commit_after>#include "p0compile/parser.hpp"
#include "p0compile/expression_tree.hpp"
#include "p0compile/scanner.hpp"
#include "p0compile/compiler_error.hpp"
#include <boost/test/unit_test.hpp>


namespace
{
	bool handle_unexpected_error(p0::compiler_error const &error)
	{
		(void)error;
		BOOST_CHECK(nullptr == "No error expected");
		return true;
	}

	template <class ASTHandler>
	void test_parser(std::string const &source, ASTHandler const &handle_ast)
	{
		p0::source_range const source_range(
					source.data(),
					source.data() + source.size());
		p0::scanner scanner(source_range);
		p0::parser parser(scanner, handle_unexpected_error);
		auto const ast = parser.parse_unit();
		BOOST_REQUIRE(ast);
		handle_ast(*ast);
	}
}

BOOST_AUTO_TEST_CASE(parse_empty_file_test)
{
	test_parser("", [](p0::function_tree const &ast)
	{
		BOOST_CHECK(ast.parameters().empty());
		//TODO check empty body
	});
}
{'fraction_non_alphanumeric': 0.136977886977887, 'fraction_numerical': 0.010442260442260442, 'mean_word_length': 6.021551724137931, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '6838239', 'n_tokens_mistral': 616, 'n_tokens_neox': 578, 'n_words': 103}