mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
WIP Commits separated as follows: - Update lints in analysis_options files - Run `dart fix --apply` - Clean up leftover analysis issues - Run `dart format .` in the right places. Local analysis and testing passes. Checking CI now. Part of https://github.com/flutter/flutter/issues/178827 - Adoption of flutter_lints in examples/api coming in a separate change (cc @loic-sharma) ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
460 lines
16 KiB
Dart
460 lines
16 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/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
late TextStyle composingStyle;
|
|
late TextStyle misspelledTextStyle;
|
|
|
|
void main() {
|
|
setUp(() {
|
|
composingStyle = const TextStyle(decoration: TextDecoration.underline);
|
|
|
|
// Using Android handling for testing.
|
|
misspelledTextStyle = TextField.materialMisspelledTextStyle;
|
|
});
|
|
|
|
testWidgets(
|
|
'buildTextSpanWithSpellCheckSuggestions ignores composing region when composing region out of range',
|
|
(WidgetTester tester) async {
|
|
const text = 'Hello, wrold! Hey';
|
|
const value = TextEditingValue(text: text);
|
|
const composingRegionOutOfRange = true;
|
|
const spellCheckResults = SpellCheckResults(text, <SuggestionSpan>[
|
|
SuggestionSpan(TextRange(start: 7, end: 12), <String>['world', 'word', 'old']),
|
|
]);
|
|
|
|
final expectedTextSpanTree = TextSpan(
|
|
children: <TextSpan>[
|
|
const TextSpan(text: 'Hello, '),
|
|
TextSpan(style: misspelledTextStyle, text: 'wrold'),
|
|
const TextSpan(text: '! Hey'),
|
|
],
|
|
);
|
|
final TextSpan textSpanTree = buildTextSpanWithSpellCheckSuggestions(
|
|
value,
|
|
composingRegionOutOfRange,
|
|
null,
|
|
misspelledTextStyle,
|
|
spellCheckResults,
|
|
);
|
|
|
|
expect(textSpanTree, equals(expectedTextSpanTree));
|
|
},
|
|
variant: const TargetPlatformVariant(<TargetPlatform>{
|
|
TargetPlatform.android,
|
|
TargetPlatform.iOS,
|
|
}),
|
|
);
|
|
|
|
testWidgets(
|
|
'buildTextSpanWithSpellCheckSuggestions, isolated misspelled word with separate composing region example',
|
|
(WidgetTester tester) async {
|
|
const text = 'Hello, wrold! Hey';
|
|
const value = TextEditingValue(text: text, composing: TextRange(start: 14, end: 17));
|
|
const composingRegionOutOfRange = false;
|
|
const spellCheckResults = SpellCheckResults(text, <SuggestionSpan>[
|
|
SuggestionSpan(TextRange(start: 7, end: 12), <String>['world', 'word', 'old']),
|
|
]);
|
|
|
|
final expectedTextSpanTree = TextSpan(
|
|
children: <TextSpan>[
|
|
const TextSpan(text: 'Hello, '),
|
|
TextSpan(style: misspelledTextStyle, text: 'wrold'),
|
|
const TextSpan(text: '! '),
|
|
TextSpan(style: composingStyle, text: 'Hey'),
|
|
],
|
|
);
|
|
final TextSpan textSpanTree = buildTextSpanWithSpellCheckSuggestions(
|
|
value,
|
|
composingRegionOutOfRange,
|
|
null,
|
|
misspelledTextStyle,
|
|
spellCheckResults,
|
|
);
|
|
|
|
expect(textSpanTree, equals(expectedTextSpanTree));
|
|
},
|
|
variant: const TargetPlatformVariant(<TargetPlatform>{TargetPlatform.android}),
|
|
);
|
|
|
|
testWidgets(
|
|
'buildTextSpanWithSpellCheckSuggestions, composing region and misspelled words overlap example',
|
|
(WidgetTester tester) async {
|
|
const text = 'Right worng worng right';
|
|
const value = TextEditingValue(text: text, composing: TextRange(start: 12, end: 17));
|
|
const composingRegionOutOfRange = false;
|
|
const spellCheckResults = SpellCheckResults(text, <SuggestionSpan>[
|
|
SuggestionSpan(TextRange(start: 6, end: 11), <String>['wrong', 'worn', 'wrung']),
|
|
SuggestionSpan(TextRange(start: 12, end: 17), <String>['wrong', 'worn', 'wrung']),
|
|
]);
|
|
|
|
final expectedTextSpanTree = TextSpan(
|
|
children: <TextSpan>[
|
|
const TextSpan(text: 'Right '),
|
|
TextSpan(style: misspelledTextStyle, text: 'worng'),
|
|
const TextSpan(text: ' '),
|
|
TextSpan(style: composingStyle, text: 'worng'),
|
|
const TextSpan(text: ' right'),
|
|
],
|
|
);
|
|
final TextSpan textSpanTree = buildTextSpanWithSpellCheckSuggestions(
|
|
value,
|
|
composingRegionOutOfRange,
|
|
null,
|
|
misspelledTextStyle,
|
|
spellCheckResults,
|
|
);
|
|
|
|
expect(textSpanTree, equals(expectedTextSpanTree));
|
|
},
|
|
variant: const TargetPlatformVariant(<TargetPlatform>{TargetPlatform.android}),
|
|
);
|
|
|
|
testWidgets(
|
|
'buildTextSpanWithSpellCheckSuggestions, consecutive misspelled words example',
|
|
(WidgetTester tester) async {
|
|
const text = 'Right worng worng right';
|
|
const value = TextEditingValue(text: text);
|
|
const composingRegionOutOfRange = true;
|
|
const spellCheckResults = SpellCheckResults(text, <SuggestionSpan>[
|
|
SuggestionSpan(TextRange(start: 6, end: 11), <String>['wrong', 'worn', 'wrung']),
|
|
SuggestionSpan(TextRange(start: 12, end: 17), <String>['wrong', 'worn', 'wrung']),
|
|
]);
|
|
|
|
final expectedTextSpanTree = TextSpan(
|
|
children: <TextSpan>[
|
|
const TextSpan(text: 'Right '),
|
|
TextSpan(style: misspelledTextStyle, text: 'worng'),
|
|
const TextSpan(text: ' '),
|
|
TextSpan(style: misspelledTextStyle, text: 'worng'),
|
|
const TextSpan(text: ' right'),
|
|
],
|
|
);
|
|
final TextSpan textSpanTree = buildTextSpanWithSpellCheckSuggestions(
|
|
value,
|
|
composingRegionOutOfRange,
|
|
null,
|
|
misspelledTextStyle,
|
|
spellCheckResults,
|
|
);
|
|
|
|
expect(textSpanTree, equals(expectedTextSpanTree));
|
|
},
|
|
variant: const TargetPlatformVariant(<TargetPlatform>{
|
|
TargetPlatform.android,
|
|
TargetPlatform.iOS,
|
|
}),
|
|
);
|
|
|
|
testWidgets(
|
|
'buildTextSpanWithSpellCheckSuggestions corrects results when they lag, results text shorter than actual text example',
|
|
(WidgetTester tester) async {
|
|
const text = 'Hello, wrold! Hey';
|
|
const resultsText = 'Hello, wrold!';
|
|
const value = TextEditingValue(text: text);
|
|
const composingRegionOutOfRange = false;
|
|
const spellCheckResults = SpellCheckResults(resultsText, <SuggestionSpan>[
|
|
SuggestionSpan(TextRange(start: 7, end: 12), <String>['world', 'word', 'old']),
|
|
]);
|
|
|
|
final expectedTextSpanTree = TextSpan(
|
|
children: <TextSpan>[
|
|
const TextSpan(text: 'Hello, '),
|
|
TextSpan(style: misspelledTextStyle, text: 'wrold'),
|
|
const TextSpan(text: '! Hey'),
|
|
],
|
|
);
|
|
final TextSpan textSpanTree = buildTextSpanWithSpellCheckSuggestions(
|
|
value,
|
|
composingRegionOutOfRange,
|
|
null,
|
|
misspelledTextStyle,
|
|
spellCheckResults,
|
|
);
|
|
|
|
expect(textSpanTree, equals(expectedTextSpanTree));
|
|
},
|
|
variant: const TargetPlatformVariant(<TargetPlatform>{
|
|
TargetPlatform.android,
|
|
TargetPlatform.iOS,
|
|
}),
|
|
);
|
|
|
|
testWidgets(
|
|
'buildTextSpanWithSpellCheckSuggestions corrects results when they lag, results text longer with more misspelled words than actual text example',
|
|
(WidgetTester tester) async {
|
|
const text = 'Hello, wrold! Hey';
|
|
const resultsText = 'Hello, wrold Hey feirnd!';
|
|
const value = TextEditingValue(text: text);
|
|
const composingRegionOutOfRange = false;
|
|
const spellCheckResults = SpellCheckResults(resultsText, <SuggestionSpan>[
|
|
SuggestionSpan(TextRange(start: 7, end: 12), <String>['world', 'word', 'old']),
|
|
SuggestionSpan(TextRange(start: 17, end: 23), <String>['friend', 'fiend', 'fern']),
|
|
]);
|
|
|
|
final expectedTextSpanTree = TextSpan(
|
|
children: <TextSpan>[
|
|
const TextSpan(text: 'Hello, '),
|
|
TextSpan(style: misspelledTextStyle, text: 'wrold'),
|
|
const TextSpan(text: '! Hey'),
|
|
],
|
|
);
|
|
final TextSpan textSpanTree = buildTextSpanWithSpellCheckSuggestions(
|
|
value,
|
|
composingRegionOutOfRange,
|
|
null,
|
|
misspelledTextStyle,
|
|
spellCheckResults,
|
|
);
|
|
|
|
expect(textSpanTree, equals(expectedTextSpanTree));
|
|
},
|
|
variant: const TargetPlatformVariant(<TargetPlatform>{
|
|
TargetPlatform.android,
|
|
TargetPlatform.iOS,
|
|
}),
|
|
);
|
|
|
|
testWidgets(
|
|
'buildTextSpanWithSpellCheckSuggestions corrects results when they lag, results text mismatched example',
|
|
(WidgetTester tester) async {
|
|
const text = 'Hello, wrold! Hey';
|
|
const resultsText = 'Hello, wrild! Hey';
|
|
const value = TextEditingValue(text: text);
|
|
const composingRegionOutOfRange = false;
|
|
const spellCheckResults = SpellCheckResults(resultsText, <SuggestionSpan>[
|
|
SuggestionSpan(TextRange(start: 7, end: 12), <String>['wild', 'world']),
|
|
]);
|
|
|
|
const expectedTextSpanTree = TextSpan(
|
|
children: <TextSpan>[TextSpan(text: 'Hello, wrold! Hey')],
|
|
);
|
|
final TextSpan textSpanTree = buildTextSpanWithSpellCheckSuggestions(
|
|
value,
|
|
composingRegionOutOfRange,
|
|
null,
|
|
misspelledTextStyle,
|
|
spellCheckResults,
|
|
);
|
|
|
|
expect(textSpanTree, equals(expectedTextSpanTree));
|
|
},
|
|
variant: const TargetPlatformVariant(<TargetPlatform>{
|
|
TargetPlatform.android,
|
|
TargetPlatform.iOS,
|
|
}),
|
|
);
|
|
|
|
testWidgets(
|
|
'buildTextSpanWithSpellCheckSuggestions corrects results when they lag, results shifted forward example',
|
|
(WidgetTester tester) async {
|
|
const text = 'Hello, there wrold! Hey';
|
|
const resultsText = 'Hello, wrold! Hey';
|
|
const value = TextEditingValue(text: text);
|
|
const composingRegionOutOfRange = false;
|
|
const spellCheckResults = SpellCheckResults(resultsText, <SuggestionSpan>[
|
|
SuggestionSpan(TextRange(start: 7, end: 12), <String>['world', 'word', 'old']),
|
|
]);
|
|
|
|
final expectedTextSpanTree = TextSpan(
|
|
children: <TextSpan>[
|
|
const TextSpan(text: 'Hello, there '),
|
|
TextSpan(style: misspelledTextStyle, text: 'wrold'),
|
|
const TextSpan(text: '! Hey'),
|
|
],
|
|
);
|
|
final TextSpan textSpanTree = buildTextSpanWithSpellCheckSuggestions(
|
|
value,
|
|
composingRegionOutOfRange,
|
|
null,
|
|
misspelledTextStyle,
|
|
spellCheckResults,
|
|
);
|
|
|
|
expect(textSpanTree, equals(expectedTextSpanTree));
|
|
},
|
|
variant: const TargetPlatformVariant(<TargetPlatform>{
|
|
TargetPlatform.android,
|
|
TargetPlatform.iOS,
|
|
}),
|
|
);
|
|
|
|
testWidgets(
|
|
'buildTextSpanWithSpellCheckSuggestions corrects results when they lag, results shifted backwards example',
|
|
(WidgetTester tester) async {
|
|
const text = 'Hello, wrold! Hey';
|
|
const resultsText = 'Hello, great wrold! Hey';
|
|
const value = TextEditingValue(text: text);
|
|
const composingRegionOutOfRange = false;
|
|
const spellCheckResults = SpellCheckResults(resultsText, <SuggestionSpan>[
|
|
SuggestionSpan(TextRange(start: 13, end: 18), <String>['world', 'word', 'old']),
|
|
]);
|
|
|
|
final expectedTextSpanTree = TextSpan(
|
|
children: <TextSpan>[
|
|
const TextSpan(text: 'Hello, '),
|
|
TextSpan(style: misspelledTextStyle, text: 'wrold'),
|
|
const TextSpan(text: '! Hey'),
|
|
],
|
|
);
|
|
final TextSpan textSpanTree = buildTextSpanWithSpellCheckSuggestions(
|
|
value,
|
|
composingRegionOutOfRange,
|
|
null,
|
|
misspelledTextStyle,
|
|
spellCheckResults,
|
|
);
|
|
|
|
expect(textSpanTree, equals(expectedTextSpanTree));
|
|
},
|
|
variant: const TargetPlatformVariant(<TargetPlatform>{
|
|
TargetPlatform.android,
|
|
TargetPlatform.iOS,
|
|
}),
|
|
);
|
|
|
|
testWidgets(
|
|
'buildTextSpanWithSpellCheckSuggestions corrects results when they lag, results shifted backwards and forwards example',
|
|
(WidgetTester tester) async {
|
|
const text = 'Hello, wrold! And Hye!';
|
|
const resultsText = 'Hello, great wrold! Hye!';
|
|
const value = TextEditingValue(text: text);
|
|
const composingRegionOutOfRange = false;
|
|
const spellCheckResults = SpellCheckResults(resultsText, <SuggestionSpan>[
|
|
SuggestionSpan(TextRange(start: 13, end: 18), <String>['world', 'word', 'old']),
|
|
SuggestionSpan(TextRange(start: 20, end: 23), <String>['Hey', 'He']),
|
|
]);
|
|
|
|
final expectedTextSpanTree = TextSpan(
|
|
children: <TextSpan>[
|
|
const TextSpan(text: 'Hello, '),
|
|
TextSpan(style: misspelledTextStyle, text: 'wrold'),
|
|
const TextSpan(text: '! And '),
|
|
TextSpan(style: misspelledTextStyle, text: 'Hye'),
|
|
const TextSpan(text: '!'),
|
|
],
|
|
);
|
|
final TextSpan textSpanTree = buildTextSpanWithSpellCheckSuggestions(
|
|
value,
|
|
composingRegionOutOfRange,
|
|
null,
|
|
misspelledTextStyle,
|
|
spellCheckResults,
|
|
);
|
|
|
|
expect(textSpanTree, equals(expectedTextSpanTree));
|
|
},
|
|
variant: const TargetPlatformVariant(<TargetPlatform>{
|
|
TargetPlatform.android,
|
|
TargetPlatform.iOS,
|
|
}),
|
|
);
|
|
|
|
testWidgets(
|
|
'buildTextSpanWithSpellCheckSuggestions discards result when additions are made to misspelled word example',
|
|
(WidgetTester tester) async {
|
|
const text = 'Hello, wroldd!';
|
|
const resultsText = 'Hello, wrold!';
|
|
const value = TextEditingValue(text: text);
|
|
const composingRegionOutOfRange = false;
|
|
const spellCheckResults = SpellCheckResults(resultsText, <SuggestionSpan>[
|
|
SuggestionSpan(TextRange(start: 7, end: 12), <String>['world', 'word', 'old']),
|
|
]);
|
|
|
|
const expectedTextSpanTree = TextSpan(children: <TextSpan>[TextSpan(text: 'Hello, wroldd!')]);
|
|
final TextSpan textSpanTree = buildTextSpanWithSpellCheckSuggestions(
|
|
value,
|
|
composingRegionOutOfRange,
|
|
null,
|
|
misspelledTextStyle,
|
|
spellCheckResults,
|
|
);
|
|
|
|
expect(textSpanTree, equals(expectedTextSpanTree));
|
|
},
|
|
variant: const TargetPlatformVariant(<TargetPlatform>{
|
|
TargetPlatform.android,
|
|
TargetPlatform.iOS,
|
|
}),
|
|
);
|
|
|
|
testWidgets(
|
|
'buildTextSpanWithSpellCheckSuggestions does not throw when text contains regex reserved characters',
|
|
(WidgetTester tester) async {
|
|
// Regression test for https://github.com/flutter/flutter/issues/136032.
|
|
const text = 'Hello, *ãresaa';
|
|
const resultsText = 'Hello, *ãresa';
|
|
const value = TextEditingValue(text: text);
|
|
const composingRegionOutOfRange = false;
|
|
const spellCheckResults = SpellCheckResults(resultsText, <SuggestionSpan>[
|
|
SuggestionSpan(TextRange(start: 7, end: 12), <String>['*rangesa']),
|
|
]);
|
|
|
|
const expectedTextSpanTree = TextSpan(children: <TextSpan>[TextSpan(text: 'Hello, *ãresaa')]);
|
|
final TextSpan textSpanTree = buildTextSpanWithSpellCheckSuggestions(
|
|
value,
|
|
composingRegionOutOfRange,
|
|
null,
|
|
misspelledTextStyle,
|
|
spellCheckResults,
|
|
);
|
|
|
|
expect(tester.takeException(), null);
|
|
expect(textSpanTree, equals(expectedTextSpanTree));
|
|
},
|
|
variant: const TargetPlatformVariant(<TargetPlatform>{
|
|
TargetPlatform.android,
|
|
TargetPlatform.iOS,
|
|
}),
|
|
);
|
|
|
|
testWidgets(
|
|
'buildTextSpanWithSpellCheckSuggestions does not throw when text is being deleted',
|
|
(WidgetTester tester) async {
|
|
// Regression test for https://github.com/flutter/flutter/issues/152272.
|
|
const text = 'Lorem ipsum dolor ';
|
|
const resultsText = 'Lorem ipsum dolor sit ';
|
|
const value = TextEditingValue(
|
|
text: text,
|
|
selection: TextSelection.collapsed(offset: text.length),
|
|
);
|
|
const composingRegionOutOfRange = false;
|
|
const spellCheckResults = SpellCheckResults(resultsText, <SuggestionSpan>[
|
|
SuggestionSpan(TextRange(start: 0, end: 5), <String>['suggestion1', 'suggestion2']),
|
|
SuggestionSpan(TextRange(start: 6, end: 11), <String>['suggestion1', 'suggestion2']),
|
|
SuggestionSpan(TextRange(start: 12, end: 17), <String>['suggestion1', 'suggestion2']),
|
|
SuggestionSpan(TextRange(start: 18, end: 21), <String>['suggestion1', 'suggestion2']),
|
|
]);
|
|
|
|
final expectedTextSpanTree = TextSpan(
|
|
children: <TextSpan>[
|
|
TextSpan(text: 'Lorem', style: misspelledTextStyle),
|
|
const TextSpan(text: ' '),
|
|
TextSpan(text: 'ipsum', style: misspelledTextStyle),
|
|
const TextSpan(text: ' '),
|
|
TextSpan(text: 'dolor', style: misspelledTextStyle),
|
|
const TextSpan(text: ' '),
|
|
],
|
|
);
|
|
final TextSpan textSpanTree = buildTextSpanWithSpellCheckSuggestions(
|
|
value,
|
|
composingRegionOutOfRange,
|
|
null,
|
|
misspelledTextStyle,
|
|
spellCheckResults,
|
|
);
|
|
|
|
expect(tester.takeException(), null);
|
|
expect(textSpanTree, equals(expectedTextSpanTree));
|
|
},
|
|
variant: const TargetPlatformVariant(<TargetPlatform>{
|
|
TargetPlatform.android,
|
|
TargetPlatform.iOS,
|
|
}),
|
|
);
|
|
}
|