testCasesGenerator top-level property

FigGenerator testCasesGenerator
final

Implementation

final FigGenerator testCasesGenerator = FigGenerator(
  script: [
    "bash",
    "-c",
    'for i in \$(find -E . -regex ".*.robot" -type f); do cat -s \$i ; done',
  ],
  postProcess: (String out, [List<String>? tokens]) {
    final blockRegex = RegExp(
        r'(?:\*{3} ?Test Cases ?\*{3})([\S\s]*)(?:\*{3}(\w+\s?)+\*{3})*',
        caseSensitive: false,
        multiLine: true);
    final matches = blockRegex.allMatches(out);

    final Set<String> seen = {};
    final List<FigSuggestion> suggestions = [];

    for (final match in matches) {
      final block = match.group(1);
      if (block == null) continue;

      final lineRegex =
          RegExp(r'^(\w+( |-)*)+(?!.\#.*)(?!.\#.*)', multiLine: true);
      final lines = lineRegex.allMatches(block);

      for (final lineMatch in lines) {
        var testCase = lineMatch.group(0)?.trim();
        if (testCase == null) continue;

        if (RegExp(r'\s\s+').hasMatch(testCase)) continue;

        if (seen.contains(testCase)) continue;
        seen.add(testCase);

        suggestions.add(FigSuggestion(
          name: testCase,
          description: "Test case",
        ));
      }
    }
    return suggestions;
  },
);