compilation.cpp
No OneTemporary

File Metadata

Created
Wed, Jul 8, 9:48 PM

compilation.cpp

#include "passmanager.h"
#include "gtest/gtest.h"
using namespace xreate;
//DEBT implement no pkgconfig ways to link libs
//TOTEST FunctionUnit::compileInline
TEST(Compilation, DISABLED_functionInline1){
}
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, Sequence2){
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"
" context:: expectNoErrors. "
" buf1 = \"aaaaa\"::string.\n"
" buf2 = \"aaaaa\"::string.\n"
" sequence ["
" sprintf(buf1, \"%d\", system(\"bazaar --version\")),"
" sprintf(buf2, \"%d\", system(\"svn --version\")),"
" printf(buf1),\n"
" printf(buf2)\n"
"]"
"}"
);
int (*main)() = (int (*)()) man->run();
main();
}
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));
}

Event Timeline