table_border_test.dart 5.8 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 8 9
// 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';
import 'package:flutter_test/flutter_test.dart';

void main() {
  test('TableBorder constructor', () {
10
    const TableBorder border1 = TableBorder(
11
      left: BorderSide(),
12 13
      right: BorderSide(color: Color(0xFF00FF00)),
      verticalInside: BorderSide(),
14 15
    );
    expect(border1.top, BorderSide.none);
16
    expect(border1.right, const BorderSide(color: Color(0xFF00FF00)));
17
    expect(border1.bottom, BorderSide.none);
18
    expect(border1.left, const BorderSide());
19
    expect(border1.horizontalInside, BorderSide.none);
20
    expect(border1.verticalInside, const BorderSide());
21 22 23
    expect(border1.dimensions, const EdgeInsets.symmetric(horizontal: 1.0));
    expect(border1.isUniform, isFalse);
    expect(border1.scale(2.0), const TableBorder(
24 25 26
      left: BorderSide(width: 2.0),
      right: BorderSide(width: 2.0, color: Color(0xFF00FF00)),
      verticalInside: BorderSide(width: 2.0),
27 28 29 30
    ));
  });

  test('TableBorder.all constructor', () {
31
    final TableBorder border2 = TableBorder.all(
32 33 34
      width: 2.0,
      color: const Color(0xFF00FFFF),
    );
35 36 37 38 39 40
    expect(border2.top, const BorderSide(width: 2.0, color: Color(0xFF00FFFF)));
    expect(border2.right, const BorderSide(width: 2.0, color: Color(0xFF00FFFF)));
    expect(border2.bottom, const BorderSide(width: 2.0, color: Color(0xFF00FFFF)));
    expect(border2.left, const BorderSide(width: 2.0, color: Color(0xFF00FFFF)));
    expect(border2.horizontalInside, const BorderSide(width: 2.0, color: Color(0xFF00FFFF)));
    expect(border2.verticalInside, const BorderSide(width: 2.0, color: Color(0xFF00FFFF)));
41 42
    expect(border2.dimensions, const EdgeInsets.symmetric(horizontal: 2.0, vertical: 2.0));
    expect(border2.isUniform, isTrue);
43
    expect(border2.scale(0.5), TableBorder.all(color: const Color(0xFF00FFFF)));
44 45 46
  });

  test('TableBorder.symmetric constructor', () {
47
    final TableBorder border3 = TableBorder.symmetric(
48
      inside: const BorderSide(width: 3.0),
49
      outside: const BorderSide(color: Color(0xFFFF0000)),
50
    );
51 52 53 54
    expect(border3.top, const BorderSide(color: Color(0xFFFF0000)));
    expect(border3.right, const BorderSide(color: Color(0xFFFF0000)));
    expect(border3.bottom, const BorderSide(color: Color(0xFFFF0000)));
    expect(border3.left, const BorderSide(color: Color(0xFFFF0000)));
55 56 57 58
    expect(border3.horizontalInside, const BorderSide(width: 3.0));
    expect(border3.verticalInside, const BorderSide(width: 3.0));
    expect(border3.dimensions, const EdgeInsets.symmetric(horizontal: 1.0, vertical: 1.0));
    expect(border3.isUniform, isFalse);
59
    expect(border3.scale(0.0), TableBorder.symmetric(
60
      outside: const BorderSide(width: 0.0, color: Color(0xFFFF0000), style: BorderStyle.none),
61 62 63 64
    ));
  });

  test('TableBorder.lerp', () {
65
    const BorderSide side1 = BorderSide(color: Color(0x00000001));
66 67 68 69 70
    const BorderSide side2 = BorderSide(width: 2.0, color: Color(0x00000002));
    const BorderSide side3 = BorderSide(width: 3.0, color: Color(0x00000003));
    const BorderSide side4 = BorderSide(width: 4.0, color: Color(0x00000004));
    const BorderSide side5 = BorderSide(width: 5.0, color: Color(0x00000005));
    const BorderSide side6 = BorderSide(width: 6.0, color: Color(0x00000006));
71
    const TableBorder tableA = TableBorder(
72 73 74 75 76 77 78 79 80
      top: side1,
      right: side2,
      bottom: side3,
      left: side4,
      horizontalInside: side5,
      verticalInside: side6,
    );
    expect(tableA.isUniform, isFalse);
    expect(tableA.dimensions, const EdgeInsets.fromLTRB(4.0, 1.0, 2.0, 3.0));
81
    final TableBorder tableB = TableBorder(
82 83 84 85 86 87 88 89 90
      top: side1.scale(2.0),
      right: side2.scale(2.0),
      bottom: side3.scale(2.0),
      left: side4.scale(2.0),
      horizontalInside: side5.scale(2.0),
      verticalInside: side6.scale(2.0),
    );
    expect(tableB.isUniform, isFalse);
    expect(tableB.dimensions, const EdgeInsets.fromLTRB(4.0, 1.0, 2.0, 3.0) * 2.0);
91
    final TableBorder tableC = TableBorder(
92 93 94 95 96 97 98 99 100 101 102 103
      top: side1.scale(3.0),
      right: side2.scale(3.0),
      bottom: side3.scale(3.0),
      left: side4.scale(3.0),
      horizontalInside: side5.scale(3.0),
      verticalInside: side6.scale(3.0),
    );
    expect(tableC.isUniform, isFalse);
    expect(tableC.dimensions, const EdgeInsets.fromLTRB(4.0, 1.0, 2.0, 3.0) * 3.0);
    expect(TableBorder.lerp(tableA, tableC, 0.5), tableB);
    expect(TableBorder.lerp(tableA, tableB, 2.0), tableC);
    expect(TableBorder.lerp(tableB, tableC, -1.0), tableA);
104
    expect(TableBorder.lerp(tableA, tableC, 0.9195)!.isUniform, isFalse);
105 106 107 108
    expect(
      TableBorder.lerp(tableA, tableC, 0.9195)!.dimensions,
      EdgeInsets.lerp(tableA.dimensions, tableC.dimensions, 0.9195),
    );
109 110 111
  });

  test('TableBorder.lerp with nulls', () {
112
    final TableBorder table2 = TableBorder.all(width: 2.0);
113
    final TableBorder table1 = TableBorder.all();
114 115 116 117 118 119 120
    expect(TableBorder.lerp(table2, null, 0.5), table1);
    expect(TableBorder.lerp(null, table2, 0.5), table1);
    expect(TableBorder.lerp(null, null, 0.5), null);
  });

  test('TableBorder Object API', () {
    expect(const TableBorder(), isNot(1.0));
121
    expect(const TableBorder().hashCode, isNot(const TableBorder(top: BorderSide(width: 0.0)).hashCode));
122 123 124 125
  });

  test('TableBorder Object API', () {
    final String none = BorderSide.none.toString();
126 127
    final String zeroRadius = BorderRadius.zero.toString();
    expect(const TableBorder().toString(), 'TableBorder($none, $none, $none, $none, $none, $none, $zeroRadius)');
128
  });
129 130

  test('TableBorder.all with a borderRadius', () {
131 132
    final TableBorder tableA = TableBorder.all(borderRadius: const BorderRadius.all(Radius.circular(8.0)));
    expect(tableA.borderRadius, const BorderRadius.all(Radius.circular(8.0)));
133 134
  });

135
}