-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/fallbackfunctions' into feature/Unreal_fixes
- Loading branch information
Showing
15 changed files
with
189 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include "catch.hpp" | ||
#include "../inkcpp_cl/test.h" | ||
|
||
#include <system.h> | ||
#include <story.h> | ||
#include <runner.h> | ||
#include <globals.h> | ||
#include <compiler.h> | ||
|
||
#include <cmath> | ||
|
||
using namespace ink::runtime; | ||
|
||
SCENARIO("run a story with external function and fallback function", "[external function]") | ||
{ | ||
GIVEN("story with two external functions, one with fallback") | ||
{ | ||
inklecate("ink/FallBack.ink", "FallBack.tmp"); | ||
ink::compiler::run("FallBack.tmp", "FallBack.bin"); | ||
auto ink = story::from_file("FallBack.bin"); | ||
runner thread = ink->new_runner(); | ||
|
||
WHEN("bind both external functions") | ||
{ | ||
int cnt_sqrt = 0; | ||
auto fn_sqrt = [&cnt_sqrt](int x)->int{ ++cnt_sqrt; return sqrt(x); }; | ||
int cnt_greeting = 0; | ||
auto fn_greeting = [&cnt_greeting]()->const char*{++cnt_greeting; return "Hohooh"; }; | ||
|
||
thread->bind("sqrt", fn_sqrt); | ||
thread->bind("greeting", fn_greeting); | ||
|
||
std::string out; | ||
REQUIRE_NOTHROW(out = thread->getall()); | ||
THEN("Both function should be called the correct amount of times") | ||
{ | ||
REQUIRE(out == "Hohooh ! A small demonstraion of my power:\n4 * 4 = 16, stunning i would say\n"); | ||
REQUIRE(cnt_sqrt == 2); | ||
REQUIRE(cnt_greeting == 1); | ||
} | ||
} | ||
WHEN("only bind function without fallback") | ||
{ | ||
int cnt_sqrt = 0; | ||
auto fn_sqrt = [&cnt_sqrt](int x)->int{++cnt_sqrt; return sqrt(x); }; | ||
|
||
thread ->bind("sqrt", fn_sqrt); | ||
|
||
std::string out; | ||
REQUIRE_NOTHROW(out = thread->getall());; | ||
THEN("Sqrt should be falled twice, and uses default greeting") | ||
{ | ||
REQUIRE(out == "Hello ! A small demonstraion of my power:\n4 * 4 = 16, stunning i would say\n"); | ||
REQUIRE(cnt_sqrt == 2); | ||
} | ||
} | ||
WHEN("bind no function") | ||
{ | ||
std::string out; | ||
REQUIRE_THROWS_AS(out = thread->getall(), ink::ink_exception); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
-> Start | ||
|
||
EXTERNAL sqrt(x) | ||
|
||
EXTERNAL greeting() | ||
|
||
=== function greeting() === | ||
~ return "Hello" | ||
|
||
== Start == | ||
{greeting()} ! A small demonstraion of my power: | ||
{sqrt(16)} * {sqrt(16)} = 16, stunning i would say | ||
-> DONE |
Oops, something went wrong.