<commit_before>
#include <togo/core/error/assert.hpp>
#include <togo/core/utility/utility.hpp>
#include <togo/core/log/log.hpp>
#include <togo/core/collection/fixed_array.hpp>
#include <togo/core/string/string.hpp>
#include <togo/core/hash/hash.hpp>
#include <togo/game/resource/resource.hpp>

#include <initializer_list>

using namespace togo;
using namespace togo::game;

void test_path(
	ResourcePathParts& pp,
	StringRef const path,
	bool const expect_valid,
	StringRef const name,
	StringRef const type,
	std::initializer_list<StringRef> tags
) {
	bool const valid = resource::parse_path(path, pp);
	TOGO_LOGF("%s: '%.*s'\n", valid ? "valid  " : "invalid", path.size, path.data);
	if (valid) {
		TOGO_LOGF("  name: 0x%016lx '%.*s'\n", pp.name_hash, pp.name.size, pp.name.data);
		TOGO_LOGF("  type: 0x%08x%8s '%.*s'\n", pp.type_hash, "", pp.type.size, pp.type.data);
		TOGO_LOGF("  tags: 0x%016lx [", pp.tags_hash);
		for (unsigned i = 0; i < fixed_array::size(pp.tags); ++i) {
			TOGO_LOGF(
				"0x%08x '%.*s'%.*s",
				pp.tags[i].hash,
				pp.tags[i].name.size,
				pp.tags[i].name.data,
				fixed_array::size(pp.tags) == i + 1 ? 0 : 2, ", "
			);
		}
		TOGO_LOG("]\n\n");

		auto const type_hash = resource::hash_type(type);
		auto const name_hash = resource::hash_name(name);
		TOGO_ASSERTE(type_hash == pp.type_hash);
		TOGO_ASSERTE(string::compare_equal(type, pp.type));
		TOGO_ASSERTE(name_hash == pp.name_hash);
		TOGO_ASSERTE(string::compare_equal(name, pp.name));
		TOGO_ASSERTE(
			fixed_array::empty(pp.tags) ==
			(pp.tags_hash == RES_TAGS_NULL)
		);

		for (unsigned i = 0; i < fixed_array::size(pp.tags); ++i) {
			auto const name = *(begin(tags) + i);
			auto const hash = hash::calc_generic<
				decltype(ResourcePathParts::Tag::hash)
			>(name);
			TOGO_ASSERTE(hash == pp.tags[i].hash);
			TOGO_ASSERTE(string::compare_equal(name, pp.tags[i].name));
		}
		TOGO_ASSERTE(fixed_array::size(pp.tags) == tags.size());
	}
	TOGO_ASSERTE(valid == expect_valid);
}<commit_msg>lib/game/test/resource/general: tidy.<commit_after>
#include <togo/core/error/assert.hpp>
#include <togo/core/utility/utility.hpp>
#include <togo/core/log/log.hpp>
#include <togo/core/collection/fixed_array.hpp>
#include <togo/core/string/string.hpp>
#include <togo/core/hash/hash.hpp>
#include <togo/game/resource/resource.hpp>

#include <initializer_list>

using namespace togo;
using namespace togo::game;

void test_path(
	ResourcePathParts& pp,
	StringRef const path,
	bool const expect_valid,
	StringRef const name,
	StringRef const type,
	std::initializer_list<StringRef> tags
) {
	bool const valid = resource::parse_path(path, pp);
	TOGO_LOGF("%s: '%.*s'\n", valid ? "valid  " : "invalid", path.size, path.data);
	if (valid) {
		TOGO_LOGF("  name: %016lx '%.*s'\n", pp.name_hash, pp.name.size, pp.name.data);
		TOGO_LOGF("  type: %08x%8s '%.*s'\n", pp.type_hash, "", pp.type.size, pp.type.data);
		TOGO_LOGF("  tags: %016lx [", pp.tags_hash);
		for (unsigned i = 0; i < fixed_array::size(pp.tags); ++i) {
			TOGO_LOGF(
				"%08x '%.*s'%.*s",
				pp.tags[i].hash,
				pp.tags[i].name.size,
				pp.tags[i].name.data,
				fixed_array::size(pp.tags) == i + 1 ? 0 : 2, ", "
			);
		}
		TOGO_LOG("]\n\n");

		auto const type_hash = resource::hash_type(type);
		auto const name_hash = resource::hash_name(name);
		TOGO_ASSERTE(type_hash == pp.type_hash);
		TOGO_ASSERTE(string::compare_equal(type, pp.type));
		TOGO_ASSERTE(name_hash == pp.name_hash);
		TOGO_ASSERTE(string::compare_equal(name, pp.name));
		TOGO_ASSERTE(
			fixed_array::empty(pp.tags) ==
			(pp.tags_hash == RES_TAGS_NULL)
		);

		for (unsigned i = 0; i < fixed_array::size(pp.tags); ++i) {
			auto const name = *(begin(tags) + i);
			auto const hash = hash::calc_generic<
				decltype(ResourcePathParts::Tag::hash)
			>(name);
			TOGO_ASSERTE(hash == pp.tags[i].hash);
			TOGO_ASSERTE(string::compare_equal(name, pp.tags[i].name));
		}
		TOGO_ASSERTE(fixed_array::size(pp.tags) == tags.size());
	}
	TOGO_ASSERTE(valid == expect_valid);
}
{'fraction_non_alphanumeric': 0.18459229614807404, 'fraction_numerical': 0.009004502251125562, 'mean_word_length': 4.577405857740586, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 23, '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': '3084839', 'n_tokens_mistral': 1750, 'n_tokens_neox': 1609, 'n_words': 277}