-
-
Notifications
You must be signed in to change notification settings - Fork 21
Implemented Tags #26
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
Closed
Closed
Implemented Tags #26
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1a7802f
Implemented Tags
frantufro 62c7063
Add Tag printing to command line tool
JBenda 7395555
Make tag fetch functions const
JBenda d341269
Add tag behavior example
JBenda a9c2b10
Add test for tags
JBenda bff08dd
Add Null terminator for setting global strings
JBenda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ namespace ink | |
| "\n", | ||
| "<>", | ||
| "void", | ||
| "#", | ||
| "DIVERT", | ||
| "DIVERT_TO_VARIABLE", | ||
| "TUNNEL", | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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,96 @@ | ||
| #include "catch.hpp" | ||
| #include "../inkcpp_cl/test.h" | ||
|
|
||
| #include <story.h> | ||
| #include <globals.h> | ||
| #include <runner.h> | ||
| #include <compiler.h> | ||
| #include <choice.h> | ||
|
|
||
| using namespace ink::runtime; | ||
|
|
||
| SCENARIO("run story with tags", "[tags]") | ||
| { | ||
| GIVEN("a story with tags") | ||
| { | ||
| inklecate("ink/TagsStory.ink", "TagsStory.tmp"); | ||
| ink::compiler::run("TagsStory.tmp", "TagsStory.bin"); | ||
| auto ink = story::from_file("TagsStory.bin"); | ||
| runner thread = ink->new_runner(); | ||
| WHEN("start thread") | ||
| { | ||
| THEN("No tags") | ||
| { | ||
| REQUIRE(thread->has_tags() == false); | ||
| } | ||
| WHEN("approach first line") | ||
| { | ||
| std::string line = thread->getall(); | ||
| THEN("print no tags") | ||
| { | ||
| REQUIRE(line == "Hello\n"); | ||
| } | ||
| THEN("collect all previous Tags (global, knot, line) in correct order") | ||
| { | ||
| REQUIRE(thread->has_tags() == true); | ||
| REQUIRE(thread->num_tags() == 4); | ||
| REQUIRE(std::string(thread->get_tag(0)) == "global_tag"); | ||
| REQUIRE(std::string(thread->get_tag(1)) == "knot_tag_start"); | ||
| REQUIRE(std::string(thread->get_tag(2)) == "second_knot_tag_start"); | ||
| REQUIRE(std::string(thread->get_tag(3)) == "output_tag_h"); | ||
| } | ||
| WHEN("print choices") | ||
| { | ||
| auto itr = thread->begin(); | ||
| std::string choices[2] = { | ||
| (itr++)->text(), | ||
| (itr++)->text() | ||
| }; | ||
| THEN("choices won't print tags, tags are still the same") | ||
| { | ||
| REQUIRE(choices[0] == "a"); | ||
| REQUIRE(choices[1] == "b"); | ||
| REQUIRE(thread->has_tags() == true); | ||
| REQUIRE(thread->num_tags() == 4); | ||
| REQUIRE(std::string(thread->get_tag(0)) == "global_tag"); | ||
| REQUIRE(std::string(thread->get_tag(1)) == "knot_tag_start"); | ||
| REQUIRE(std::string(thread->get_tag(2)) == "second_knot_tag_start"); | ||
| REQUIRE(std::string(thread->get_tag(3)) == "output_tag_h"); | ||
| } | ||
| WHEN("choose divert") | ||
| { | ||
| thread->choose(1); | ||
| THEN("choosing won't add tags!") | ||
| { | ||
| REQUIRE(thread->has_tags() == false); | ||
| REQUIRE(thread->num_tags() == 0); | ||
| } | ||
| WHEN("proceed") | ||
| { | ||
| std::string line = thread->getline(); | ||
| THEN("new knot tag and now line tag, also choice tag. AND dont print tag in choice") | ||
| { | ||
| REQUIRE(line == "bKnot2\n"); | ||
| REQUIRE(thread->has_tags() == true); | ||
| REQUIRE(thread->num_tags() == 3); | ||
| REQUIRE(std::string(thread->get_tag(0)) == "choice_tag_b"); | ||
| REQUIRE(std::string(thread->get_tag(1)) == "knot_tag_2"); | ||
| REQUIRE(std::string(thread->get_tag(2)) == "output_tag_k"); | ||
| } | ||
| WHEN("choose choice without tag, and proceed to end") | ||
| { | ||
| thread->choose(0); | ||
| thread->getline(); | ||
| THEN("no tags, tags behind END are ignored") | ||
| { | ||
| REQUIRE(thread->has_tags() == false); | ||
| REQUIRE(thread->num_tags() == 0); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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,21 @@ | ||
| # global_tag | ||
| ->start | ||
| ===start | ||
| # knot_tag_start | ||
| # second_knot_tag_start | ||
|
|
||
| Hello # output_tag_h | ||
| * a | ||
| * b->knot2 # choice_tag_b | ||
| - World! # output_tag_w | ||
| * c # choice_tag_c | ||
| * d # choice_tag_d | ||
| - ->END | ||
|
|
||
| ===knot2 | ||
| # knot_tag_2 | ||
|
|
||
| Knot2 # output_tag_k | ||
| * e | ||
| * f # choice_tag_f | ||
| - out->END # close_tag |
This file contains hidden or 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,24 @@ | ||
| Tags are accessible via runner functions: | ||
|
|
||
| - `bool has_tags()` are there any tags now? | ||
| - `size_t num_tags()` how many tags are there right now? | ||
| - `const char* get_tag(size_t i)` get string value of tag | ||
|
|
||
| Tags are acquired until a choice appears. After choosing the acquired tags will | ||
| be cleared. | ||
| ``` | ||
| # Tag1 | ||
| # Tag 2 | ||
| Some Text # Tag3 | ||
| * A # Tag 4 | ||
| * B # Tag 5 | ||
| - out # Tag6 | ||
| ``` | ||
|
|
||
| Will produce: | ||
| > Some Text: Tag1, Tag2, Tag3 | ||
| > * A | ||
| > * B | ||
| > <1 | ||
| > A | ||
| > out: Tag4, Tag6 |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ namespace ink | |
| NEWLINE, | ||
| GLUE, | ||
| VOID, | ||
| TAG, | ||
|
|
||
| // == Diverts | ||
| DIVERT, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to investigate this before I approve. Just to make sure...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, this actually needs to be true and the fact it's failing means there's another issue. With your change, the CNT? command actually won't work anymore because it's expecting an index in the container visits table, not the actual byte offset of the container in the instruction data. Can you create a new issue in GitHub with the failing file and the error message?