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

import 'package:flutter/rendering.dart';
6
import 'package:flutter_test/flutter_test.dart';
7 8 9

void main() {
  test('RelativeRect.==', () {
10
    const RelativeRect r = RelativeRect.fromLTRB(10.0, 20.0, 30.0, 40.0);
Dan Field's avatar
Dan Field committed
11
    expect(r, RelativeRect.fromSize(const Rect.fromLTWH(10.0, 20.0, 0.0, 0.0), const Size(40.0, 60.0)));
12
  });
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
  test('RelativeRect.fromDirectional', () {
    final RelativeRect r1 = RelativeRect.fromDirectional(
      textDirection: TextDirection.ltr,
      start: 10.0,
      top: 20.0,
      end: 30.0,
      bottom: 40.0,
    );
    final RelativeRect r2 = RelativeRect.fromDirectional(
      textDirection: TextDirection.rtl,
      start: 10.0,
      top: 20.0,
      end: 30.0,
      bottom: 40.0,
    );
    expect(r1, const RelativeRect.fromLTRB(10.0, 20.0, 30.0, 40.0));
    expect(r2, const RelativeRect.fromLTRB(30.0, 20.0, 10.0, 40.0));
  });
31
  test('RelativeRect.shift', () {
32
    const RelativeRect r1 = RelativeRect.fromLTRB(10.0, 20.0, 30.0, 40.0);
33
    final RelativeRect r2 = r1.shift(const Offset(5.0, 50.0));
34 35 36
    expect(r2, const RelativeRect.fromLTRB(15.0, 70.0, 25.0, -10.0));
  });
  test('RelativeRect.inflate', () {
37
    const RelativeRect r1 = RelativeRect.fromLTRB(10.0, 20.0, 30.0, 40.0);
38
    final RelativeRect r2 = r1.inflate(5.0);
39 40 41
    expect(r2, const RelativeRect.fromLTRB(5.0, 15.0, 25.0, 35.0));
  });
  test('RelativeRect.deflate', () {
42
    const RelativeRect r1 = RelativeRect.fromLTRB(10.0, 20.0, 30.0, 40.0);
43
    final RelativeRect r2 = r1.deflate(5.0);
44 45 46
    expect(r2, const RelativeRect.fromLTRB(15.0, 25.0, 35.0, 45.0));
  });
  test('RelativeRect.intersect', () {
47 48
    const RelativeRect r1 = RelativeRect.fromLTRB(10.0, 20.0, 30.0, 40.0);
    const RelativeRect r2 = RelativeRect.fromLTRB(0.0, 30.0, 60.0, 0.0);
49 50
    final RelativeRect r3 = r1.intersect(r2);
    final RelativeRect r4 = r2.intersect(r1);
51 52 53 54
    expect(r3, r4);
    expect(r3, const RelativeRect.fromLTRB(10.0, 30.0, 60.0, 40.0));
  });
  test('RelativeRect.toRect', () {
55
    const RelativeRect r1 = RelativeRect.fromLTRB(10.0, 20.0, 30.0, 40.0);
Dan Field's avatar
Dan Field committed
56 57
    final Rect r2 = r1.toRect(const Rect.fromLTRB(10.0, 20.0, 90.0, 180.0));
    expect(r2, const Rect.fromLTRB(10.0, 20.0, 50.0, 120.0));
58
  });
Ian Hickson's avatar
Ian Hickson committed
59
  test('RelativeRect.toSize', () {
60
    const RelativeRect r1 = RelativeRect.fromLTRB(10.0, 20.0, 30.0, 40.0);
Ian Hickson's avatar
Ian Hickson committed
61 62 63
    final Size r2 = r1.toSize(const Size(80.0, 160.0));
    expect(r2, const Size(40.0, 100.0));
  });
64
  test('RelativeRect.lerp', () {
65
    const RelativeRect r1 = RelativeRect.fill;
66
    const RelativeRect r2 = RelativeRect.fromLTRB(10.0, 20.0, 30.0, 40.0);
67
    final RelativeRect r3 = RelativeRect.lerp(r1, r2, 0.5)!;
68 69 70
    expect(r3, const RelativeRect.fromLTRB(5.0, 10.0, 15.0, 20.0));
  });
}