/*
 * TestLexer.cpp
 *
 *  Created on: Nov 4, 2012
 *      Author: attero
 */

#include "TestLexer.h"


TestLexer::TestLexer() {
	// TODO Auto-generated constructor stub

}

TestLexer::~TestLexer() {
	// TODO Auto-generated destructor stub
}

std::string TestLexer::all_tests()
{
	std::string test_report = "";

	mu_run_test(test_searching_keyword_for_not_keyword);
	mu_run_test(test_fake);
	mu_run_test(test_searching_keyword);
	mu_run_test(test_parsing_simple_token);
	mu_run_test(test_parsing_tricky_token);

	return test_report;
}

std::string TestLexer::test_fake()
{
	mu_assert("1 == 1", 1 == 1);
	return "";
}

std::string TestLexer::test_searching_keyword_for_not_keyword()
{
	mu_assert("Balloon is treated as a keyword.", !lexer.is_keyword("Balloon"));
	return "";
}

std::string TestLexer::test_searching_keyword()
{
	mu_assert("\"while\" isn't treated as keyword.", lexer.is_keyword("while"));
	return "";
}

std::string TestLexer::test_parsing_simple_token()
{
	std::string test_report = "";
	Token token = lexer.parse_token("buttocks^^").second;
	muu_assert(" buttocks isn't symbol token", token.type == t_symbol);
	muu_assert(" value isn't buttocks", token.value == "buttocks");
	return test_report;
}

std::string TestLexer::test_parsing_tricky_token()
{
	std::string test_report = "";
	Token token = lexer.parse_token("while_trhe#").second;
	muu_assert("while_trhe# not a symbol", token.type == t_symbol);
	muu_assert("value isn't while_trhe", token.value == "while_trhe");

	token = lexer.parse_token("1if").second;
	std::string rest_of_string = lexer.parse_token("1if").first;

	muu_assert("Isn\'t a number", token.type == t_invalid_token);
	muu_assert("Isn\'t equal 1if but ", token.value == "1if");
	muu_assert("Rest of string is crap", rest_of_string == "" );

	return test_report;
}
