Skip to content

Commit

Permalink
Merge pull request #998 from y-lohse/fix/incorrect-substring
Browse files Browse the repository at this point in the history
Add failing tests to prove #997 Fix incorrect substring in TrySplittingHeadTailWhitespace
  • Loading branch information
smwhr authored Feb 26, 2023
2 parents 1d702f8 + eb78a98 commit 74c9155
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "inkjs",
"version": "2.2.0",
"version": "2.2.1",
"description": "A javascript port of inkle's ink scripting language (http://www.inklestudios.com/ink/)",
"main": "dist/ink-full.js",
"types": "ink.d.ts",
Expand Down
10 changes: 5 additions & 5 deletions src/engine/StoryState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -815,10 +815,7 @@ export class StoryState {
}

if (innerStrEnd > innerStrStart) {
let innerStrText = str.substring(
innerStrStart,
innerStrEnd - innerStrStart
);
let innerStrText = str.substring(innerStrStart, innerStrEnd);
listTexts.push(new StringValue(innerStrText));
}

Expand All @@ -827,7 +824,10 @@ export class StoryState {
if (tailLastNewlineIdx < str.length - 1) {
let numSpaces = str.length - tailLastNewlineIdx - 1;
let trailingSpaces = new StringValue(
str.substring(tailLastNewlineIdx + 1, numSpaces)
str.substring(
tailLastNewlineIdx + 1,
tailLastNewlineIdx + 1 + numSpaces
)
);
listTexts.push(trailingSpaces);
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/inkfiles/compiled/inkjs/tests.ink.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/tests/inkfiles/original/inkjs/tests.ink
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,10 @@ mutated 1
mutated 2
-> DONE

= variable_print
{stringvar}
-> DONE

= visit_count
visited
-> DONE
Expand Down
15 changes: 15 additions & 0 deletions src/tests/specs/inkjs/engine/Integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ describe("Integration", () => {
expect(context.story.variablesState["stringvar"]).toEqual("Jonas");
});

it("should correctly print variables passed to ink, part 1", () => {
context.story.variablesState["stringvar"] = "\n\nDear Emilia";
context.story.ChoosePathString("integration.variable_print");
expect(context.story.Continue()).toEqual("Dear Emilia\n");
});

it("should correctly print variables passed to ink, part 2", () => {
context.story.variablesState["stringvar"] =
"\n\nDear Emilia, \nHope you are well\n\n ";
context.story.ChoosePathString("integration.variable_print");
expect(context.story.Continue()).toEqual(
"Dear Emilia,\nHope you are well\n"
);
});

it("should observe variables", () => {
context.story.ChoosePathString("integration.variable_observer");
expect(context.story.variablesState["observedVar1"]).toEqual(1);
Expand Down

0 comments on commit 74c9155

Please sign in to comment.