genUiFuzzSummary function

String genUiFuzzSummary(
  1. List<GenUiFuzzFinding> findings
)

A table of findings, one line per component, for a CI log.

The detail is in the findings themselves; this is what to look at first when a run comes back with sixty of them and the question is which component to open.

Implementation

String genUiFuzzSummary(List<GenUiFuzzFinding> findings) {
  if (findings.isEmpty) return 'nothing broke';
  final byComponent = <String, List<GenUiFuzzFinding>>{};
  for (final f in findings) {
    byComponent.putIfAbsent(f.component, () => <GenUiFuzzFinding>[]).add(f);
  }
  final names = byComponent.keys.toList()
    ..sort((a, b) => byComponent[b]!.length.compareTo(byComponent[a]!.length));
  final buffer = StringBuffer(
    '${findings.length} in ${names.length} '
    'component${names.length == 1 ? '' : 's'}\n',
  );
  for (final String name in names) {
    final List<GenUiFuzzFinding> mine = byComponent[name]!;
    int count(GenUiFuzzKind kind) => mine.where((f) => f.kind == kind).length;
    final List<String> parts = [
      if (count(GenUiFuzzKind.rejected) > 0) 'its example was rejected',
      if (count(GenUiFuzzKind.threw) > 0) '${count(GenUiFuzzKind.threw)} threw',
      if (count(GenUiFuzzKind.renderedNothing) > 0)
        '${count(GenUiFuzzKind.renderedNothing)} rendered nothing',
    ];
    buffer.writeln(
      '  ${mine.length.toString().padLeft(4)}  $name  (${parts.join(', ')})',
    );
  }
  return buffer.toString();
}