assertBuffer method

void assertBuffer(
  1. List<List<String>> expected
)

Implementation

void assertBuffer(List<List<String>> expected) {
  final actual = terminal.grid;
  final diffs = <String>[];
  bool hasDiff = false;

  for (int y = 0; y < actual.length || y < expected.length; y++) {
    final actualRow = y < actual.length ? actual[y] : <String>[];
    final expectedRow = y < expected.length ? expected[y] : <String>[];

    for (int x = 0; x < actualRow.length || x < expectedRow.length; x++) {
      final actualCell = x < actualRow.length ? actualRow[x] : '';
      final expectedCell = x < expectedRow.length ? expectedRow[x] : '';

      if (actualCell != expectedCell) {
        hasDiff = true;
        diffs.add(
          'Cell ($x, $y): Expected "$expectedCell", Actual "$actualCell"',
        );
      }
    }
  }

  if (hasDiff) {
    throw AssertionError(
      'Buffer does not match:\n${diffs.take(20).join('\n')}',
    );
  }
}