stepOutlineTopLevelIndexes function

Iterable<({String line, bool nested, int topLevelIndex})> stepOutlineTopLevelIndexes(
  1. List<String> stepsOutline
)

Pure helpers for attributing API/console/storage logs to top-level test steps.

Kept free of Flutter imports so unit tests and the CLI can use them. Walks stepsOutline and yields each line with its top-level step index.

Nested outline lines (indented with two spaces) inherit the parent index.

Implementation

/// Walks [stepsOutline] and yields each line with its top-level step index.
///
/// Nested outline lines (indented with two spaces) inherit the parent index.
Iterable<({String line, int topLevelIndex, bool nested})>
    stepOutlineTopLevelIndexes(
  List<String> stepsOutline,
) sync* {
  var topLevelIndex = -1;
  for (final line in stepsOutline) {
    final nested = line.startsWith('  ');
    if (!nested) {
      topLevelIndex++;
    }
    if (topLevelIndex < 0) continue;
    yield (line: line, topLevelIndex: topLevelIndex, nested: nested);
  }
}