paragraph_intrinsics_test.dart 3.76 KB
Newer Older
1 2 3 4 5
// Copyright 2015 The Chromium Authors. All rights reserved.
// 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 '../flutter_test_alternative.dart';
7 8

void main() {
9
  test('list body and paragraph intrinsics', () {
10
    final RenderParagraph paragraph = RenderParagraph(
11
      const TextSpan(
12
        style: TextStyle(height: 1.0),
Ian Hickson's avatar
Ian Hickson committed
13 14 15
        text: 'Hello World',
      ),
      textDirection: TextDirection.ltr,
16
    );
17
    final RenderListBody testBlock = RenderListBody(
18 19
      children: <RenderBox>[
        paragraph,
20
      ],
21 22
    );

23 24
    final double textWidth = paragraph.getMaxIntrinsicWidth(double.infinity);
    final double oneLineTextHeight = paragraph.getMinIntrinsicHeight(double.infinity);
25
    final double constrainedWidth = textWidth * 0.9;
26
    final double wrappedTextWidth = paragraph.getMinIntrinsicWidth(double.infinity);
27 28 29 30 31 32 33 34 35
    final double twoLinesTextHeight = paragraph.getMinIntrinsicHeight(constrainedWidth);
    final double manyLinesTextHeight = paragraph.getMinIntrinsicHeight(0.0);

    // paragraph
    expect(wrappedTextWidth, greaterThan(0.0));
    expect(wrappedTextWidth, lessThan(textWidth));
    expect(oneLineTextHeight, lessThan(twoLinesTextHeight));
    expect(twoLinesTextHeight, lessThan(oneLineTextHeight * 3.0));
    expect(manyLinesTextHeight, greaterThan(twoLinesTextHeight));
36
    expect(paragraph.getMaxIntrinsicHeight(double.infinity), equals(oneLineTextHeight));
37 38 39 40
    expect(paragraph.getMaxIntrinsicHeight(constrainedWidth), equals(twoLinesTextHeight));
    expect(paragraph.getMaxIntrinsicHeight(0.0), equals(manyLinesTextHeight));

    // vertical block (same expectations)
41 42 43
    expect(testBlock.getMinIntrinsicWidth(double.infinity), equals(wrappedTextWidth));
    expect(testBlock.getMaxIntrinsicWidth(double.infinity), equals(textWidth));
    expect(testBlock.getMinIntrinsicHeight(double.infinity), equals(oneLineTextHeight));
44
    expect(testBlock.getMinIntrinsicHeight(constrainedWidth), equals(twoLinesTextHeight));
45
    expect(testBlock.getMaxIntrinsicHeight(double.infinity), equals(oneLineTextHeight));
46 47 48 49 50 51 52 53 54
    expect(testBlock.getMaxIntrinsicHeight(constrainedWidth), equals(twoLinesTextHeight));
    expect(testBlock.getMinIntrinsicWidth(0.0), equals(wrappedTextWidth));
    expect(testBlock.getMaxIntrinsicWidth(0.0), equals(textWidth));
    expect(testBlock.getMinIntrinsicHeight(wrappedTextWidth), equals(twoLinesTextHeight));
    expect(testBlock.getMaxIntrinsicHeight(wrappedTextWidth), equals(twoLinesTextHeight));
    expect(testBlock.getMinIntrinsicHeight(0.0), equals(manyLinesTextHeight));
    expect(testBlock.getMaxIntrinsicHeight(0.0), equals(manyLinesTextHeight));

    // horizontal block (same expectations again)
55
    testBlock.axisDirection = AxisDirection.right;
56 57 58
    expect(testBlock.getMinIntrinsicWidth(double.infinity), equals(wrappedTextWidth));
    expect(testBlock.getMaxIntrinsicWidth(double.infinity), equals(textWidth));
    expect(testBlock.getMinIntrinsicHeight(double.infinity), equals(oneLineTextHeight));
59
    expect(testBlock.getMinIntrinsicHeight(constrainedWidth), equals(twoLinesTextHeight));
60
    expect(testBlock.getMaxIntrinsicHeight(double.infinity), equals(oneLineTextHeight));
61 62 63 64 65 66 67 68 69
    expect(testBlock.getMaxIntrinsicHeight(constrainedWidth), equals(twoLinesTextHeight));
    expect(testBlock.getMinIntrinsicWidth(0.0), equals(wrappedTextWidth));
    expect(testBlock.getMaxIntrinsicWidth(0.0), equals(textWidth));
    expect(testBlock.getMinIntrinsicHeight(wrappedTextWidth), equals(twoLinesTextHeight));
    expect(testBlock.getMaxIntrinsicHeight(wrappedTextWidth), equals(twoLinesTextHeight));
    expect(testBlock.getMinIntrinsicHeight(0.0), equals(manyLinesTextHeight));
    expect(testBlock.getMaxIntrinsicHeight(0.0), equals(manyLinesTextHeight));
  });
}