Michael Goderbauer 5491c8c146
Auto-format Framework (#160545)
This auto-formats all *.dart files in the repository outside of the
`engine` subdirectory and enforces that these files stay formatted with
a presubmit check.

**Reviewers:** Please carefully review all the commits except for the
one titled "formatted". The "formatted" commit was auto-generated by
running `dev/tools/format.sh -a -f`. The other commits were hand-crafted
to prepare the repo for the formatting change. I recommend reviewing the
commits one-by-one via the "Commits" tab and avoiding Github's "Files
changed" tab as it will likely slow down your browser because of the
size of this PR.

---------

Co-authored-by: Kate Lovett <katelovett@google.com>
Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
2024-12-19 20:06:21 +00:00

81 lines
3.7 KiB
Dart

// Copyright 2014 The Flutter 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:flutter_test/flutter_test.dart';
void main() {
const Rect rect = Rect.fromLTWH(100, 100, 200, 500);
const Offset outsideTopLeft = Offset(50, 50);
const Offset outsideLeft = Offset(50, 200);
const Offset outsideBottomLeft = Offset(50, 700);
const Offset outsideTop = Offset(200, 50);
const Offset outsideTopRight = Offset(350, 50);
const Offset outsideRight = Offset(350, 200);
const Offset outsideBottomRight = Offset(350, 700);
const Offset outsideBottom = Offset(200, 700);
const Offset center = Offset(150, 300);
group('selection utils', () {
test('selectionBasedOnRect works', () {
expect(SelectionUtils.getResultBasedOnRect(rect, outsideTopLeft), SelectionResult.previous);
expect(SelectionUtils.getResultBasedOnRect(rect, outsideLeft), SelectionResult.previous);
expect(SelectionUtils.getResultBasedOnRect(rect, outsideBottomLeft), SelectionResult.next);
expect(SelectionUtils.getResultBasedOnRect(rect, outsideTop), SelectionResult.previous);
expect(SelectionUtils.getResultBasedOnRect(rect, outsideTopRight), SelectionResult.previous);
expect(SelectionUtils.getResultBasedOnRect(rect, outsideRight), SelectionResult.next);
expect(SelectionUtils.getResultBasedOnRect(rect, outsideBottomRight), SelectionResult.next);
expect(SelectionUtils.getResultBasedOnRect(rect, outsideBottom), SelectionResult.next);
expect(SelectionUtils.getResultBasedOnRect(rect, center), SelectionResult.end);
});
test('adjustDragOffset works', () {
// ltr
expect(SelectionUtils.adjustDragOffset(rect, outsideTopLeft), rect.topLeft);
expect(SelectionUtils.adjustDragOffset(rect, outsideLeft), rect.topLeft);
expect(SelectionUtils.adjustDragOffset(rect, outsideBottomLeft), rect.bottomRight);
expect(SelectionUtils.adjustDragOffset(rect, outsideTop), rect.topLeft);
expect(SelectionUtils.adjustDragOffset(rect, outsideTopRight), rect.topLeft);
expect(SelectionUtils.adjustDragOffset(rect, outsideRight), rect.bottomRight);
expect(SelectionUtils.adjustDragOffset(rect, outsideBottomRight), rect.bottomRight);
expect(SelectionUtils.adjustDragOffset(rect, outsideBottom), rect.bottomRight);
expect(SelectionUtils.adjustDragOffset(rect, center), center);
// rtl
expect(
SelectionUtils.adjustDragOffset(rect, outsideTopLeft, direction: TextDirection.rtl),
rect.topRight,
);
expect(
SelectionUtils.adjustDragOffset(rect, outsideLeft, direction: TextDirection.rtl),
rect.topRight,
);
expect(
SelectionUtils.adjustDragOffset(rect, outsideBottomLeft, direction: TextDirection.rtl),
rect.bottomLeft,
);
expect(
SelectionUtils.adjustDragOffset(rect, outsideTop, direction: TextDirection.rtl),
rect.topRight,
);
expect(
SelectionUtils.adjustDragOffset(rect, outsideTopRight, direction: TextDirection.rtl),
rect.topRight,
);
expect(
SelectionUtils.adjustDragOffset(rect, outsideRight, direction: TextDirection.rtl),
rect.bottomLeft,
);
expect(
SelectionUtils.adjustDragOffset(rect, outsideBottomRight, direction: TextDirection.rtl),
rect.bottomLeft,
);
expect(
SelectionUtils.adjustDragOffset(rect, outsideBottom, direction: TextDirection.rtl),
rect.bottomLeft,
);
expect(SelectionUtils.adjustDragOffset(rect, center, direction: TextDirection.rtl), center);
});
});
}