#include "passmanager.h"
#include "gtest/gtest.h"
using namespace xreate;

//TEST FunctionUnit::compileInline
TEST(Compilation, DISABLED_functionInline1){
}

//DEBT implement no pkgconfig ways to link libs
TEST(Compilation, Sequence1){
	PassManager* man = PassManager::prepareForCode(
			"interface(extern-c){\n"
			"  libFake = library:: pkgconfig(\"libxml-2.0\").\n"
			"  \n"
			"  include {\n"
			"    libFake = [\"stdio.h\", \"stdlib.h\"]\n"
			"  }.\n"
			"}"

			"main = function:: int; entry {\n"
			"	sequence ["
			"		printf(\"FIRST-\"),\n"
			"		printf(\">SECOND\")\n"
			"	]"
			"}"
	);

	int (*main)() = (int (*)()) man->run();

	testing::internal::CaptureStdout();
	main();
	std::string output = testing::internal::GetCapturedStdout();

	ASSERT_STREQ("FIRST->SECOND", output.c_str());
}

TEST(Compilation, full_IFStatementWithVariantType){
	PassManager* man = PassManager::prepareForCode(
		"COLORS = type variant (RED, BLUE, GREEN).\n"
		"\n"
		"	main = function(x::int):: int; entry {\n"
		"		color = if (x == 0 )::COLORS {RED} else {BLUE}.\n"
		"		if (color == BLUE)::int {1} else {0}\n"
		"	}"
	);

	int (*main)(int) = (int (*)(int)) man->run();
	ASSERT_EQ(0, main(0));
	ASSERT_EQ(1, main(1));
}

//			"main = function:: int; entry {\n"
//			"	context:: expectNoErrors.  "
//			"	buf1 = \"aaaaa\"::string.\n"
//			"	buf2 = \"aaaaa\"::string.\n"
//			"	sequence ["
//			"		sprintf(buf1, \"%d\", exec(\"bazaar --version\")),"
//			"		sprintf(buf2, \"%d\", exec(\"svn --version\")),"
//			"		printf(buf1),\n"
//			"		printf(buf2)\n"
//				"]"
//			"}"
