Improve test coverage in rendering.dart (#4775)
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
/// The Flutter rendering tree.
|
||||
///
|
||||
///
|
||||
/// To use, import `package:flutter/rendering.dart`.
|
||||
///
|
||||
/// The [RenderObject] hierarchy is used by the Flutter Widgets
|
||||
@@ -48,6 +48,7 @@ export 'src/rendering/semantics.dart';
|
||||
export 'src/rendering/shifted_box.dart';
|
||||
export 'src/rendering/stack.dart';
|
||||
export 'src/rendering/table.dart';
|
||||
export 'src/rendering/tweens.dart';
|
||||
export 'src/rendering/view.dart';
|
||||
export 'src/rendering/viewport.dart';
|
||||
|
||||
|
||||
@@ -51,13 +51,13 @@ class RenderBlock extends RenderBox
|
||||
}
|
||||
|
||||
BoxConstraints _getInnerConstraints(BoxConstraints constraints) {
|
||||
assert(_mainAxis != null);
|
||||
switch (_mainAxis) {
|
||||
case Axis.horizontal:
|
||||
return new BoxConstraints.tightFor(height: constraints.maxHeight);
|
||||
case Axis.vertical:
|
||||
return new BoxConstraints.tightFor(width: constraints.maxWidth);
|
||||
}
|
||||
assert(_mainAxis != null);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -66,13 +66,13 @@ class RenderBlock extends RenderBox
|
||||
if (child == null)
|
||||
return 0.0;
|
||||
BoxParentData parentData = child.parentData;
|
||||
assert(mainAxis != null);
|
||||
switch (mainAxis) {
|
||||
case Axis.horizontal:
|
||||
return parentData.offset.dx + child.size.width;
|
||||
case Axis.vertical:
|
||||
return parentData.offset.dy + child.size.height;
|
||||
}
|
||||
assert(mainAxis != null);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -183,49 +183,49 @@ class RenderBlock extends RenderBox
|
||||
|
||||
@override
|
||||
double computeMinIntrinsicWidth(double height) {
|
||||
assert(mainAxis != null);
|
||||
switch (mainAxis) {
|
||||
case Axis.horizontal:
|
||||
return _getIntrinsicMainAxis((RenderBox child) => child.getMinIntrinsicWidth(height));
|
||||
case Axis.vertical:
|
||||
return _getIntrinsicCrossAxis((RenderBox child) => child.getMinIntrinsicWidth(height));
|
||||
}
|
||||
assert(mainAxis != null);
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
double computeMaxIntrinsicWidth(double height) {
|
||||
assert(mainAxis != null);
|
||||
switch (mainAxis) {
|
||||
case Axis.horizontal:
|
||||
return _getIntrinsicMainAxis((RenderBox child) => child.getMaxIntrinsicWidth(height));
|
||||
case Axis.vertical:
|
||||
return _getIntrinsicCrossAxis((RenderBox child) => child.getMaxIntrinsicWidth(height));
|
||||
}
|
||||
assert(mainAxis != null);
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
double computeMinIntrinsicHeight(double width) {
|
||||
assert(mainAxis != null);
|
||||
switch (mainAxis) {
|
||||
case Axis.horizontal:
|
||||
return _getIntrinsicMainAxis((RenderBox child) => child.getMinIntrinsicHeight(width));
|
||||
case Axis.vertical:
|
||||
return _getIntrinsicCrossAxis((RenderBox child) => child.getMinIntrinsicHeight(width));
|
||||
}
|
||||
assert(mainAxis != null);
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
double computeMaxIntrinsicHeight(double width) {
|
||||
assert(mainAxis != null);
|
||||
switch (mainAxis) {
|
||||
case Axis.horizontal:
|
||||
return _getIntrinsicMainAxis((RenderBox child) => child.getMaxIntrinsicHeight(width));
|
||||
case Axis.vertical:
|
||||
return _getIntrinsicCrossAxis((RenderBox child) => child.getMaxIntrinsicHeight(width));
|
||||
}
|
||||
assert(mainAxis != null);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
import 'dart:math' as math;
|
||||
import 'dart:ui' as ui show lerpDouble;
|
||||
|
||||
import 'package:flutter/animation.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:vector_math/vector_math_64.dart';
|
||||
@@ -1456,17 +1455,3 @@ abstract class RenderBoxContainerDefaultsMixin<ChildType extends RenderBox, Pare
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// An interpolation between two fractional offsets.
|
||||
///
|
||||
/// This class specializes the interpolation of Tween<FractionalOffset> to be
|
||||
/// appropriate for rectangles.
|
||||
class FractionalOffsetTween extends Tween<FractionalOffset> {
|
||||
/// Creates a fractional offset tween.
|
||||
///
|
||||
/// The [begin] and [end] arguments must not be null.
|
||||
FractionalOffsetTween({ FractionalOffset begin, FractionalOffset end }) : super(begin: begin, end: end);
|
||||
|
||||
@override
|
||||
FractionalOffset lerp(double t) => FractionalOffset.lerp(begin, end, t);
|
||||
}
|
||||
|
||||
21
packages/flutter/lib/src/rendering/tweens.dart
Normal file
21
packages/flutter/lib/src/rendering/tweens.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
// 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/animation.dart';
|
||||
import 'package:flutter/painting.dart';
|
||||
|
||||
/// An interpolation between two fractional offsets.
|
||||
///
|
||||
/// This class specializes the interpolation of Tween<FractionalOffset> to be
|
||||
/// appropriate for rectangles.
|
||||
class FractionalOffsetTween extends Tween<FractionalOffset> {
|
||||
/// Creates a fractional offset tween.
|
||||
///
|
||||
/// The [begin] and [end] arguments must not be null.
|
||||
FractionalOffsetTween({ FractionalOffset begin, FractionalOffset end })
|
||||
: super(begin: begin, end: end);
|
||||
|
||||
@override
|
||||
FractionalOffset lerp(double t) => FractionalOffset.lerp(begin, end, t);
|
||||
}
|
||||
106
packages/flutter/test/rendering/box_constraints_test.dart
Normal file
106
packages/flutter/test/rendering/box_constraints_test.dart
Normal file
@@ -0,0 +1,106 @@
|
||||
// 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';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
test('BoxConstraints toString', () {
|
||||
expect(const BoxConstraints.expand().toString(), contains('biggest'));
|
||||
expect(new BoxConstraints().toString(), contains('unconstrained'));
|
||||
expect(new BoxConstraints.tightFor(width: 50.0).toString(), contains('w=50'));
|
||||
});
|
||||
|
||||
test('BoxConstraints copyWith', () {
|
||||
BoxConstraints constraints = new BoxConstraints(
|
||||
minWidth: 3.0,
|
||||
maxWidth: 7.0,
|
||||
minHeight: 11.0,
|
||||
maxHeight: 17.0
|
||||
);
|
||||
BoxConstraints copy = constraints.copyWith();
|
||||
expect(copy, equals(constraints));
|
||||
copy = constraints.copyWith(
|
||||
minWidth: 13.0,
|
||||
maxWidth: 17.0,
|
||||
minHeight: 111.0,
|
||||
maxHeight: 117.0
|
||||
);
|
||||
expect(copy.minWidth, 13.0);
|
||||
expect(copy.maxWidth, 17.0);
|
||||
expect(copy.minHeight, 111.0);
|
||||
expect(copy.maxHeight, 117.0);
|
||||
expect(copy, isNot(equals(constraints)));
|
||||
expect(copy.hashCode, isNot(equals(constraints.hashCode)));
|
||||
});
|
||||
|
||||
test('BoxConstraints operators', () {
|
||||
BoxConstraints constraints = new BoxConstraints(
|
||||
minWidth: 3.0,
|
||||
maxWidth: 7.0,
|
||||
minHeight: 11.0,
|
||||
maxHeight: 17.0
|
||||
);
|
||||
BoxConstraints copy = constraints * 2.0;
|
||||
expect(copy.minWidth, 6.0);
|
||||
expect(copy.maxWidth, 14.0);
|
||||
expect(copy.minHeight, 22.0);
|
||||
expect(copy.maxHeight, 34.0);
|
||||
expect(copy / 2.0, equals(constraints));
|
||||
copy = constraints ~/ 2.0;
|
||||
expect(copy.minWidth, 1.0);
|
||||
expect(copy.maxWidth, 3.0);
|
||||
expect(copy.minHeight, 5.0);
|
||||
expect(copy.maxHeight, 8.0);
|
||||
copy = constraints % 3.0;
|
||||
expect(copy.minWidth, 0.0);
|
||||
expect(copy.maxWidth, 1.0);
|
||||
expect(copy.minHeight, 2.0);
|
||||
expect(copy.maxHeight, 2.0);
|
||||
});
|
||||
|
||||
test('BoxConstraints lerp', () {
|
||||
expect(BoxConstraints.lerp(null, null, 0.5), isNull);
|
||||
BoxConstraints constraints = new BoxConstraints(
|
||||
minWidth: 3.0,
|
||||
maxWidth: 7.0,
|
||||
minHeight: 11.0,
|
||||
maxHeight: 17.0
|
||||
);
|
||||
BoxConstraints copy = BoxConstraints.lerp(null, constraints, 0.5);
|
||||
expect(copy.minWidth, 1.5);
|
||||
expect(copy.maxWidth, 3.5);
|
||||
expect(copy.minHeight, 5.5);
|
||||
expect(copy.maxHeight, 8.5);
|
||||
copy = BoxConstraints.lerp(constraints, null, 0.5);
|
||||
expect(copy.minWidth, 1.5);
|
||||
expect(copy.maxWidth, 3.5);
|
||||
expect(copy.minHeight, 5.5);
|
||||
expect(copy.maxHeight, 8.5);
|
||||
copy = BoxConstraints.lerp(new BoxConstraints(
|
||||
minWidth: 13.0,
|
||||
maxWidth: 17.0,
|
||||
minHeight: 111.0,
|
||||
maxHeight: 117.0
|
||||
), constraints, 0.2);
|
||||
expect(copy.minWidth, 11.0);
|
||||
expect(copy.maxWidth, 15.0);
|
||||
expect(copy.minHeight, 91.0);
|
||||
expect(copy.maxHeight, 97.0);
|
||||
});
|
||||
|
||||
test('BoxConstraints normalize', () {
|
||||
BoxConstraints constraints = new BoxConstraints(
|
||||
minWidth: 3.0,
|
||||
maxWidth: 2.0,
|
||||
minHeight: 11.0,
|
||||
maxHeight: 18.0
|
||||
);
|
||||
BoxConstraints copy = constraints.normalize();
|
||||
expect(copy.minWidth, 3.0);
|
||||
expect(copy.maxWidth, 3.0);
|
||||
expect(copy.minHeight, 11.0);
|
||||
expect(copy.maxHeight, 18.0);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user