
#ifndef TESTS_UTILS_HPP
# define TESTS_UTILS_HPP


#include "colors.h"
#include <iostream>
#include <string>
#include <iomanip>		// std::setw()
#include <iterator>		// std::reverse_iterator
#include <utility>		// std::make_pair
#include <sstream>		// std::stringstream
#include <deque>
#include <vector>
#include <map>
#include <stack>

#include "tests_structs.hpp"


// defines
//                  ****************************************
# define TITLE(s)	std::cout << "\n" B_PURPLE #s RESET "\n\n";
# define VAL(n)		val<T>(n)
# define VALT(n)	val<T>(n)
# define VALU(n)	val<U>(n)
# define TOI(n)		toi<T>(n)
# define PRINT(n)	print<>(n, #n);
# define DELETE		delete_structs();


// prototypes
//            *********************************************
void add_to_list(std::string title, std::string type, A_test* test);
void delete_structs();


// global variables
//                  ***************************************
extern std::vector< std::vector<A_test*> >	test_list;
extern std::vector< mystruct* >				mem_list;


// adding each test to the list
//                              ***************************
#define TEST(f_name) TEST_V(f_name)

/*
*/

#define TEST_V(f_name) \
	template <class T> struct s_ ## f_name : public A_test\
		{ void func(); };\
	void f_name () {\
		add_to_list("", "", NULL);\
		add_to_list(#f_name, "int", new(s_ ## f_name <int>));\
		add_to_list(#f_name, "char", new(s_ ## f_name <char>));\
		add_to_list(#f_name, "std::string", new(s_ ## f_name <std::string>));\
		add_to_list(#f_name, "mystruct*", new(s_ ## f_name <mystruct*>));\
		}\
	template <class T>\
		void s_ ## f_name <T>::func()

#define TEST_M(f_name) \
	template <class T, class U> struct s_ ## f_name : public A_test\
		{ void func(); };\
	void f_name () {\
		add_to_list("", "", NULL);\
		add_to_list(#f_name, "char, int", new(s_ ## f_name <char, int>));\
		add_to_list(#f_name, "char, char", new(s_ ## f_name <char, char>));\
		add_to_list(#f_name, "char, std::string", new(s_ ## f_name <char, std::string>));\
		add_to_list(#f_name, "int, int", new(s_ ## f_name <int, int>));\
		add_to_list(#f_name, "int, char", new(s_ ## f_name <int, char>));\
		add_to_list(#f_name, "int, std::string", new(s_ ## f_name <int, std::string>));\
	}\
	template <class T, class U>\
		void s_ ## f_name <T, U>::func()
/*
		add_to_list(#f_name, "char, mystruct*", new(s_ ## f_name <char, mystruct*>));\
		add_to_list(#f_name, "int, mystruct*", new(s_ ## f_name <int, mystruct*>));\
*/


// templates get value
//                     *************************************
// specialization in header, make it inline :
// https://stackoverflow.com/questions/63529059/c-specialized-method-templates-produce-multiple-definition-errors
template <class T>
	T val(int n) { (void)n; return (T()); }
template <>
	inline	int val(int n) { return (n); }
template <>
	inline	char val(int n) {
	
	if (n <= 126 && n >= 33)
		return n;
	return (n % 94 + 33);
}
template <>
	inline	std::string val(int n) {

	std::string			str;
	std::stringstream	stream;

	stream << n;
	stream >> str;
	stream.clear();
	return (str);
}
template <>
	inline	mystruct* val(int n) {

	mystruct *s = new mystruct(n);
	mem_list.push_back(s);
	return ( s );
}
template <class T>
	T val(std::string str) { (void)str; return (T()); }
template <>
	inline	int val(std::string str) { int i = str[0]; return (val<int>(i)); }
template <>
	inline	char val(std::string str) { int i = str[0]; return (val<char>(i)); }
template <>
	inline	std::string val(std::string str) { return (str); }
template <>
	inline	mystruct* val(std::string str) { int i = str[0]; return (val<mystruct*>(i)); }


// templates to value
//                    **************************************
template <class T>
	int toi(T t) {(void)t; return (0);
}
template <>
	inline	int toi(int i) {return (i);
}
template <>
	inline	int toi(char c) {return (c);
}
template <>
	inline	int toi(std::string str) {

	int					i;
	std::stringstream	stream;

	stream << str;
	stream >> i;
	stream.clear();
	return (i);
}
template <>
	inline	int toi(mystruct* s) {

	return ( s->get_data()[0] );
}


#endif

