forked from dnfield/flutter_svg
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgolden_svg_test.dart
45 lines (37 loc) · 1.36 KB
/
golden_svg_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import 'dart:io';
import 'dart:typed_data';
import 'package:path/path.dart';
import 'package:test/test.dart';
import '../tool/gen_golden.dart' as golden;
Iterable<File> getGoldenFileNames() sync* {
final String root = dirname(Platform.script.toFilePath());
final Directory dir =
Directory(join(root, root.endsWith('test') ? '..' : '', 'golden'));
for (FileSystemEntity fe in dir.listSync(recursive: true)) {
if (fe is File && fe.path.toLowerCase().endsWith('.png')) {
if (fe.path.toLowerCase().contains('text') && !Platform.isLinux) {
continue;
}
yield fe;
}
}
}
String getSvgAssetName(String goldenFileName) {
return goldenFileName
.replaceAll('/golden/', '/example/assets/')
.replaceAll('\\golden\\', '\\example\\assets\\')
.replaceAll('.png', '.svg');
}
void main() {
test('SVG Rendering matches golden files', () async {
for (File goldenFile in getGoldenFileNames()) {
final File svgAssetFile = File(getSvgAssetName(goldenFile.path));
final Uint8List bytes =
await golden.getSvgPngBytes(await svgAssetFile.readAsString());
final Uint8List goldenBytes = await goldenFile.readAsBytes();
expect(bytes, orderedEquals(goldenBytes),
reason:
'${goldenFile.path} does not match rendered output of ${svgAssetFile.path}!');
}
}, skip: !Platform.isLinux);
}