33// found in the LICENSE file.
44
55/// Provides utilities for testing engine code.
6- // @dart = 2.6
6+ // @dart = 2.12
77library matchers;
88
99import 'dart:html' as html;
@@ -12,7 +12,6 @@ import 'dart:math' as math;
1212import 'package:html/parser.dart' as html_package;
1313import 'package:html/dom.dart' as html_package;
1414
15- import 'package:meta/meta.dart' ;
1615import 'package:test/test.dart' ;
1716
1817import 'package:ui/ui.dart' ;
@@ -23,9 +22,9 @@ import 'package:ui/src/engine.dart';
2322/// If [root] is `null` returns all surfaces from the last rendered scene.
2423///
2524/// Surfaces are returned in a depth-first order.
26- Iterable <PersistedSurface > enumerateSurfaces ([PersistedSurface root]) {
25+ Iterable <PersistedSurface > enumerateSurfaces ([PersistedSurface ? root]) {
2726 root ?? = SurfaceSceneBuilder .debugLastFrameScene;
28- final List <PersistedSurface > surfaces = < PersistedSurface > [root];
27+ final List <PersistedSurface > surfaces = < PersistedSurface > [root! ];
2928
3029 root.visitChildren ((PersistedSurface surface) {
3130 surfaces.addAll (enumerateSurfaces (surface));
@@ -37,15 +36,15 @@ Iterable<PersistedSurface> enumerateSurfaces([PersistedSurface root]) {
3736/// Enumerates all pictures nested under [root] .
3837///
3938/// If [root] is `null` returns all pictures from the last rendered scene.
40- Iterable <PersistedPicture > enumeratePictures ([PersistedSurface root]) {
39+ Iterable <PersistedPicture > enumeratePictures ([PersistedSurface ? root]) {
4140 root ?? = SurfaceSceneBuilder .debugLastFrameScene;
4241 return enumerateSurfaces (root).whereType <PersistedPicture >();
4342}
4443
4544/// Enumerates all offset surfaces nested under [root] .
4645///
4746/// If [root] is `null` returns all pictures from the last rendered scene.
48- Iterable <PersistedOffset > enumerateOffsets ([PersistedSurface root]) {
47+ Iterable <PersistedOffset > enumerateOffsets ([PersistedSurface ? root]) {
4948 root ?? = SurfaceSceneBuilder .debugLastFrameScene;
5049 return enumerateSurfaces (root).whereType <PersistedOffset >();
5150}
@@ -76,7 +75,7 @@ typedef DistanceFunction<T> = num Function(T a, T b);
7675///
7776/// Calling an instance of this type must either be done dynamically, or by
7877/// first casting it to a [DistanceFunction<T>] for some concrete T.
79- typedef AnyDistanceFunction = num Function (Null a, Null b);
78+ typedef AnyDistanceFunction = num Function (Never a, Never b);
8079
8180const Map <Type , AnyDistanceFunction > _kStandardDistanceFunctions =
8281 < Type , AnyDistanceFunction > {
@@ -108,7 +107,7 @@ double _rectDistance(Rect a, Rect b) {
108107}
109108
110109double _sizeDistance (Size a, Size b) {
111- final Offset delta = b - a;
110+ final Offset delta = ( b - a) as Offset ;
112111 return delta.distance;
113112}
114113
@@ -134,11 +133,11 @@ double _sizeDistance(Size a, Size b) {
134133/// [double]s and has an optional `epsilon` parameter.
135134/// * [closeTo] , which specializes in numbers only.
136135Matcher within <T >({
137- @ required num distance,
138- @ required T from,
139- DistanceFunction <T > distanceFunction,
136+ required num distance,
137+ required T from,
138+ DistanceFunction <T >? distanceFunction,
140139}) {
141- distanceFunction ?? = _kStandardDistanceFunctions[T ];
140+ distanceFunction ?? = _kStandardDistanceFunctions[T ] as DistanceFunction < T > ? ;
142141
143142 if (distanceFunction == null ) {
144143 throw ArgumentError (
@@ -158,7 +157,7 @@ class _IsWithinDistance<T> extends Matcher {
158157 final num epsilon;
159158
160159 @override
161- bool matches (Object object, Map <dynamic , dynamic > matchState) {
160+ bool matches (Object ? object, Map <dynamic , dynamic > matchState) {
162161 if (object is ! T ) {
163162 return false ;
164163 }
@@ -183,7 +182,7 @@ class _IsWithinDistance<T> extends Matcher {
183182
184183 @override
185184 Description describeMismatch (
186- Object object,
185+ Object ? object,
187186 Description mismatchDescription,
188187 Map <dynamic , dynamic > matchState,
189188 bool verbose,
@@ -230,11 +229,11 @@ enum HtmlComparisonMode {
230229String canonicalizeHtml (String htmlContent,
231230 {HtmlComparisonMode mode = HtmlComparisonMode .nonLayoutOnly,
232231 bool throwOnUnusedAttributes = false }) {
233- if (htmlContent == null || htmlContent .trim ().isEmpty) {
232+ if (htmlContent.trim ().isEmpty) {
234233 return '' ;
235234 }
236235
237- String _unusedAttribute (String name) {
236+ String ? _unusedAttribute (String name) {
238237 if (throwOnUnusedAttributes) {
239238 fail ('Provided HTML contains style attribute "$name " which '
240239 'is not used for comparison in the test. The HTML was:\n\n $htmlContent ' );
@@ -244,7 +243,7 @@ String canonicalizeHtml(String htmlContent,
244243 }
245244
246245 html_package.Element _cleanup (html_package.Element original) {
247- String replacementTag = original.localName;
246+ String replacementTag = original.localName! ;
248247 switch (replacementTag) {
249248 case 'flt-scene' :
250249 replacementTag = 's' ;
@@ -256,7 +255,7 @@ String canonicalizeHtml(String htmlContent,
256255 replacementTag = 'o' ;
257256 break ;
258257 case 'flt-clip' :
259- final String clipType = original.attributes['clip-type' ];
258+ final String ? clipType = original.attributes['clip-type' ];
260259 switch (clipType) {
261260 case 'rect' :
262261 replacementTag = 'clip' ;
@@ -314,7 +313,7 @@ String canonicalizeHtml(String htmlContent,
314313 });
315314
316315 if (original.attributes.containsKey ('style' )) {
317- final String styleValue = original.attributes['style' ];
316+ final String styleValue = original.attributes['style' ]! ;
318317
319318 int attrCount = 0 ;
320319 final String processedAttributes = styleValue
@@ -368,7 +367,7 @@ String canonicalizeHtml(String htmlContent,
368367 attrCount++ ;
369368 return attr.trim ();
370369 })
371- .where ((String attr) => attr != null && attr.isNotEmpty)
370+ .where ((String ? attr) => attr != null && attr.isNotEmpty)
372371 .join ('; ' );
373372
374373 if (attrCount > 0 ) {
@@ -412,7 +411,7 @@ void expectHtml(html.Element element, String expectedHtml,
412411 {HtmlComparisonMode mode = HtmlComparisonMode .nonLayoutOnly}) {
413412 expectedHtml =
414413 canonicalizeHtml (expectedHtml, mode: mode, throwOnUnusedAttributes: true );
415- final String actualHtml = canonicalizeHtml (element.outerHtml, mode: mode);
414+ final String actualHtml = canonicalizeHtml (element.outerHtml! , mode: mode);
416415 expect (actualHtml, expectedHtml);
417416}
418417
@@ -462,7 +461,7 @@ class SceneTester {
462461 final SurfaceScene scene;
463462
464463 void expectSceneHtml (String expectedHtml) {
465- expectHtml (scene.webOnlyRootElement, expectedHtml,
464+ expectHtml (scene.webOnlyRootElement! , expectedHtml,
466465 mode: HtmlComparisonMode .noAttributes);
467466 }
468467}
0 commit comments