Skip to content

Commit 2d7f591

Browse files
committed
fix(NO_STD): touchups needed for rebase of current master
1 parent 6913c51 commit 2d7f591

File tree

3 files changed

+149
-2
lines changed

3 files changed

+149
-2
lines changed

inkcpp/runner_impl.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,14 @@ class runner_impl
273273
_threadDone.forget();
274274
}
275275

276-
void set(size_t index, const ip_t& value) { _threadDone.set(index, value); }
276+
void set(size_t index, const ip_t& value)
277+
{
278+
if (index >= _threadDone.capacity()) {
279+
inkAssert(index == _threadDone.capacity(), "Threads should only be created incremental");
280+
_threadDone.resize(_threadDone.capacity() * 1.5);
281+
}
282+
_threadDone.set(index, value);
283+
}
277284

278285
const ip_t& get(size_t index) const { return _threadDone.get(index); }
279286

inkcpp_test/Fixes.cpp

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ SCENARIO(
169169
}
170170
}
171171
}
172+
172173
SCENARIO("Casting during redefinition is too strict _ #134", "[fixes]")
173174
{
174175
GIVEN("story with problematic text")
@@ -248,4 +249,48 @@ SCENARIO("Using knot visit count as condition _ #139", "[fixes]")
248249
}
249250
}
250251
}
251-
}
252+
}
253+
254+
SCENARIO("Provoke thread array expension _ #142", "[fixes]")
255+
{
256+
GIVEN("story with 15 threads in one know")
257+
{
258+
std::unique_ptr<story> ink{story::from_file(INK_TEST_RESOURCE_DIR "142_many_threads.bin")};
259+
runner thread = ink->new_runner();
260+
WHEN("just go to choice")
261+
{
262+
std::string content = thread->getall();
263+
REQUIRE(content == "At the top\n");
264+
THEN("expect to see 15 choices")
265+
{
266+
REQUIRE(thread->num_choices() == 15);
267+
const char options[] = "abcdefghijklmno";
268+
for (const char* c = options; *c; ++c) {
269+
CHECK(thread->get_choice(c - options)->text()[0] == *c);
270+
}
271+
}
272+
}
273+
WHEN("choose 5 options")
274+
{
275+
std::string content = thread->getall();
276+
for (int i = 0; i < 5; ++i) {
277+
REQUIRE_FALSE(thread->can_continue());
278+
thread->choose(i);
279+
content += thread->getall();
280+
}
281+
REQUIRE(
282+
content
283+
== "At the top\na\nAt the top\nc\nAt the top\ne\nAt the top\ng\nAt the top\ni\nAt the "
284+
"top\n"
285+
);
286+
THEN("only 11 choices are left")
287+
{
288+
REQUIRE(thread->num_choices() == 10);
289+
const char* options = "bdfhjklmno";
290+
for (const char* c = options; *c; ++c) {
291+
CHECK(thread->get_choice(c - options)->text()[0] == *c);
292+
}
293+
}
294+
}
295+
}
296+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
-> top
2+
3+
=== top ===
4+
At the top
5+
<- thread_a
6+
<- thread_b
7+
<- thread_c
8+
<- thread_d
9+
<- thread_e
10+
<- thread_f
11+
<- thread_g
12+
<- thread_h
13+
<- thread_i
14+
<- thread_j
15+
<- thread_k
16+
<- thread_l
17+
<- thread_m
18+
<- thread_n
19+
<- thread_o
20+
-> DONE
21+
22+
= thread_a
23+
* [a]
24+
a
25+
-> top
26+
27+
= thread_b
28+
* [b]
29+
b
30+
-> top
31+
32+
= thread_c
33+
* [c]
34+
c
35+
-> top
36+
37+
= thread_d
38+
* [d]
39+
d
40+
-> top
41+
42+
= thread_e
43+
* [e]
44+
e
45+
-> top
46+
47+
= thread_f
48+
* [f]
49+
f
50+
-> top
51+
52+
= thread_g
53+
* [g]
54+
g
55+
-> top
56+
57+
= thread_h
58+
* [h]
59+
h
60+
-> top
61+
62+
= thread_i
63+
* [i]
64+
i
65+
-> top
66+
67+
= thread_j
68+
* [j]
69+
j
70+
-> top
71+
72+
= thread_k
73+
* [k]
74+
k
75+
-> top
76+
77+
= thread_l
78+
* [l]
79+
l
80+
-> top
81+
82+
= thread_m
83+
* [m]
84+
m
85+
-> top
86+
87+
= thread_n
88+
* [n]
89+
n
90+
-> top
91+
92+
= thread_o
93+
* [o]
94+
o
95+
-> top

0 commit comments

Comments
 (0)