unit-test-example.cpp
No OneTemporary

File Metadata

Created
Thu, Jul 9, 3:56 AM

unit-test-example.cpp

#include "xreatemanager.h" //main Xreate header
#include "transcendlayer.h"
#include <gtest/gtest.h>
using namespace xreate;
using namespace std;
TEST(Example, Example1){
//Your custom transcend rules if any
string rules =
R"SCRIPT(
bind_func(sum, entry).
)SCRIPT";
//Your custom program
string example =
R"CODE(
//Custom code
sum = function(a:: int, b:: int):: int
{
a + b
}
)CODE";
//Initialize compiler
unique_ptr<XreateManager> man(XreateManager::prepare(move(example)));
//Add transcend part:
man->transcend->addRawScript(move(rules));
//Define signature of your entry function:
typedef int (*ENTRYFN)(int, int);
//Compile the example and get a pointer to the entry function:
ENTRYFN yourEntryFn = (ENTRYFN) man->run();
//Now execute function and check the result
int resultActual = yourEntryFn(5, 7);
int resultExpected = 5 + 7;
ASSERT_EQ(resultExpected, resultActual);
}

Event Timeline