<commit_before>#include "static-strings.hpp"
#include <cassert>
#include <type_traits>

struct EMPTY {
	constexpr static const char* str() {
		return "";
	}
};

struct Hello {
	constexpr static const char* str() {
		return "Hello ";
	}
};

struct World {
	constexpr static const char* str() {
		return "World";
	}
};

struct Exclamation {
	constexpr static const char* str() {
		return "!";
	}
};


using E = static_string::from_provider<EMPTY>;
using H = static_string::from_provider<Hello>;
using W = static_string::from_provider<World>;


void testBasics() {
	assert(E::size == 0);
	assert(E::string() == "");

	assert(H::size == 6);
	assert(H::string() == "Hello ");

	assert(W::size == 5);
	assert(W::string() == "World");
}


void testConcat() {
	using HW = static_string::concat<H, W>;
	using X = static_string::concat<H, W, static_string::from_provider<Exclamation>>;

	assert(HW::size == 11);
	assert(HW::string() == "Hello World");

	assert(X::size == 12);
	assert(X::string() == "Hello World!");
}


void testCharTypes() {
	struct    World { constexpr static const     char* str() { return  "World"; } };
	struct   WWorld { constexpr static const  wchar_t* str() { return L"World"; } };
	struct U16World { constexpr static const char16_t* str() { return u"World"; } };
	struct U32World { constexpr static const char32_t* str() { return U"World"; } };

	using W   = static_string::from_provider<   World>;
	using WW  = static_string::from_provider<  WWorld>;
	using W16 = static_string::from_provider<U16World>;
	using W32 = static_string::from_provider<U32World>;

	assert((std::is_same<decltype(  W::string()),    std::string>::value));
	assert((std::is_same<decltype( WW::string()),   std::wstring>::value));
	assert((std::is_same<decltype(W16::string()), std::u16string>::value));
	assert((std::is_same<decltype(W32::string()), std::u32string>::value));

	assert(  W::string() ==  "World");
	assert( WW::string() == L"World");
	assert(W16::string() == u"World");
	assert(W32::string() == U"World");

	assert((std::is_same<  W::char_type,     char>::value));
	assert((std::is_same< WW::char_type,  wchar_t>::value));
	assert((std::is_same<W16::char_type, char16_t>::value));
	assert((std::is_same<W32::char_type, char32_t>::value));

	assert((std::is_same<  W::string_type,    std::string>::value));
	assert((std::is_same< WW::string_type,   std::wstring>::value));
	assert((std::is_same<W16::string_type, std::u16string>::value));
	assert((std::is_same<W32::string_type, std::u32string>::value));
}


void testExplicitSize() {
	struct World {
		enum { size = 11 };
		constexpr static const char* str() {
			return  "Hello\0World";
		}
	};

	using HW1 = static_string::from_provider<World>;
	using HW2 = static_string::from_provider<World, 7>;

	assert(HW1::size == 11);
	assert(HW2::size == 7);

	assert(HW1::string() == std::string("Hello") + '\0' + "World");
	assert(HW2::string() == std::string("Hello") + '\0' + 'W');
}


int main() {
	testBasics();
	testConcat();
	testCharTypes();
	testExplicitSize();
}
<commit_msg>static-strings: Include tests for building of static strings with individual chars<commit_after>#include "static-strings.hpp"
#include <cassert>
#include <type_traits>


void testBuildingWithIndividualChars() {
	using Empty = static_string::static_string<char>;
	assert(Empty::size == 0);
	assert(Empty::string() == "");

	using Hello = static_string::static_string<char, 'H', 'e', 'l', 'l', 'o'>;
	assert(Hello::size == 5);
	assert(Hello::string() == "Hello");
}


void testBuildingWithStringProviders() {
	struct EmptyStrProvider {
		constexpr static const char* str() {
			return "";
		}
	};
	using Empty = static_string::from_provider<EmptyStrProvider>;
	assert(Empty::size == 0);
	assert(Empty::string() == "");

	struct HelloStrProvider {
		constexpr static const char* str() {
			return "Hello";
		}
	};
	using Hello = static_string::from_provider<HelloStrProvider>;
	assert(Hello::size == 5);
	assert(Hello::string() == "Hello");
}


void testConcat() {
	struct EmptyStrProvider { constexpr static const char* str() { return ""; } };
	struct WorldStrProvider { constexpr static const char* str() { return "World"; } };

	using Hello = static_string::static_string<char, 'H', 'e', 'l', 'l', 'o', ' '>;
	using Empty = static_string::from_provider<EmptyStrProvider>;
	using World = static_string::from_provider<WorldStrProvider>;

	using HelloWorld1 = static_string::concat<Hello, World>;
	assert(HelloWorld1::size == 11);
	assert(HelloWorld1::string() == "Hello World");

	using HelloWorld2 = static_string::concat<Hello, Empty, World>;
	assert(HelloWorld2::size == 11);
	assert(HelloWorld2::string() == "Hello World");
}


void testCharTypes() {
	struct    World { constexpr static const     char* str() { return  "World"; } };
	struct   WWorld { constexpr static const  wchar_t* str() { return L"World"; } };
	struct U16World { constexpr static const char16_t* str() { return u"World"; } };
	struct U32World { constexpr static const char32_t* str() { return U"World"; } };

	using W   = static_string::from_provider<   World>;
	using WW  = static_string::from_provider<  WWorld>;
	using W16 = static_string::from_provider<U16World>;
	using W32 = static_string::from_provider<U32World>;

	assert((std::is_same<decltype(  W::string()),    std::string>::value));
	assert((std::is_same<decltype( WW::string()),   std::wstring>::value));
	assert((std::is_same<decltype(W16::string()), std::u16string>::value));
	assert((std::is_same<decltype(W32::string()), std::u32string>::value));

	assert(  W::string() ==  "World");
	assert( WW::string() == L"World");
	assert(W16::string() == u"World");
	assert(W32::string() == U"World");

	assert((std::is_same<  W::char_type,     char>::value));
	assert((std::is_same< WW::char_type,  wchar_t>::value));
	assert((std::is_same<W16::char_type, char16_t>::value));
	assert((std::is_same<W32::char_type, char32_t>::value));

	assert((std::is_same<  W::string_type,    std::string>::value));
	assert((std::is_same< WW::string_type,   std::wstring>::value));
	assert((std::is_same<W16::string_type, std::u16string>::value));
	assert((std::is_same<W32::string_type, std::u32string>::value));
}


void testStringProviderWithExplicitSize() {
	struct World {
		enum { size = 11 };
		constexpr static const char* str() {
			return  "Hello\0World";
		}
	};

	using HelloWorld = static_string::from_provider<World>;
	using HelloW     = static_string::from_provider<World, 7>;

	assert(HelloWorld::size == 11);
	assert(    HelloW::size == 7);

	assert(HelloWorld::string() == std::string("Hello") + '\0' + "World");
	assert(    HelloW::string() == std::string("Hello") + '\0' + 'W');
}


int main() {
	testBuildingWithIndividualChars();
	testBuildingWithStringProviders();
	testConcat();
	testCharTypes();
	testStringProviderWithExplicitSize();
}

{'fraction_non_alphanumeric': 0.19283827414147345, 'fraction_numerical': 0.01951863809803346, 'mean_word_length': 6.084199584199585, 'pattern_counts': {'":': 0, '<': 58, '<?xml version=': 0, '>': 58, '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': '2542552', 'n_tokens_mistral': 2485, 'n_tokens_neox': 2312, 'n_words': 468}