vitool_test.dart 21.7 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:math';

import 'package:collection/collection.dart';
8
import 'package:flutter/foundation.dart';
9
import 'package:flutter_test/flutter_test.dart';
10
import 'package:path/path.dart' as path;
11
import 'package:vitool/vitool.dart';
12 13 14 15 16 17

void main() {

  test('parsePixels', () {
    expect(parsePixels('23px'), 23);
    expect(parsePixels('9px'), 9);
Dan Field's avatar
Dan Field committed
18
    expect(() { parsePixels('9pt'); }, throwsArgumentError);
19 20 21 22
  });

  test('parsePoints', () {
    expect(parsePoints('1.0, 2.0'),
23
        const <Point<double>>[Point<double>(1.0, 2.0)],
24 25 26
    );
    expect(parsePoints('12.0, 34.0 5.0, 6.6'),
        const <Point<double>>[
27 28
          Point<double>(12.0, 34.0),
          Point<double>(5.0, 6.6),
29
        ],
30 31 32
    );
    expect(parsePoints('12.0 34.0 5.0 6.6'),
        const <Point<double>>[
33 34
          Point<double>(12.0, 34.0),
          Point<double>(5.0, 6.6),
35
        ],
36 37 38 39 40 41 42 43 44 45 46 47
    );
  });

  group('parseSvg', () {
    test('empty SVGs', () {
      interpretSvg(testAsset('empty_svg_1_48x48.svg'));
      interpretSvg(testAsset('empty_svg_2_100x50.svg'));
    });

    test('illegal SVGs', () {
      expect(
        () { interpretSvg(testAsset('illegal_svg_multiple_roots.svg')); },
48
        throwsA(anything),
49 50 51 52 53 54
      );
    });

    test('SVG size', () {
      expect(
          interpretSvg(testAsset('empty_svg_1_48x48.svg')).size,
55
          const Point<double>(48.0, 48.0),
56 57 58 59
      );

      expect(
          interpretSvg(testAsset('empty_svg_2_100x50.svg')).size,
60
          const Point<double>(100.0, 50.0),
61 62 63 64 65 66
      );
    });

    test('horizontal bar', () {
      final FrameData frameData = interpretSvg(testAsset('horizontal_bar.svg'));
      expect(frameData.paths, <SvgPath>[
67 68 69 70 71 72
        const SvgPath('path_1', <SvgPathCommand>[
          SvgPathCommand('M', <Point<double>>[Point<double>(0.0, 19.0)]),
          SvgPathCommand('L', <Point<double>>[Point<double>(48.0, 19.0)]),
          SvgPathCommand('L', <Point<double>>[Point<double>(48.0, 29.0)]),
          SvgPathCommand('L', <Point<double>>[Point<double>(0.0, 29.0)]),
          SvgPathCommand('Z', <Point<double>>[]),
73 74 75 76 77 78 79 80 81 82 83
        ]),
      ]);
    });

    test('leading space path command', () {
      interpretSvg(testAsset('leading_space_path_command.svg'));
    });

    test('SVG illegal path', () {
      expect(
        () { interpretSvg(testAsset('illegal_path.svg')); },
84
        throwsA(anything),
85 86 87 88 89 90 91
      );
    });


    test('SVG group', () {
      final FrameData frameData = interpretSvg(testAsset('bars_group.svg'));
      expect(frameData.paths, const <SvgPath>[
92 93 94 95 96 97
        SvgPath('path_1', <SvgPathCommand>[
          SvgPathCommand('M', <Point<double>>[Point<double>(0.0, 19.0)]),
          SvgPathCommand('L', <Point<double>>[Point<double>(48.0, 19.0)]),
          SvgPathCommand('L', <Point<double>>[Point<double>(48.0, 29.0)]),
          SvgPathCommand('L', <Point<double>>[Point<double>(0.0, 29.0)]),
          SvgPathCommand('Z', <Point<double>>[]),
98
        ]),
99 100 101 102 103 104
        SvgPath('path_2', <SvgPathCommand>[
          SvgPathCommand('M', <Point<double>>[Point<double>(0.0, 34.0)]),
          SvgPathCommand('L', <Point<double>>[Point<double>(48.0, 34.0)]),
          SvgPathCommand('L', <Point<double>>[Point<double>(48.0, 44.0)]),
          SvgPathCommand('L', <Point<double>>[Point<double>(0.0, 44.0)]),
          SvgPathCommand('Z', <Point<double>>[]),
105 106 107 108 109 110 111
        ]),
      ]);
    });

    test('SVG group translate', () {
      final FrameData frameData = interpretSvg(testAsset('bar_group_translate.svg'));
      expect(frameData.paths, const <SvgPath>[
112 113 114 115 116 117
        SvgPath('path_1', <SvgPathCommand>[
          SvgPathCommand('M', <Point<double>>[Point<double>(0.0, 34.0)]),
          SvgPathCommand('L', <Point<double>>[Point<double>(48.0, 34.0)]),
          SvgPathCommand('L', <Point<double>>[Point<double>(48.0, 44.0)]),
          SvgPathCommand('L', <Point<double>>[Point<double>(0.0, 44.0)]),
          SvgPathCommand('Z', <Point<double>>[]),
118 119 120 121 122 123 124
        ]),
      ]);
    });

    test('SVG group scale', () {
      final FrameData frameData = interpretSvg(testAsset('bar_group_scale.svg'));
      expect(frameData.paths, const <SvgPath>[
125 126 127 128 129 130 131
        SvgPath(
            'path_1', <SvgPathCommand>[
          SvgPathCommand('M', <Point<double>>[Point<double>(0.0, 9.5)]),
          SvgPathCommand('L', <Point<double>>[Point<double>(24.0, 9.5)]),
          SvgPathCommand('L', <Point<double>>[Point<double>(24.0, 14.5)]),
          SvgPathCommand('L', <Point<double>>[Point<double>(0.0, 14.5)]),
          SvgPathCommand('Z', <Point<double>>[]),
132 133 134 135 136 137 138
        ]),
      ]);
    });

    test('SVG group rotate scale', () {
      final FrameData frameData = interpretSvg(testAsset('bar_group_rotate_scale.svg'));
      expect(frameData.paths, const <PathMatcher>[
139 140 141 142 143 144 145 146
        PathMatcher(
            SvgPath(
                'path_1', <SvgPathCommand>[
              SvgPathCommand('L', <Point<double>>[Point<double>(29.0, 0.0)]),
              SvgPathCommand('L', <Point<double>>[Point<double>(29.0, 48.0)]),
              SvgPathCommand('L', <Point<double>>[Point<double>(19.0, 48.0)]),
              SvgPathCommand('M', <Point<double>>[Point<double>(19.0, 0.0)]),
              SvgPathCommand('Z', <Point<double>>[]),
147
            ]),
148
            margin: precisionErrorTolerance,
149
        ),
150 151 152 153 154 155
      ]);
    });

    test('SVG illegal transform', () {
      expect(
        () { interpretSvg(testAsset('illegal_transform.svg')); },
156
        throwsA(anything),
157 158 159 160 161 162
      );
    });

    test('SVG group opacity', () {
      final FrameData frameData = interpretSvg(testAsset('bar_group_opacity.svg'));
      expect(frameData.paths, const <SvgPath>[
163
        SvgPath(
164
          'path_1',
165 166 167 168 169 170
          <SvgPathCommand>[
            SvgPathCommand('M', <Point<double>>[Point<double>(0.0, 19.0)]),
            SvgPathCommand('L', <Point<double>>[Point<double>(48.0, 19.0)]),
            SvgPathCommand('L', <Point<double>>[Point<double>(48.0, 29.0)]),
            SvgPathCommand('L', <Point<double>>[Point<double>(0.0, 29.0)]),
            SvgPathCommand('Z', <Point<double>>[]),
171 172 173 174 175 176 177 178 179 180
          ],
          opacity: 0.5,
        ),
      ]);
    });

    test('horizontal bar relative', () {
      // This asset uses the relative 'l' command instead of 'L'.
      final FrameData frameData = interpretSvg(testAsset('horizontal_bar_relative.svg'));
      expect(frameData.paths, const <SvgPath>[
181 182 183 184 185 186 187
        SvgPath(
            'path_1', <SvgPathCommand>[
          SvgPathCommand('M', <Point<double>>[Point<double>(0.0, 19.0)]),
          SvgPathCommand('L', <Point<double>>[Point<double>(48.0, 19.0)]),
          SvgPathCommand('L', <Point<double>>[Point<double>(48.0, 29.0)]),
          SvgPathCommand('L', <Point<double>>[Point<double>(0.0, 29.0)]),
          SvgPathCommand('Z', <Point<double>>[]),
188 189 190 191 192 193 194 195
        ]),
      ]);
    });

    test('close in middle of path', () {
      // This asset uses the relative 'l' command instead of 'L'.
      final FrameData frameData = interpretSvg(testAsset('close_path_in_middle.svg'));
      expect(frameData.paths, const <SvgPath>[
196 197 198 199 200 201 202 203 204
        SvgPath(
            'path_1', <SvgPathCommand>[
          SvgPathCommand('M', <Point<double>>[Point<double>(50.0, 50.0)]),
          SvgPathCommand('L', <Point<double>>[Point<double>(60.0, 50.0)]),
          SvgPathCommand('L', <Point<double>>[Point<double>(60.0, 60.0)]),
          SvgPathCommand('Z', <Point<double>>[]),
          SvgPathCommand('L', <Point<double>>[Point<double>(50.0, 40.0)]),
          SvgPathCommand('L', <Point<double>>[Point<double>(40.0, 40.0)]),
          SvgPathCommand('Z', <Point<double>>[]),
205 206 207 208 209 210 211
        ]),
      ]);
    });
  });

  group('create PathAnimation', () {
    test('single path', () {
212 213 214 215 216
      const List<FrameData> frameData = <FrameData>[
        FrameData(
          Point<double>(10.0, 10.0),
          <SvgPath>[
            SvgPath(
217
              'path_1',
218 219 220
              <SvgPathCommand>[
                SvgPathCommand('M', <Point<double>>[Point<double>(0.0, 0.0)]),
                SvgPathCommand('L', <Point<double>>[Point<double>(10.0, 10.0)]),
221 222 223 224 225
              ],
            ),
          ],
        ),
      ];
226
      expect(PathAnimation.fromFrameData(frameData, 0),
227 228 229 230
          const PathAnimationMatcher(PathAnimation(
              <PathCommandAnimation>[
                PathCommandAnimation('M', <List<Point<double>>>[
                  <Point<double>>[Point<double>(0.0, 0.0)],
231
                ]),
232 233
                PathCommandAnimation('L', <List<Point<double>>>[
                  <Point<double>>[Point<double>(10.0, 10.0)],
234 235
                ]),
              ],
236 237
              opacities: <double>[1.0],
          )),
238 239 240 241
      );
    });

    test('multiple paths', () {
242 243 244 245 246
      const List<FrameData> frameData = <FrameData>[
        FrameData(
          Point<double>(10.0, 10.0),
          <SvgPath>[
            SvgPath(
247
              'path_1',
248 249
              <SvgPathCommand>[
                SvgPathCommand('M', <Point<double>>[Point<double>(0.0, 0.0)]),
250 251
              ],
            ),
252
            SvgPath(
253
              'path_2',
254 255
              <SvgPathCommand>[
                SvgPathCommand('M', <Point<double>>[Point<double>(5.0, 6.0)]),
256 257 258 259 260
              ],
            ),
          ],
        ),
      ];
261
      expect(PathAnimation.fromFrameData(frameData, 0),
262 263 264 265
          const PathAnimationMatcher(PathAnimation(
              <PathCommandAnimation>[
                PathCommandAnimation('M', <List<Point<double>>>[
                  <Point<double>>[Point<double>(0.0, 0.0)],
266
                ]),
267
              ],
268 269
              opacities: <double>[1.0],
          )),
270 271
      );

272
      expect(PathAnimation.fromFrameData(frameData, 1),
273 274 275 276
          const PathAnimationMatcher(PathAnimation(
              <PathCommandAnimation>[
                PathCommandAnimation('M', <List<Point<double>>>[
                  <Point<double>>[Point<double>(5.0, 6.0)],
277
                ]),
278
              ],
279 280
              opacities: <double>[1.0],
          )),
281 282 283 284
      );
    });

    test('multiple frames', () {
285 286 287 288 289
      const List<FrameData> frameData = <FrameData>[
        FrameData(
          Point<double>(10.0, 10.0),
          <SvgPath>[
            SvgPath(
290
              'path_1',
291
              <SvgPathCommand>[
292
                SvgPathCommand('M', <Point<double>>[Point<double>(0.0, 0.0)]),
293 294 295 296 297
              ],
              opacity: 0.5,
            ),
          ],
        ),
298 299 300 301
        FrameData(
          Point<double>(10.0, 10.0),
          <SvgPath>[
            SvgPath(
302
              'path_1',
303
              <SvgPathCommand>[
304
                SvgPathCommand('M', <Point<double>>[Point<double>(10.0, 10.0)]),
305 306 307 308 309
              ],
            ),
          ],
        ),
      ];
310
      expect(PathAnimation.fromFrameData(frameData, 0),
311 312 313 314 315 316
          const PathAnimationMatcher(PathAnimation(
              <PathCommandAnimation>[
                PathCommandAnimation('M', <List<Point<double>>>[
                  <Point<double>>[
                    Point<double>(0.0, 0.0),
                    Point<double>(10.0, 10.0),
317 318 319
                  ],
                ]),
              ],
320 321
              opacities: <double>[0.5, 1.0],
          )),
322 323 324 325 326 327
      );
    });
  });

  group('create Animation', () {
    test('multiple paths', () {
328 329 330 331 332
      const List<FrameData> frameData = <FrameData>[
        FrameData(
          Point<double>(10.0, 10.0),
          <SvgPath>[
            SvgPath(
333
              'path_1',
334 335
              <SvgPathCommand>[
                SvgPathCommand('M', <Point<double>>[Point<double>(0.0, 0.0)]),
336 337
              ],
            ),
338
            SvgPath(
339
              'path_1',
340 341
              <SvgPathCommand>[
                SvgPathCommand('M', <Point<double>>[Point<double>(5.0, 6.0)]),
342 343 344 345 346
              ],
            ),
          ],
        ),
      ];
347
      final Animation animation = Animation.fromFrameData(frameData);
348
      expect(animation.paths[0],
349 350 351 352
          const PathAnimationMatcher(PathAnimation(
              <PathCommandAnimation>[
                PathCommandAnimation('M', <List<Point<double>>>[
                  <Point<double>>[Point<double>(0.0, 0.0)],
353
                ]),
354
              ],
355 356
              opacities: <double>[1.0],
          )),
357 358 359
      );

      expect(animation.paths[1],
360 361 362 363
          const PathAnimationMatcher(PathAnimation(
              <PathCommandAnimation>[
                PathCommandAnimation('M', <List<Point<double>>>[
                  <Point<double>>[Point<double>(5.0, 6.0)],
364
                ]),
365
              ],
366 367
              opacities: <double>[1.0],
          )),
368 369 370 371 372 373 374 375
      );

      expect(animation.size, const Point<double>(10.0, 10.0));
    });
  });

  group('toDart', () {
    test('_PathMoveTo', () {
376
      const PathCommandAnimation command = PathCommandAnimation(
377
        'M',
378 379 380 381
        <List<Point<double>>>[
          <Point<double>>[
            Point<double>(1.0, 2.0),
            Point<double>(3.0, 4.0),
382 383 384 385 386 387 388 389 390 391
          ],
        ],
      );

      expect(command.toDart(),
          '        const _PathMoveTo(\n'
          '          const <Offset>[\n'
          '            const Offset(1.0, 2.0),\n'
          '            const Offset(3.0, 4.0),\n'
          '          ],\n'
392
          '        ),\n',
393 394 395 396 397

      );
    });

    test('_PathLineTo', () {
398
      const PathCommandAnimation command = PathCommandAnimation(
399
        'L',
400 401 402 403
        <List<Point<double>>>[
          <Point<double>>[
            Point<double>(1.0, 2.0),
            Point<double>(3.0, 4.0),
404 405 406 407 408 409 410 411 412 413
          ],
        ],
      );

      expect(command.toDart(),
          '        const _PathLineTo(\n'
          '          const <Offset>[\n'
          '            const Offset(1.0, 2.0),\n'
          '            const Offset(3.0, 4.0),\n'
          '          ],\n'
414
          '        ),\n',
415 416 417 418 419

      );
    });

    test('_PathCubicTo', () {
420
      const PathCommandAnimation command = PathCommandAnimation(
421
        'C',
422 423 424 425
        <List<Point<double>>>[
          <Point<double>>[
            Point<double>(16.0, 24.0),
            Point<double>(16.0, 10.0),
426
          ],
427 428 429
          <Point<double>>[
            Point<double>(16.0, 25.0),
            Point<double>(16.0, 11.0),
430
          ],
431 432 433
          <Point<double>>[
            Point<double>(40.0, 40.0),
            Point<double>(40.0, 40.0),
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
          ],
        ],
      );

      expect(command.toDart(),
          '        const _PathCubicTo(\n'
          '          const <Offset>[\n'
          '            const Offset(16.0, 24.0),\n'
          '            const Offset(16.0, 10.0),\n'
          '          ],\n'
          '          const <Offset>[\n'
          '            const Offset(16.0, 25.0),\n'
          '            const Offset(16.0, 11.0),\n'
          '          ],\n'
          '          const <Offset>[\n'
          '            const Offset(40.0, 40.0),\n'
          '            const Offset(40.0, 40.0),\n'
          '          ],\n'
452
          '        ),\n',
453 454 455 456 457

      );
    });

    test('_PathClose', () {
458
      const PathCommandAnimation command = PathCommandAnimation(
459
        'Z',
460
        <List<Point<double>>>[],
461 462 463 464
      );

      expect(command.toDart(),
          '        const _PathClose(\n'
465
          '        ),\n',
466 467 468 469 470

      );
    });

    test('Unsupported path command', () {
471
      const PathCommandAnimation command = PathCommandAnimation(
472
        'h',
473
        <List<Point<double>>>[],
474 475 476 477
      );

      expect(
        () { command.toDart(); },
478
        throwsA(anything),
479 480 481 482
      );
    });

    test('_PathFrames', () {
483 484 485 486 487 488
      const PathAnimation pathAnimation = PathAnimation(
          <PathCommandAnimation>[
            PathCommandAnimation('M', <List<Point<double>>>[
              <Point<double>>[
                Point<double>(0.0, 0.0),
                Point<double>(10.0, 10.0),
489 490
              ],
            ]),
491 492 493 494
            PathCommandAnimation('L', <List<Point<double>>>[
              <Point<double>>[
                Point<double>(48.0, 10.0),
                Point<double>(0.0, 0.0),
495 496 497
              ],
            ]),
          ],
498
          opacities: <double>[0.5, 1.0],
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
      );

      expect(pathAnimation.toDart(),
          '    const _PathFrames(\n'
          '      opacities: const <double>[\n'
          '        0.5,\n'
          '        1.0,\n'
          '      ],\n'
          '      commands: const <_PathCommand>[\n'
          '        const _PathMoveTo(\n'
          '          const <Offset>[\n'
          '            const Offset(0.0, 0.0),\n'
          '            const Offset(10.0, 10.0),\n'
          '          ],\n'
          '        ),\n'
          '        const _PathLineTo(\n'
          '          const <Offset>[\n'
          '            const Offset(48.0, 10.0),\n'
          '            const Offset(0.0, 0.0),\n'
          '          ],\n'
          '        ),\n'
          '      ],\n'
521
          '    ),\n',
522 523 524 525
      );
    });

    test('Animation', () {
526 527 528 529 530 531 532 533 534
      const Animation animation = Animation(
          Point<double>(48.0, 48.0),
          <PathAnimation>[
            PathAnimation(
                <PathCommandAnimation>[
                  PathCommandAnimation('M', <List<Point<double>>>[
                    <Point<double>>[
                      Point<double>(0.0, 0.0),
                      Point<double>(10.0, 10.0),
535 536
                    ],
                  ]),
537 538 539 540
                  PathCommandAnimation('L', <List<Point<double>>>[
                    <Point<double>>[
                      Point<double>(48.0, 10.0),
                      Point<double>(0.0, 0.0),
541 542 543
                    ],
                  ]),
                ],
544
                opacities: <double>[0.5, 1.0],
545 546
            ),

547 548 549 550 551 552
            PathAnimation(
                <PathCommandAnimation>[
                  PathCommandAnimation('M', <List<Point<double>>>[
                    <Point<double>>[
                      Point<double>(0.0, 0.0),
                      Point<double>(10.0, 10.0),
553 554 555
                    ],
                  ]),
                ],
556
                opacities: <double>[0.5, 1.0],
557 558 559
            ),
          ]);

560
      expect(animation.toDart('_AnimatedIconData', r'_$data1'),
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
          'const _AnimatedIconData _\$data1 = const _AnimatedIconData(\n'
          '  const Size(48.0, 48.0),\n'
          '  const <_PathFrames>[\n'
          '    const _PathFrames(\n'
          '      opacities: const <double>[\n'
          '        0.5,\n'
          '        1.0,\n'
          '      ],\n'
          '      commands: const <_PathCommand>[\n'
          '        const _PathMoveTo(\n'
          '          const <Offset>[\n'
          '            const Offset(0.0, 0.0),\n'
          '            const Offset(10.0, 10.0),\n'
          '          ],\n'
          '        ),\n'
          '        const _PathLineTo(\n'
          '          const <Offset>[\n'
          '            const Offset(48.0, 10.0),\n'
          '            const Offset(0.0, 0.0),\n'
          '          ],\n'
          '        ),\n'
          '      ],\n'
          '    ),\n'
          '    const _PathFrames(\n'
          '      opacities: const <double>[\n'
          '        0.5,\n'
          '        1.0,\n'
          '      ],\n'
          '      commands: const <_PathCommand>[\n'
          '        const _PathMoveTo(\n'
          '          const <Offset>[\n'
          '            const Offset(0.0, 0.0),\n'
          '            const Offset(10.0, 10.0),\n'
          '          ],\n'
          '        ),\n'
          '      ],\n'
          '    ),\n'
          '  ],\n'
599
          ');',
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622
      );
    });
  });
}

