Skip to content

Commit

Permalink
Avoid cumbersome formatter workaround
Browse files Browse the repository at this point in the history
If a list shouldn't be formatted with one element on each line, a single EOL-comment inside is enough to disable the formatter.
Much simpler.
  • Loading branch information
lrhn authored Apr 19, 2024
1 parent 88a3a56 commit 52a71f5
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions packages/flutter_markdown/test/image_test_mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,15 @@ MockHttpClient createMockImageHttpClient(SecurityContext? _) {
return client;
}

// This string represents the hexidecial bytes of a transparent image. A
// string is used to make the visual representation of the data compact. A
// List<int> of the same data requires over 60 lines in a source file with
// each element in the array on a single line.
const String _imageBytesAsString = '''
// A list of integers that can be consumed as image data in a stream.
final List<int> _transparentImage = [
// Image bytes.
0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49,
0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x06,
0x00, 0x00, 0x00, 0x1F, 0x15, 0xC4, 0x89, 0x00, 0x00, 0x00, 0x0A, 0x49, 0x44,
0x41, 0x54, 0x78, 0x9C, 0x63, 0x00, 0x01, 0x00, 0x00, 0x05, 0x00, 0x01, 0x0D,
0x0A, 0x2D, 0xB4, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE,
''';

// Convert the string representing the hexidecimal bytes in the image into
// a list of integers that can be consumed as image data in a stream.
final List<int> _transparentImage = const LineSplitter()
.convert(_imageBytesAsString.replaceAllMapped(
RegExp(r' *0x([A-F0-9]{2}),? *\n? *'), (Match m) => '${m[1]}\n'))
.map<int>((String b) => int.parse(b, radix: 16))
.toList();
];

List<int> getTestImageData() {
return _transparentImage;
Expand Down

0 comments on commit 52a71f5

Please sign in to comment.