<commit_before>#include "../catch.hpp"
#include "../../Engine/Kernel.h"
#include "../../Engine/Components/CompScript.h"
#include "../../Engine/LuaInterface.h"
#include "../../Engine/Defines.h"
#include "../mocks/GameStateMock.h"
#include "../mocks/RSC_MapMock.h"

std::string lastError = "";
EID lastErrorID = 0;
void luaErrorCallback (EID id, const std::string& error){
	lastErrorID = id;
	lastError = error;
}

TEST_CASE("Lua Interface can be instantiated", "[lua][lua_interface]"){
	Kernel::Inst();

	auto stateManager = &K_StateMan;
	auto stateAuto = make_unique<GameStateMock>(stateManager);
	auto state = stateAuto.get();
	stateManager->PushState(std::move(stateAuto));

	auto scriptMan = state->GetComponentManagerScript();
	auto posMan = state->GetComponentManagerPosition();
	auto eid = 20;

	//pos comp is prereq to having scipt comp
	posMan->AddComponent(eid);
	//script comp is prereq to luaInterface creating an entity instance
	scriptMan->AddComponent(eid);

	auto luaInterface = state->GetLuaInterface();
	luaInterface->SetErrorCallbackFunction(luaErrorCallback);
	auto scriptName = "Testing/cppLuaInterfaceTest.lua";
	auto script = RSC_Script::LoadResource(scriptName);
	REQUIRE(script.get() != NULL);

	auto mapDepth= 10;
	auto parent = 0;
	auto scriptType = "TEST";
	luaInterface->RunScript(eid, script.get(), mapDepth, parent, scriptName, scriptType, NULL,NULL);

	REQUIRE(lastError == "Interface Working");

	SECTION("Ensure Input events are properly handled"){
		//script should register to listen for 'up' and 'down'
		//correct key is 'up'
		//incorrect key is 'down'
		//all else will be ignored
		auto keyPressed = "up";
		auto incorrectKey = "down";
		auto ignoredKey = "blarg"; 

		//This should not trigger any new error messages; lastError should not change by pressing a key
		auto previousErrorMessage = lastError;
		stateManager->input.SimulateKeyPress(ignoredKey);	
		REQUIRE(lastError == previousErrorMessage);

		stateManager->input.SimulateKeyPress(incorrectKey);	
		REQUIRE(lastError == "KeyPress: Incorrect Input");

		stateManager->input.SimulateKeyPress(keyPressed);	
		REQUIRE(lastError == "KeyPress: Correct Input");


		previousErrorMessage = lastError;
		stateManager->input.SimulateKeyRelease(ignoredKey);	
		REQUIRE(lastError == previousErrorMessage);

		stateManager->input.SimulateKeyRelease(incorrectKey);	
		REQUIRE(lastError == "KeyRelease: Incorrect Input");

		stateManager->input.SimulateKeyRelease(keyPressed);	
		REQUIRE(lastError == "KeyRelease: Correct Input");
	}

	SECTION("Ensure that the LEngine module is correctly loaded"){
		auto scriptComponent = (ComponentScript*) scriptMan->GetComponent(eid);

		std::string mapDepthString = "10";
		std::string parentString = "0";
		std::stringstream eidString;
		eidString << eid;

		scriptComponent->RunFunction("PrintDepth");
		REQUIRE(lastError == mapDepthString);

		scriptComponent->RunFunction("PrintParent");
		REQUIRE(lastError == parentString);

		scriptComponent->RunFunction("PrintEID");
		REQUIRE(lastError == eidString.str());

		scriptComponent->RunFunction("PrintName");
		REQUIRE(lastError == scriptName);<commit_msg>Unit Tests passing<commit_after>#include "../catch.hpp"
#include "../../Engine/Kernel.h"
#include "../../Engine/Components/CompScript.h"
#include "../../Engine/LuaInterface.h"
#include "../../Engine/Defines.h"
#include "../mocks/GameStateMock.h"
#include "../mocks/RSC_MapMock.h"

std::string lastError = "";
EID lastErrorID = 0;
void luaErrorCallback (EID id, const std::string& error){
	lastErrorID = id;
	lastError = error;
}

TEST_CASE("Lua Interface can be instantiated", "[lua][lua_interface]"){
	Kernel::Inst();

	auto stateManager = &K_StateMan;
	auto stateAuto = make_unique<GameStateMock>(stateManager);
	auto state = stateAuto.get();
	stateManager->PushState(std::move(stateAuto));

	auto scriptMan = state->GetComponentManagerScript();
	auto posMan = state->GetComponentManagerPosition();
	auto eid = 20;

	//pos comp is prereq to having scipt comp
	posMan->AddComponent(eid);
	//script comp is prereq to luaInterface creating an entity instance
	scriptMan->AddComponent(eid);

	auto luaInterface = state->GetLuaInterface();
	luaInterface->SetErrorCallbackFunction(luaErrorCallback);
	auto scriptName = "Testing/cppLuaInterfaceTest.lua";
	auto script = RSC_Script::LoadResource(scriptName);
	REQUIRE(script.get() != NULL);

	auto mapDepth= 10;
	auto parent = 0;
	auto scriptType = "TEST";
	luaInterface->RunScript(eid, script.get(), mapDepth, parent, scriptName, scriptType, NULL,NULL);

	REQUIRE(lastError == "Interface Working");

	SECTION("Ensure Input events are properly handled"){
		//script should register to listen for 'up' and 'down'
		//correct key is 'up'
		//incorrect key is 'down'
		//all else will be ignored
		auto keyPressed = "up";
		auto incorrectKey = "down";
		auto ignoredKey = "blarg"; 

		//This should not trigger any new error messages; lastError should not change by pressing a key
		auto previousErrorMessage = lastError;
		stateManager->inputManager->SimulateKeyPress(ignoredKey);	
		REQUIRE(lastError == previousErrorMessage);

		stateManager->inputManager->SimulateKeyPress(incorrectKey);	
		REQUIRE(lastError == "KeyPress: Incorrect Input");

		stateManager->inputManager->SimulateKeyPress(keyPressed);	
		REQUIRE(lastError == "KeyPress: Correct Input");


		previousErrorMessage = lastError;
		stateManager->inputManager->SimulateKeyRelease(ignoredKey);	
		REQUIRE(lastError == previousErrorMessage);

		stateManager->inputManager->SimulateKeyRelease(incorrectKey);	
		REQUIRE(lastError == "KeyRelease: Incorrect Input");

		stateManager->inputManager->SimulateKeyRelease(keyPressed);	
		REQUIRE(lastError == "KeyRelease: Correct Input");
	}

	SECTION("Ensure that the LEngine module is correctly loaded"){
		auto scriptComponent = (ComponentScript*) scriptMan->GetComponent(eid);

		std::string mapDepthString = "10";
		std::string parentString = "0";
		std::stringstream eidString;
		eidString << eid;

		scriptComponent->RunFunction("PrintDepth");
		REQUIRE(lastError == mapDepthString);

		scriptComponent->RunFunction("PrintParent");
		REQUIRE(lastError == parentString);

		scriptComponent->RunFunction("PrintEID");
		REQUIRE(lastError == eidString.str());

		scriptComponent->RunFunction("PrintName");
		REQUIRE(lastError == scriptName);
{'fraction_non_alphanumeric': 0.13434487118697644, 'fraction_numerical': 0.002844950213371266, 'mean_word_length': 5.557512953367875, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 49, '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': '1663328', 'n_tokens_mistral': 2027, 'n_tokens_neox': 1920, 'n_words': 451}