Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for space after bracket choice. #64

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
submodules: true

# Download inklecate
- uses: suisei-cn/actions-download-file@v1
- uses: suisei-cn/actions-download-file@v1.4.0
name: Download Inklecate
id: download_inklecate
with:
Expand All @@ -62,7 +62,7 @@ jobs:

# Setup CMake
- name: Setup cmake
uses: jwlawson/actions-setup-cmake@v1.9
uses: jwlawson/actions-setup-cmake@v1.14.2
with:
cmake-version: '3.21.x'

Expand Down Expand Up @@ -144,7 +144,7 @@ jobs:
shell: bash
working-directory: proofing/ink-proof
run: |
python3 proof.py --examples 'I...' inkcpp inklecate_v0.9.0 > run.out
python3 proof.py --examples 'I...' inklecate_v1.1.1 inkcpp_runtime > run.out
echo -e "| ${{ matrix.name }} | $(cat run.out) |" > ${{ matrix.artifact }}.txt

# Creates a "disabled" artifact if ink proofing is disabled
Expand Down Expand Up @@ -172,11 +172,17 @@ jobs:

reporting:
name: "Pull Request Report"
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository }}
# if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'brwarner/inkcpp' }}
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'master' }}
runs-on: ubuntu-latest
needs: compilation
permissions:
pull-requests: write
steps:
# Download Ink Proof Results
- name: Debug
run: |
echo ${{github.event_name}} ${{github.event.pull_request.head.repo.full_name}} ${{github.event.pull_request.head.ref}} ${{github.event.pull_request.base.full_name}} ${{github.event.pull_request.base.ref}}
- uses: actions/download-artifact@v2
with:
name: results
Expand All @@ -200,7 +206,7 @@ jobs:
done

# Post Comment
- uses: marocchino/sticky-pull-request-comment@v2
- uses: marocchino/sticky-pull-request-comment@v2.8.0
with:
recreate: true
path: comment.txt
Expand Down
6 changes: 6 additions & 0 deletions inkcpp/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ namespace ink::runtime::internal {
}
}

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

const T& operator[]( size_t i ) const { return data()[i]; }
T& operator[]( size_t i ) { return data()[i]; }
const T* data() const
Expand Down
8 changes: 6 additions & 2 deletions inkcpp/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,12 @@ namespace ink::runtime::internal
std::string result = str.str();
if ( !result.empty() ) {
auto end = clean_string<true, false>( result.begin(), result.end() );
_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;
}
Expand Down
2 changes: 1 addition & 1 deletion inkcpp/runner_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ namespace ink::runtime::internal

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

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;
}
}
}
5 changes: 2 additions & 3 deletions inkcpp_cl/inkcpp_cl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ int main(int argc, const char** argv)
using namespace ink::runtime;

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

// Start runner
runner thread;
Expand Down Expand Up @@ -213,12 +213,11 @@ int main(int argc, const char** argv)
// out of content
break;
}

return 0;
}
catch (const std::exception& e)
{
std::cerr << "Unhandled ink runtime exception: " << e.what() << std::endl;
return 1;
}
return 0;
}
1 change: 1 addition & 0 deletions inkcpp_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ add_executable(inkcpp_test catch.hpp Main.cpp
LabelCondition.cpp
Observer.cpp
InkyJson.cpp
SpaceAfterBracketChoice.cpp
)

target_link_libraries(inkcpp_test PUBLIC inkcpp inkcpp_compiler inkcpp_shared)
Expand Down
48 changes: 48 additions & 0 deletions inkcpp_test/SpaceAfterBracketChoice.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +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());
}
}
}
}
}
7 changes: 7 additions & 0 deletions inkcpp_test/ink/ChoiceBracketStory.ink
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-> choices
= choices

+ [Choice 1]
+ [Choice 2]

- -> choices
2 changes: 1 addition & 1 deletion proofing/inkcpp_runtime_driver
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import shutil

ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PATH = os.path.join(ROOT, 'deps', 'inkcpp', 'inkcpp_cl')
ARGS = ["inkcpp_cl", "-p"] + sys.argv[1:]
ARGS = ["inkcpp_cl", "--ommit-choice-tags", "-p"] + sys.argv[1:]
os.execv(PATH, ARGS)
sleep(2)

Loading