Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
JBenda committed Dec 15, 2023
1 parent 69765f1 commit b3cf913
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 119 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ SpaceAfterTemplateKeyword: false
SpaceAfterLogicalNot: true
SpaceAfterCStyleCast: true
SortUsingDeclarations: Lexicographic
SortIncludes: CaseInsensitive
SortIncludes: Never
ShortNamespaceLines: 0
SeparateDefinitionBlocks: Always
RequiresExpressionIndentation: OuterScope
Expand Down
15 changes: 8 additions & 7 deletions inkcpp/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ namespace ink::runtime::internal {
{
_dynamic_data = new T[initialCapacity];
}
}
}

~managed_array() {
if constexpr (dynamic) {
delete[] _dynamic_data;
}
}
~managed_array()
{
if constexpr (dynamic) {
delete[] _dynamic_data;
}
}

const T& operator[]( size_t i ) const { return data()[i]; }
const T& operator[]( size_t i ) const { return data()[i]; }
T& operator[]( size_t i ) { return data()[i]; }
const T* data() const
{
Expand Down
14 changes: 7 additions & 7 deletions inkcpp/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ namespace ink::runtime::internal
std::string result = str.str();
if ( !result.empty() ) {
auto end = clean_string<true, false>( result.begin(), result.end() );
if (result.begin() == end) {
result.resize(0);
} else {
_last_char = *( end - 1 );
result.resize( end - result.begin() - ( _last_char == ' ' ? 1 : 0 ) );
}
}
if (result.begin() == end) {
result.resize(0);
} else {
_last_char = *(end - 1);
result.resize(end - result.begin() - (_last_char == ' ' ? 1 : 0));
}
}
return result;
}
#endif
Expand Down
25 changes: 13 additions & 12 deletions inkcpp/runner_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,15 @@ namespace ink::runtime::internal
// without entering any other containers
// OR IF if target is same position do nothing
// could happend if jumping to and of an unnamed container
if (dest ==_ptr)
{
_ptr = dest;
if (dest == _ptr) {
_ptr = dest;
return;
}
}

const uint32_t* iter = nullptr;
const uint32_t* iter = nullptr;
container_t id;
ip_t offset = nullptr;
size_t comm_end;
ip_t offset = nullptr;
size_t comm_end;
bool reversed = _ptr > dest;

if (reversed) {
Expand Down Expand Up @@ -1172,14 +1171,16 @@ namespace ink::runtime::internal
} break;
case Command::END_CONTAINER_MARKER:
{
container_t index = read<container_t>();
container_t index = read<container_t>();

inkAssert(_container.top().id == index, "Leaving container we are not in!");
inkAssert(
_container.top().id == index, "Leaving container we are not in!"
);

// Move up out of the current container
_container.pop();
// Move up out of the current container
_container.pop();

// SPECIAL: If we've popped all containers, then there's an implied 'done' command or return
// SPECIAL: If we've popped all containers, then there's an implied 'done' command or return
if (_container.empty())
{
_is_falling = false;
Expand Down
2 changes: 1 addition & 1 deletion inkcpp/story_ptr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ namespace ink::runtime::internal
_instance_block = _story_block = nullptr;
return is_destroyed;
}
}
} // namespace ink::runtime::internal
10 changes: 5 additions & 5 deletions inkcpp_cl/inkcpp_cl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ int main(int argc, const char** argv)
using namespace ink::runtime;

// Load story
std::unique_ptr<story> myInk{story::from_file(outputFilename.c_str())};
std::unique_ptr<story> myInk{story::from_file(outputFilename.c_str())};

// Start runner
// Start runner
runner thread;
if (snapshotFile.size()) {
auto snap_ptr = snapshot::from_file( snapshotFile.c_str() );
Expand Down Expand Up @@ -212,12 +212,12 @@ int main(int argc, const char** argv)

// out of content
break;
}
}
}
}
catch (const std::exception& e)
{
std::cerr << "Unhandled ink runtime exception: " << e.what() << std::endl;
return 1;
}
return 0;
return 0;
}
96 changes: 48 additions & 48 deletions inkcpp_test/SpaceAfterBracketChoice.cpp
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
#include "catch.hpp"
#include "../inkcpp_cl/test.h"

#include <story.h>
#include <globals.h>
#include <runner.h>
#include <compiler.h>

using namespace ink::runtime;

