table_border_test.dart 5.62 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 11 12 13
    const TableBorder border1 = TableBorder(
      left: BorderSide(width: 1.0),
      right: BorderSide(color: Color(0xFF00FF00)),
      verticalInside: BorderSide(),
14 15
    );
    expect(border1.top, BorderSide.none);
16
    expect(border1.right, const BorderSide(color: Color(0xFF00FF00)));
17 18 19
    expect(border1.bottom, BorderSide.none);
    expect(border1.left, const BorderSide(width: 1.0));
    expect(border1.horizontalInside, BorderSide.none);
20
    expect(border1.verticalInside, const BorderSide(width: 1.0, color: Color(0xFF000000)));
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
      inside: const BorderSide(width: 0.0, style: BorderStyle.none),
61
      outside: const BorderSide(width: 0.0, color: Color(0xFFFF0000), style: BorderStyle.none),
62 63 64 65
    ));
  });

  test('TableBorder.lerp', () {
66 67 68 69 70 71
    const BorderSide side1 = BorderSide(width: 1.0, color: Color(0x00000001));
    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));
72
    const TableBorder tableA = TableBorder(
73 74 75 76 77 78 79 80 81
      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));
82
    final TableBorder tableB = TableBorder(
83 84 85 86 87 88 89 90 91
      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);
92
    final TableBorder tableC = TableBorder(
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
      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);
    expect(TableBorder.lerp(tableA, tableC, 0.9195).isUniform, isFalse);
    expect(TableBorder.lerp(tableA, tableC, 0.9195).dimensions,
           EdgeInsets.lerp(tableA.dimensions, tableC.dimensions, 0.9195));
  });

  test('TableBorder.lerp with nulls', () {
111 112
    final TableBorder table2 = TableBorder.all(width: 2.0);
    final TableBorder table1 = TableBorder.all(width: 1.0);
113 114 115 116 117 118 119
    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));
120
    expect(const TableBorder().hashCode, isNot(const TableBorder(top: BorderSide(width: 0.0)).hashCode));
121 122 123 124 125 126 127
  });

  test('TableBorder Object API', () {
    final String none = BorderSide.none.toString();
    expect(const TableBorder().toString(), 'TableBorder($none, $none, $none, $none, $none, $none)');
  });
}