overflow_test.dart 1.68 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
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

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

import 'rendering_tester.dart';

void main() {
Ian Hickson's avatar
Ian Hickson committed
11
  test('overflow should not affect baseline', () {
12
    RenderBox root, child, text;
13
    late double baseline1, baseline2, height1, height2;
14

15 16 17
    root = RenderPositionedBox(
      child: RenderCustomPaint(
        child: child = text = RenderParagraph(
Ian Hickson's avatar
Ian Hickson committed
18 19 20
          const TextSpan(text: 'Hello World'),
          textDirection: TextDirection.ltr,
        ),
21
        painter: TestCallbackPainter(
22
          onPaint: () {
23
            baseline1 = child.getDistanceToBaseline(TextBaseline.alphabetic)!;
24
            height1 = text.size.height;
25 26 27
          },
        ),
      ),
28 29 30
    );
    layout(root, phase: EnginePhase.paint);

31 32 33 34
    root = RenderPositionedBox(
      child: RenderCustomPaint(
        child: child = RenderConstrainedOverflowBox(
          child: text = RenderParagraph(
Ian Hickson's avatar
Ian Hickson committed
35 36 37
            const TextSpan(text: 'Hello World'),
            textDirection: TextDirection.ltr,
          ),
38
          maxHeight: height1 / 2.0,
39
          alignment: Alignment.topLeft,
40
        ),
41
        painter: TestCallbackPainter(
42
          onPaint: () {
43
            baseline2 = child.getDistanceToBaseline(TextBaseline.alphabetic)!;
44
            height2 = text.size.height;
45 46 47
          },
        ),
      ),
48 49 50 51 52 53 54 55 56
    );
    layout(root, phase: EnginePhase.paint);

    expect(baseline1, lessThan(height1));
    expect(height2, equals(height1 / 2.0));
    expect(baseline2, equals(baseline1));
    expect(baseline2, greaterThan(height2));
  });
}