-
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathLookaheadSafe.cpp
More file actions
49 lines (44 loc) · 1.32 KB
/
LookaheadSafe.cpp
File metadata and controls
49 lines (44 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "catch.hpp"
#include <../runner_impl.h>
#include <compiler.h>
#include <globals.h>
#include <runner.h>
#include <story.h>
using namespace ink::runtime;
SCENARIO("a story with external functions and glue", "[external]")
{
GIVEN("the story")
{
std::unique_ptr<story> ink{story::from_file(INK_TEST_RESOURCE_DIR "LookaheadSafe.bin")};
int cnt = 0;
auto foo = [&cnt]() {
cnt += 1;
};
WHEN("the external function is safe for look-ahead")
{
auto thread = ink->new_runner().cast<internal::runner_impl>();
std::stringstream commands;
thread->set_debug_enabled(&commands);
thread->bind("foo", foo, true);
CHECK(thread->getline() == "Call1 glued to Call 2\n");
std::string c = commands.str();
CHECK(cnt == 3);
REQUIRE(thread->getline() == "Call 3 is separated\n");
CHECK(cnt == 4);
}
WHEN("the external function is unsafe for look-ahead")
{
auto thread = ink->new_runner().cast<internal::runner_impl>();
std::stringstream commands;
thread->set_debug_enabled(&commands);
thread->bind("foo", foo, false);
CHECK(thread->getline() == "Call1\n");
std::string c = commands.str();
CHECK(cnt == 1);
CHECK(thread->getline() == "glued to Call 2\n");
CHECK(cnt == 2);
CHECK(thread->getline() == "Call 3 is separated\n");
CHECK(cnt == 3);
}
}
}