SCENARIO("a story with bracketed choices and spaces can choose correctly", "[choices]")
{
GIVEN("a story with line breaks")
{
inklecate("ink/ChoiceBracketStory.ink", "ChoiceBracketStory.tmp");
ink::compiler::run("ChoiceBracketStory.tmp", "ChoiceBracketStory.bin");
auto ink = story::from_file("ChoiceBracketStory.bin");
runner thread = ink->new_runner();
thread->getall();
WHEN("start thread")
{
THEN("thread has choices")
{
thread->getall();
REQUIRE(thread->has_choices());
}
WHEN("choose choice 1")
{
thread->choose(0);
thread->getall();
THEN("still has choices")
{
thread->getall();
REQUIRE(thread->has_choices());
}
}
WHEN("choose choice 2")
{
thread->choose(1);
thread->getall();
THEN("still has choices")
{
REQUIRE(thread->has_choices());
}
}
}
}
}
#include "catch.hpp"
#include "../inkcpp_cl/test.h"

#include <story.h>
#include <globals.h>
#include <runner.h>
#include <compiler.h>

using namespace ink::runtime;

SCENARIO("a story with bracketed choices and spaces can choose correctly", "[choices]")
{
GIVEN("a story with line breaks")
{
inklecate("ink/ChoiceBracketStory.ink", "ChoiceBracketStory.tmp");
ink::compiler::run("ChoiceBracketStory.tmp", "ChoiceBracketStory.bin");
auto ink = story::from_file("ChoiceBracketStory.bin");
runner thread = ink->new_runner();
thread->getall();
WHEN("start thread")
{
THEN("thread has choices")
{
thread->getall();
REQUIRE(thread->has_choices());
}
WHEN("choose choice 1")
{
thread->choose(0);
thread->getall();
THEN("still has choices")
{
thread->getall();
REQUIRE(thread->has_choices());
}
}
WHEN("choose choice 2")
{
thread->choose(1);
thread->getall();
THEN("still has choices")
{
REQUIRE(thread->has_choices());
}
}
}
}
}
81 changes: 43 additions & 38 deletions inkcpp_test/ThirdTierChoiceAfterBrackets.cpp
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
#include "catch.hpp"
#include "../inkcpp_cl/test.h"

#include <story.h>
#include <globals.h>
#include <runner.h>
#include <compiler.h>

using namespace ink::runtime;

SCENARIO("a story with a bracketed choice as a second choice, and then a third choice, chooses properly", "[choices]")
{
GIVEN("a story with brackets and nested choices")
{
inklecate("ink/ThirdTierChoiceAfterBracketsStory.ink", "ThirdTierChoiceAfterBracketsStory.tmp");
ink::compiler::run("ThirdTierChoiceAfterBracketsStory.tmp", "ThirdTierChoiceAfterBracketsStory.bin");
auto ink = story::from_file("ThirdTierChoiceAfterBracketsStory.bin");
runner thread = ink->new_runner();

WHEN("start thread")
{
THEN("thread doesn't error")
{
thread->getall();
thread->has_choices();
thread->choose(0);
thread->getall();
thread->has_choices();
thread->choose(0);
thread->getall();
thread->has_choices();
thread->choose(0);
thread->getall();
thread->has_choices();
}
}
}
}
#include "catch.hpp"
#include "../inkcpp_cl/test.h"

#include <story.h>
#include <globals.h>
#include <runner.h>
#include <compiler.h>

using namespace ink::runtime;

SCENARIO(
"a story with a bracketed choice as a second choice, and then a third choice, chooses properly",
"[choices]"
)
{
GIVEN("a story with brackets and nested choices")
{
inklecate("ink/ThirdTierChoiceAfterBracketsStory.ink", "ThirdTierChoiceAfterBracketsStory.tmp");
ink::compiler::run(
"ThirdTierChoiceAfterBracketsStory.tmp", "ThirdTierChoiceAfterBracketsStory.bin"
);
auto ink = story::from_file("ThirdTierChoiceAfterBracketsStory.bin");
runner thread = ink->new_runner();

WHEN("start thread")
{
THEN("thread doesn't error")
{
thread->getall();
thread->has_choices();
thread->choose(0);
thread->getall();
thread->has_choices();
thread->choose(0);
thread->getall();
thread->has_choices();
thread->choose(0);
thread->getall();
thread->has_choices();
}
}
}
}

0 comments on commit b3cf913

Please sign in to comment.