Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src/catch2/interfaces/catch_interfaces_generatortracker.cpp
diff options
context:
space:
mode:
authorMartin Hořeňovský2025-10-06 11:47:38 +0200
committerMartin Hořeňovský2026-01-12 16:58:15 +0100
commit9eca713a1f4555b3095564781d77654958ee3dc1 (patch)
treee500e9b38c705f7f08ca412af16cb843cb80088e /src/catch2/interfaces/catch_interfaces_generatortracker.cpp
parent44c597f0742b491399994afa00070b99d3ef2885 (diff)
downloadcatch3-9eca713a1f4555b3095564781d77654958ee3dc1.tar.gz
Add option to skip forward to the generator interface
Diffstat (limited to 'src/catch2/interfaces/catch_interfaces_generatortracker.cpp')
-rw-r--r--src/catch2/interfaces/catch_interfaces_generatortracker.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/catch2/interfaces/catch_interfaces_generatortracker.cpp b/src/catch2/interfaces/catch_interfaces_generatortracker.cpp
index e9fa5dda..4ac23ddb 100644
--- a/src/catch2/interfaces/catch_interfaces_generatortracker.cpp
+++ b/src/catch2/interfaces/catch_interfaces_generatortracker.cpp
@@ -7,6 +7,8 @@
// SPDX-License-Identifier: BSL-1.0
#include <catch2/interfaces/catch_interfaces_generatortracker.hpp>
+#include <catch2/generators/catch_generators.hpp>
+
#include <string>
namespace Catch {
@@ -21,6 +23,31 @@ namespace Catch {
return ret;
}
+ void GeneratorUntypedBase::skipToNthElementImpl( std::size_t n ) {
+ for ( size_t i = m_currentElementIndex; i < n; ++i ) {
+ bool isValid = next();
+ if ( !isValid ) {
+ Detail::throw_generator_exception(
+ "Coud not jump to Nth element: not enough elements" );
+ }
+ }
+ }
+
+ void GeneratorUntypedBase::skipToNthElement( std::size_t n ) {
+ if ( n < m_currentElementIndex ) {
+ Detail::throw_generator_exception(
+ "Tried to jump generator backwards" );
+ }
+ if ( n == m_currentElementIndex ) { return; }
+
+ skipToNthElementImpl(n);
+ // Fixup tracking after moving the generator forward
+ // * Ensure that the correct element index is set after skipping
+ // * Invalidate cache
+ m_currentElementIndex = n;
+ m_stringReprCache.clear();
+ }
+
StringRef GeneratorUntypedBase::currentElementAsString() const {
if ( m_stringReprCache.empty() ) {
m_stringReprCache = stringifyImpl();