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 11 12 13 14 15 16 17 18 19
import 'package:vitool/vitool.dart';
import 'package:path/path.dart' as path;

const String kPackagePath = '..';

void main() {

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

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

  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')); },
50
        throwsA(anything),
51 52 53 54 55 56
      );
    });

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

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

    test('horizontal bar', () {
      final FrameData frameData = interpretSvg(testAsset('horizontal_bar.svg'));
      expect(frameData.paths, <SvgPath>[
69 70 71 72 73 74
        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>>[]),
75 76 77 78 79 80 81 82 83 84 85
        ]),
      ]);
    });

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

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


    test('SVG group', () {
      final FrameData frameData = interpretSvg(testAsset('bars_group.svg'));
      expect(frameData.paths, const <SvgPath>[
94 95 96 97 98 99
        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>>[]),
100
        ]),
101 102 103 104 105 106
        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>>[]),
107 108 109 110 111 112 113
        ]),
      ]);
    });

    test('SVG group translate', () {
      final FrameData frameData = interpretSvg(testAsset('bar_group_translate.svg'));
      expect(frameData.paths, const <SvgPath>[
114 115 116 117 118 119
        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>>[]),
120 121 122 123 124 125 126
        ]),
      ]);
    });

    test('SVG group scale', () {
      final FrameData frameData = interpretSvg(testAsset('bar_group_scale.svg'));
      expect(frameData.paths, const <SvgPath>[
127 128 129 130 131 132 133
        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>>[]),
134 135 136 137 138 139 140
        ]),
      ]);
    });

    test('SVG group rotate scale', () {
      final FrameData frameData = interpretSvg(testAsset('bar_group_rotate_scale.svg'));
      expect(frameData.paths, const <PathMatcher>[
141 142 143 144 145 146 147 148
        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>>[]),
149
            ]),
150
            margin: precisionErrorTolerance,
151
        ),
152 153 154 155 156 157
      ]);
    });

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

    test('SVG group opacity', () {
      final FrameData frameData = interpretSvg(testAsset('bar_group_opacity.svg'));
      expect(frameData.paths, const <SvgPath>[
165
        SvgPath(
166
          'path_1',
167 168 169 170 171 172
          <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>>[]),
173 174 175 176 177 178 179 180 181 182
          ],
          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>[
183 184 185 186 187 188 189
        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>>[]),
190 191 192 193 194 195 196 197
        ]),
      ]);
    });

    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>[
198 199 200 201 202 203 204 205 206
        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>>[]),
207 208 209 210 211 212 213
        ]),
      ]);
    });
  });

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

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

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

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

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

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

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

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

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

      );
    });

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

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

      );
    });

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

      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'
454
          '        ),\n',
455 456 457 458 459

      );
    });

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

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

      );
    });

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

      expect(
        () { command.toDart(); },
480
        throwsA(anything),
481 482 483 484
      );
    });

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

      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'
523
          '    ),\n',
524 525 526 527
      );
    });

    test('Animation', () {
528 529 530 531 532 533 534 535 536
      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),
537 538
                    ],
                  ]),
539 540 541 542
                  PathCommandAnimation('L', <List<Point<double>>>[
                    <Point<double>>[
                      Point<double>(48.0, 10.0),
                      Point<double>(0.0, 0.0),
543 544 545
                    ],
                  ]),
                ],
546
                opacities: <double>[0.5, 1.0],
547 548
            ),

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

562
      expect(animation.toDart('_AnimatedIconData', r'_$data1'),
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 599 600
          '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'
601
          ');',
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
      );
    });
  });
}

// 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;

625
    final SvgPath other = item as SvgPath;
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 667 668
    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;

669
    final PathAnimation other = item as PathAnimation;
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 695 696 697 698

    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) {
  return path.join(kPackagePath, 'test_assets', name);
}