Skip to content

Commit 2f06ae9

Browse files
authored
fix(runner): keep leading white spaces from strings when pushed to output (#132)
Trimming these white spaces will lead to missing spaces in concat scenarios, like choice-only text and glue. Adding first .pre-commit for hopefully easier local testing. The .pre-commit config will be extended to be able to run tests locally. Fixes: #131, #130
1 parent 8adf2d7 commit 2f06ae9

File tree

4 files changed

+64
-6
lines changed

4 files changed

+64
-6
lines changed

.pre-commit-config.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/mirrors-clang-format
3+
rev: v18.1.0
4+
hooks:
5+
- id: clang-format
6+
types_or: [c++, c, cuda]
7+
8+
- repo: https://github.com/pre-commit/pre-commit-hooks
9+
rev: v6.0.0
10+
hooks:
11+
- id: check-case-conflict
12+
- id: check-illegal-windows-names
13+
- id: check-json
14+
- id: check-toml
15+
- id: check-xml
16+
- id: check-yaml
17+
- id: detect-private-key
18+
- id: end-of-file-fixer
19+
- id: fix-byte-order-marker
20+
- id: trailing-whitespace
21+
exclude: .ink$
22+
- repo: https://github.com/pre-commit/pygrep-hooks
23+
rev: v1.10.0 # Use the ref you want to point at
24+
hooks:
25+
- id: text-unicode-replacement-char
26+
- repo: https://github.com/cheshirekow/cmake-format-precommit
27+
rev: v0.6.10
28+
hooks:
29+
- id: cmake-format
30+
- id: cmake-lint

inkcpp/output.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -392,15 +392,10 @@ char* basic_stream::get_alloc(string_table& strings, list_table& lists)
392392
_size = start;
393393

394394
// Return processed string
395-
end = clean_string<true, false>(buffer, buffer + c_str_len(buffer));
395+
end = clean_string<RemoveTail, RemoveTail>(buffer, buffer + c_str_len(buffer));
396396
*end = 0;
397397
if (end != buffer) {
398398
_last_char = end[-1];
399-
if constexpr (RemoveTail) {
400-
if (_last_char == ' ') {
401-
end[-1] = 0;
402-
}
403-
}
404399
} else {
405400
_last_char = 'e';
406401
}

inkcpp_test/Fixes.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,28 @@ SCENARIO("snapshot failed inside execution _ #111", "[fixes]")
101101
}
102102
}
103103
}
104+
105+
SCENARIO("missing leading whitespace inside choice-only text and glued text _ #130 #131", "[fixes]")
106+
{
107+
GIVEN("story with problematic text")
108+
{
109+
auto ink = story::from_file(INK_TEST_RESOURCE_DIR "130_131_missing_whitespace.bin");
110+
runner thread = ink->new_runner();
111+
WHEN("run story")
112+
{
113+
auto line = thread->getline();
114+
THEN("expect spaces in glued text") { REQUIRE(line == "Glue with no gaps.\n"); }
115+
THEN("choice contains space")
116+
{
117+
REQUIRE(thread->num_choices() == 1);
118+
REQUIRE(std::string(thread->get_choice(0)->text()) == "Look around");
119+
}
120+
thread->choose(0);
121+
line = thread->getall();
122+
THEN("no space in post choice text")
123+
{
124+
REQUIRE(line == "Looking around the saloon, you don't find much.");
125+
}
126+
}
127+
}
128+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
~temp test = true
2+
Glue <>
3+
{
4+
- test: with
5+
} <> {
6+
- test: no
7+
} <> gaps.
8+
+ Look[ around]ing around the saloon, you don't find much.->DONE

0 commit comments

Comments
 (0)