// Matches all path commands' points within an error margin.
class PathMatcher extends Matcher {
  const PathMatcher(this.actual, {this.margin = 0.0});

  final SvgPath actual;
  final double margin;

  @override
  Description describe(Description description) => description.add('$actual$margin)');

  @override
  bool matches(dynamic item, Map<dynamic, dynamic> matchState) {
    if (item == null || actual == null)
      return item == actual;

    if (item.runtimeType != actual.runtimeType)
      return false;

623
    final SvgPath other = item as SvgPath;
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
    if (other.id != actual.id || other.opacity != actual.opacity)
      return false;

    if (other.commands.length != actual.commands.length)
      return false;

    for (int i = 0; i < other.commands.length; i += 1) {
      if (!commandsMatch(actual.commands[i], other.commands[i]))
        return false;
    }
    return true;
  }

  bool commandsMatch(SvgPathCommand actual, SvgPathCommand other) {
    if (other.points.length != actual.points.length)
      return false;

    for (int i = 0; i < other.points.length; i += 1) {
      if ((other.points[i].x - actual.points[i].x).abs() > margin)
        return false;
      if ((other.points[i].y - actual.points[i].y).abs() > margin)
        return false;
    }
    return true;
  }
}

class PathAnimationMatcher extends Matcher {
  const PathAnimationMatcher(this.expected);

  final PathAnimation expected;

  @override
  Description describe(Description description) => description.add('$expected');

  @override
  bool matches(dynamic item, Map<dynamic, dynamic> matchState) {
    if (item == null || expected == null)
      return item == expected;

    if (item.runtimeType != expected.runtimeType)
      return false;

667
    final PathAnimation other = item as PathAnimation;
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694

    if (!const ListEquality<double>().equals(other.opacities, expected.opacities))
      return false;

    if (other.commands.length != expected.commands.length)
      return false;

    for (int i = 0; i < other.commands.length; i += 1) {
      if (!commandsMatch(expected.commands[i], other.commands[i]))
        return false;
    }
    return true;
  }

  bool commandsMatch(PathCommandAnimation expected, PathCommandAnimation other) {
    if (other.points.length != expected.points.length)
      return false;

    for (int i = 0; i < other.points.length; i += 1)
      if (!const ListEquality<Point<double>>().equals(other.points[i], expected.points[i]))
        return false;

    return true;
  }
}

String testAsset(String name) {
695
  return path.join('test_assets', name);
696
}