<commit_before>#if defined(_MSC_VER)
	#include "stdafx.h"
#endif

#include "UnitTests.h"

#include "NULLC/nullc.h"
#include "NULLC/nullc_debug.h"

// Check that remote debug module compiles correctly
#if defined(_MSC_VER)
	#include "NULLC/nullc_remote.h"
#endif

#include "NULLC/ParseClass.h"

#include "NULLC/includes/file.h"
#include "NULLC/includes/math.h"
#include "NULLC/includes/vector.h"
#include "NULLC/includes/random.h"
#include "NULLC/includes/dynamic.h"
#include "NULLC/includes/gc.h"
#include "NULLC/includes/time.h"
#include "NULLC/includes/string.h"

#include "NULLC/includes/canvas.h"
#include "NULLC/includes/window.h"
#include "NULLC/includes/io.h"

#include "NULLC/includes/pugi.h"

#include "tests/TestBase.h"
#include "tests/TestSpeed.h"
#include "tests/TestCompileFail.h"
#include "tests/TestParseFail.h"
#include "tests/TestInterface.h"

#pragma warning(disable: 4127 4996)

//#define ALLOC_TOP_DOWN
//#define NO_CUSTOM_ALLOCATOR

void* testAlloc(int size)
{
#ifdef ALLOC_TOP_DOWN
	return VirtualAlloc(NULL, size + 128, MEM_COMMIT | MEM_TOP_DOWN, PAGE_READWRITE);
#else
	return (char*)malloc(size + 128) + 128;
#endif
}
void testDealloc(void* ptr)
{
	if(!ptr)
		return;
#ifdef ALLOC_TOP_DOWN
	VirtualFree((char*)ptr - 128, 0, MEM_RELEASE);
#else
	free((char*)ptr - 128);
#endif
}

nullres CompileFile(const char* fileName)
{
	static char content[64 * 1024];

	FILE *euler = fopen(fileName, "rb");
	fseek(euler, 0, SEEK_END);
	unsigned int textSize = ftell(euler);
	assert(textSize < 64 * 1024);
	fseek(euler, 0, SEEK_SET);
	fread(content, 1, textSize, euler);
	content[textSize] = 0;
	fclose(euler);

	return nullcCompile(content);
}

int RunTests(bool verbose, const void* (NCDECL *fileLoadFunc)(const char*, unsigned int*, int*), bool runSpeedTests)
{<commit_msg>tests: Added a simple memory block corruption check in the test allocator<commit_after>#if defined(_MSC_VER)
	#include "stdafx.h"
#endif

#include "UnitTests.h"

#include "NULLC/nullc.h"
#include "NULLC/nullc_debug.h"

// Check that remote debug module compiles correctly
#if defined(_MSC_VER)
	#include "NULLC/nullc_remote.h"
#endif

#include "NULLC/ParseClass.h"

#include "NULLC/includes/file.h"
#include "NULLC/includes/math.h"
#include "NULLC/includes/vector.h"
#include "NULLC/includes/random.h"
#include "NULLC/includes/dynamic.h"
#include "NULLC/includes/gc.h"
#include "NULLC/includes/time.h"
#include "NULLC/includes/string.h"

#include "NULLC/includes/canvas.h"
#include "NULLC/includes/window.h"
#include "NULLC/includes/io.h"

#include "NULLC/includes/pugi.h"

#include "tests/TestBase.h"
#include "tests/TestSpeed.h"
#include "tests/TestCompileFail.h"
#include "tests/TestParseFail.h"
#include "tests/TestInterface.h"

#pragma warning(disable: 4127 4996)

//#define ALLOC_TOP_DOWN
//#define NO_CUSTOM_ALLOCATOR

void* testAlloc(int size)
{
#ifdef ALLOC_TOP_DOWN
	return VirtualAlloc(NULL, size + 128, MEM_COMMIT | MEM_TOP_DOWN, PAGE_READWRITE);
#else
	char *ptr = (char*)malloc(size + 128);
	memset(ptr, 0xee, 128);
	return ptr + 128;
#endif
}
void testDealloc(void* ptr)
{
	if(!ptr)
		return;
#ifdef ALLOC_TOP_DOWN
	VirtualFree((char*)ptr - 128, 0, MEM_RELEASE);
#else
	ptr = (char*)ptr - 128;
	for(unsigned i = 0; i < 128; i++)
		assert(((unsigned char*)ptr)[i] == 0xee);
	free(ptr);
#endif
}

nullres CompileFile(const char* fileName)
{
	static char content[64 * 1024];

	FILE *euler = fopen(fileName, "rb");
	fseek(euler, 0, SEEK_END);
	unsigned int textSize = ftell(euler);
	assert(textSize < 64 * 1024);
	fseek(euler, 0, SEEK_SET);
	fread(content, 1, textSize, euler);
	content[textSize] = 0;
	fclose(euler);

	return nullcCompile(content);
}

int RunTests(bool verbose, const void* (NCDECL *fileLoadFunc)(const char*, unsigned int*, int*), bool runSpeedTests)
{
{'fraction_non_alphanumeric': 0.15039787798408488, 'fraction_numerical': 0.023607427055702918, 'mean_word_length': 5.639084507042254, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, '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': '4387635', 'n_tokens_mistral': 1552, 'n_tokens_neox': 1443, 'n_words': 322}