Rework ScriptIterator to jump to first value on reset.
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2020-06-05 18:06:45 +02:00
parent 9e7607338f
commit fddf2cabab
5 changed files with 51 additions and 37 deletions

View File

@@ -27,7 +27,7 @@ TEST_CASE("Script Aggregator properly iterates containing script.", "[Battling,
while (aggr.HasNext()) {
auto next = aggr.GetNext();
REQUIRE(next != nullptr);
dynamic_cast<TestScript*>(next)->TestMethod(ran);
next.As<TestScript>()->TestMethod(ran);
}
CHECK(ran == 1);
}
@@ -45,7 +45,7 @@ TEST_CASE("Script Aggregator properly iterates multiple scripts.", "[Battling, S
while (aggr.HasNext()) {
auto next = aggr.GetNext();
REQUIRE(next != nullptr);
dynamic_cast<TestScript*>(next)->TestMethod(ran);
next.As<TestScript>()->TestMethod(ran);
}
CHECK(ran == 3);
}
@@ -64,7 +64,7 @@ TEST_CASE("Script Aggregator properly iterates Script Set.", "[Battling, Scripti
while (aggr.HasNext()) {
auto next = aggr.GetNextNotNull();
REQUIRE(next != nullptr);
dynamic_cast<TestScript*>(next)->TestMethod(ran);
next.As<TestScript>()->TestMethod(ran);
}
CHECK(ran == 3);
}
@@ -83,7 +83,7 @@ TEST_CASE("Script Aggregator properly iterates data of Script Set and Script.",
while (aggr.HasNext()) {
auto next = aggr.GetNextNotNull();
REQUIRE(next != nullptr);
dynamic_cast<TestScript*>(next)->TestMethod(ran);
next.As<TestScript>()->TestMethod(ran);
}
CHECK(ran == 3);
}
@@ -102,7 +102,7 @@ TEST_CASE("Script Aggregator properly iterates data of Script and Script Set.",
while (aggr.HasNext()) {
auto next = aggr.GetNextNotNull();
REQUIRE(next != nullptr);
dynamic_cast<TestScript*>(next)->TestMethod(ran);
next.As<TestScript>()->TestMethod(ran);
}
CHECK(ran == 3);
}
@@ -123,7 +123,7 @@ TEST_CASE("Script Aggregator properly iterates data of Script, Script Set and Sc
while (aggr.HasNext()) {
auto next = aggr.GetNextNotNull();
REQUIRE(next != nullptr);
dynamic_cast<TestScript*>(next)->TestMethod(ran);
next.As<TestScript>()->TestMethod(ran);
}
CHECK(ran == 4);
}
@@ -143,12 +143,11 @@ TEST_CASE("Script Aggregator properly iterates empty Script Set.", "[Battling, S
auto set = ScriptSet();
auto vec = ArbUt::List<ScriptWrapper>{ScriptWrapper::FromSet(&set)};
auto aggr = ScriptAggregator(vec);
aggr.Reset();
while (aggr.HasNext()) {
auto next = aggr.GetNext();
REQUIRE(next == nullptr);
ran++;
}
CHECK(ran == 1);
CHECK(ran == 0);
}
#endif

View File

@@ -59,19 +59,18 @@ TEST_CASE("Script source with script ptr being set.", "[Battling, Scripting]") {
TEST_CASE("Script source with script ptr being set after first iteration.", "[Battling, Scripting]") {
auto source = ScriptSourceWithScriptPtr();
auto scripts = source.GetScriptIterator();
auto first = scripts.GetNext();
CHECK(first == nullptr);
REQUIRE_FALSE(scripts.HasNext());
source.ScriptPtr = std::make_unique<TestScript>("foobar");
scripts = source.GetScriptIterator();
first = scripts.GetNext();
auto first = scripts.GetNext();
CHECK(first != nullptr);
}
TEST_CASE("Script source with empty script set.", "[Battling, Scripting]") {
auto source = ScriptSourceWithScriptSet();
auto scripts = source.GetScriptIterator();
auto first = scripts.GetNext();
CHECK(first == nullptr);
scripts.Reset();
REQUIRE_FALSE(scripts.HasNext());
}
TEST_CASE("Script source with single item script set.", "[Battling, Scripting]") {