Skip to content

feat: support legacy tag #31

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions src/main/java/com/bladecoder/ink/runtime/Story.java
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,11 @@ List<String> tagsAtStartOfFlowContainerWithPathString(String pathString) throws
+ ".Continue().");
}
}
// Legacy Tag
else if ( c instanceof Tag ) {
if (tags == null) tags = new ArrayList<>();
tags.add(((Tag) c).getText());
}

// Any other content - we're done
// We only recognise initial text-only tags
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.bladecoder.ink.runtime.test;

import com.bladecoder.ink.runtime.Story;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;

public class TagSpecForV20Test {

/**
* "- basic test for tags"
*/
@Test
public void testTags() throws Exception {

String json = TestUtils.getJsonString("inkfiles/tags/v20/tags.ink.json");
Story story = new Story(json);

String[] globalTags = {"author: Joe", "title: My Great Story"};
String[] knotTags = {"knot tag"};
String[] knotTagWhenContinuedTwice = {"end of knot tag"};
String[] stitchTags = {"stitch tag"};

Assert.assertArrayEquals(globalTags, story.getGlobalTags().toArray());

Assert.assertEquals("This is the content\n", story.Continue());

Assert.assertArrayEquals(globalTags, story.getCurrentTags().toArray());

Assert.assertArrayEquals(knotTags, story.tagsForContentAtPath("knot").toArray());
Assert.assertArrayEquals(
stitchTags, story.tagsForContentAtPath("knot.stitch").toArray());

story.choosePathString("knot");
Assert.assertEquals("Knot content\n", story.Continue());
Assert.assertArrayEquals(knotTags, story.getCurrentTags().toArray());
Assert.assertEquals("", story.Continue());
Assert.assertArrayEquals(
knotTagWhenContinuedTwice, story.getCurrentTags().toArray());
}

@Test
public void testTagsInChoice() throws Exception {

String json = TestUtils.getJsonString("inkfiles/tags/v20/tagOnChoice.ink.json");
Story story = new Story(json);

story.Continue();
story.chooseChoiceIndex(0);

String txt = story.Continue();
List<String> tags = story.getCurrentTags();

Assert.assertEquals("Hello", txt);
Assert.assertEquals(1, tags.size());
Assert.assertEquals("hey", tags.get(0));
}

}
1 change: 1 addition & 0 deletions src/test/resources/inkfiles/tags/v20/tagOnChoice.ink
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [Hi] Hello -> END #hey
1 change: 1 addition & 0 deletions src/test/resources/inkfiles/tags/v20/tagOnChoice.ink.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"inkVersion":20,"root":[["ev","str","^Hi","/str","/ev",{"*":"0.c-0","flg":20},{"c-0":["^ Hello ",{"#":"hey"},"end","\n",{"->":"0.g-0"},{"#f":5}],"g-0":["done",null]}],"done",null],"listDefs":{}}
16 changes: 16 additions & 0 deletions src/test/resources/inkfiles/tags/v20/tags.ink
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
VAR x = 2
# author: Joe
# title: My Great Story
This is the content

== knot ==
# knot tag
Knot content
# end of knot tag
-> END

= stitch
# stitch tag
Stitch content
# this tag is below some content so isn't included in the static tags for the stitch
-> END
1 change: 1 addition & 0 deletions src/test/resources/inkfiles/tags/v20/tags.ink.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"inkVersion":20,"root":[[{"#":"author: Joe"},{"#":"title: My Great Story"},"^This is the content","\n",["done",{"#n":"g-0"}],null],"done",{"knot":[{"#":"knot tag"},"^Knot content","\n",{"#":"end of knot tag"},"end",{"stitch":[{"#":"stitch tag"},"^Stitch content","\n",{"#":"this tag is below some content so isn't included in the static tags for the stitch"},"end",null]}],"global decl":["ev",2,{"VAR=":"x"},"/ev","end",null]}],"listDefs":{}}