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

import 'package:flutter/painting.dart';
import 'package:flutter_test/flutter_test.dart';

import '../rendering/mock_canvas.dart';
9
import 'common_matchers.dart';
10

Ian Hickson's avatar
Ian Hickson committed
11
void main() {
12 13 14
  test('CircleBorder defaults', () {
    const CircleBorder border = CircleBorder();
    expect(border.side, BorderSide.none);
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
    expect(border.eccentricity, 0.0);
  });

  test('CircleBorder getInnerPath and getOuterPath', () {
    const Rect circleRect = Rect.fromLTWH(50, 0, 100, 100);
    const Rect rect = Rect.fromLTWH(0, 0, 200, 100);

    expect(const CircleBorder().getInnerPath(rect).getBounds(), circleRect);
    expect(const CircleBorder().getOuterPath(rect).getBounds(), circleRect);

    const CircleBorder oval = CircleBorder(eccentricity: 1.0);
    expect(oval.getOuterPath(rect).getBounds(), rect);
    expect(oval.getInnerPath(rect).getBounds(), rect);

    const CircleBorder o10 = CircleBorder(side: BorderSide(width: 10.0), eccentricity: 1.0);
    expect(o10.getOuterPath(rect).getBounds(), Offset.zero & const Size(200, 100));
    expect(o10.getInnerPath(rect).getBounds(), const Offset(10, 10) & const Size(180, 80));
32 33 34 35 36
  });

  test('CircleBorder copyWith, ==, hashCode', () {
    expect(const CircleBorder(), const CircleBorder().copyWith());
    expect(const CircleBorder().hashCode, const CircleBorder().copyWith().hashCode);
37
    expect(const CircleBorder(eccentricity: 0.5).hashCode, const CircleBorder().copyWith(eccentricity: 0.5).hashCode);
38 39 40 41
    const BorderSide side = BorderSide(width: 10.0, color: Color(0xff123456));
    expect(const CircleBorder().copyWith(side: side), const CircleBorder(side: side));
  });

Ian Hickson's avatar
Ian Hickson committed
42
  test('CircleBorder', () {
43 44 45
    const CircleBorder c10 = CircleBorder(side: BorderSide(width: 10.0));
    const CircleBorder c15 = CircleBorder(side: BorderSide(width: 15.0));
    const CircleBorder c20 = CircleBorder(side: BorderSide(width: 20.0));
Ian Hickson's avatar
Ian Hickson committed
46 47 48 49 50 51
    expect(c10.dimensions, const EdgeInsets.all(10.0));
    expect(c10.scale(2.0), c20);
    expect(c20.scale(0.5), c10);
    expect(ShapeBorder.lerp(c10, c20, 0.0), c10);
    expect(ShapeBorder.lerp(c10, c20, 0.5), c15);
    expect(ShapeBorder.lerp(c10, c20, 1.0), c20);
52 53
    expect(c10.getInnerPath(Rect.fromCircle(center: Offset.zero, radius: 1.0).inflate(10.0)), isUnitCircle);
    expect(c10.getOuterPath(Rect.fromCircle(center: Offset.zero, radius: 1.0)), isUnitCircle);
Ian Hickson's avatar
Ian Hickson committed
54
    expect(
Dan Field's avatar
Dan Field committed
55
      (Canvas canvas) => c10.paint(canvas, const Rect.fromLTWH(10.0, 20.0, 30.0, 40.0)),
Ian Hickson's avatar
Ian Hickson committed
56
      paints
57
        ..circle(x: 25.0, y: 40.0, radius: 10.0, strokeWidth: 10.0),
Ian Hickson's avatar
Ian Hickson committed
58
    );
59
  });
Ian Hickson's avatar
Ian Hickson committed
60
}