Skip to content

Commit

Permalink
Autoformat cuppertion_icons
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartmorgan committed Oct 7, 2024
1 parent 5472a77 commit ed6ff18
Show file tree
Hide file tree
Showing 2 changed files with 1,349 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,31 @@ void main() async {
if (kIsWeb || !Platform.isLinux) {
return;
}
final bool isMainChannel = !Platform.environment.containsKey('CHANNEL')
|| Platform.environment['CHANNEL'] == 'main'
|| Platform.environment['CHANNEL'] == 'master';
final bool isMainChannel = !Platform.environment.containsKey('CHANNEL') ||
Platform.environment['CHANNEL'] == 'main' ||
Platform.environment['CHANNEL'] == 'master';
// Only test against main to avoid rendering differences between flutter channels.
if (!isMainChannel) {
return;
}
// Load font.
final String effectiveFontFamily = const TextStyle(fontFamily: CupertinoIcons.iconFont, package: CupertinoIcons.iconFontPackage).fontFamily!;
final String effectiveFontFamily = const TextStyle(
fontFamily: CupertinoIcons.iconFont,
package: CupertinoIcons.iconFontPackage)
.fontFamily!;
final FontLoader fontLoader = FontLoader(effectiveFontFamily);
final String filePath = path.canonicalize('assets/CupertinoIcons.ttf');
final File file = File(filePath);
fontLoader.addFont(file.readAsBytes().then((Uint8List v) => v.buffer.asByteData()));
fontLoader
.addFont(file.readAsBytes().then((Uint8List v) => v.buffer.asByteData()));
await fontLoader.load();

assert(icons.isNotEmpty);
for (int index = 0; index < icons.length;) {
final int groupEndCodePoint = (icons[index].codePoint ~/ iconsPerImage + 1) * iconsPerImage;
final int next = icons.indexWhere((IconData icon) => icon.codePoint >= groupEndCodePoint, index);
final int groupEndCodePoint =
(icons[index].codePoint ~/ iconsPerImage + 1) * iconsPerImage;
final int next = icons.indexWhere(
(IconData icon) => icon.codePoint >= groupEndCodePoint, index);
final int nextIndex = next < 0 ? icons.length : next;
registerTestForIconGroup(icons.slice(index, nextIndex));
index = nextIndex;
Expand All @@ -56,19 +62,24 @@ void main() async {
// symbols are added or removed.
void registerTestForIconGroup(List<IconData> iconGroup) {
assert(iconGroup.isNotEmpty);
String hexCodePoint(int codePoint) => codePoint.toRadixString(16).toUpperCase().padLeft(4, '0');
final int groupStartCodePoint = (iconGroup.first.codePoint ~/ iconsPerImage) * iconsPerImage;
final String range = 'U+${hexCodePoint(groupStartCodePoint)}-${hexCodePoint(groupStartCodePoint + iconsPerImage - 1)}';
String hexCodePoint(int codePoint) =>
codePoint.toRadixString(16).toUpperCase().padLeft(4, '0');
final int groupStartCodePoint =
(iconGroup.first.codePoint ~/ iconsPerImage) * iconsPerImage;
final String range =
'U+${hexCodePoint(groupStartCodePoint)}-${hexCodePoint(groupStartCodePoint + iconsPerImage - 1)}';

testWidgets('font golden test: $range', (WidgetTester tester) async {
addTearDown(tester.view.reset);
const Size canvasSize = Size(iconSize * iconsPerRow, iconSize * iconsPerCol);
const Size canvasSize =
Size(iconSize * iconsPerRow, iconSize * iconsPerCol);
tester.view.physicalSize = canvasSize * tester.view.devicePixelRatio;

const Widget fillerBox = SizedBox.square(dimension: iconSize);
final List<Widget> children = List<Widget>.filled(iconsPerImage, fillerBox);
for (final IconData icon in iconGroup) {
children[icon.codePoint - groupStartCodePoint] = Icon(icon, size: iconSize);
children[icon.codePoint - groupStartCodePoint] =
Icon(icon, size: iconSize);
}

final Widget widget = Directionality(
Expand All @@ -82,6 +93,7 @@ void registerTestForIconGroup(List<IconData> iconGroup) {
),
);
await tester.pumpWidget(widget);
await expectLater(find.byType(Wrap) , matchesGoldenFile('goldens/glyph_$range.png'));
await expectLater(
find.byType(Wrap), matchesGoldenFile('goldens/glyph_$range.png'));
});
}
Loading

0 comments on commit ed6ff18

Please sign in to comment.