From e9f54512c8f6c212af6861bdf4eac45129f125b3 Mon Sep 17 00:00:00 2001 From: Amir Panahandeh Date: Wed, 16 Aug 2023 03:38:42 +0330 Subject: [PATCH] Add more tests for CompositionAwareMixin (flutter/engine#44717) Adds missing tests for `CompositionAwareMixin`. Check https://github.com/flutter/engine/pull/44139#discussion_r1288733128 and https://github.com/flutter/engine/pull/44139#discussion_r1288009016 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../web_ui/test/engine/composition_test.dart | 89 +++++++++++++++++-- 1 file changed, 80 insertions(+), 9 deletions(-) diff --git a/engine/src/flutter/lib/web_ui/test/engine/composition_test.dart b/engine/src/flutter/lib/web_ui/test/engine/composition_test.dart index 31e97266dd..dcfc100865 100644 --- a/engine/src/flutter/lib/web_ui/test/engine/composition_test.dart +++ b/engine/src/flutter/lib/web_ui/test/engine/composition_test.dart @@ -106,14 +106,81 @@ Future testMain() async { }); group('determine composition state', () { - test('should return new composition state - compositing middle of text', () { - const int baseOffset = 100; + test('should return editing state if extentOffset is null', () { + final EditingState editingState = EditingState(text: 'Test'); + + final _MockWithCompositionAwareMixin mockWithCompositionAwareMixin = + _MockWithCompositionAwareMixin(); + mockWithCompositionAwareMixin.composingText = 'Test'; + + expect( + mockWithCompositionAwareMixin.determineCompositionState(editingState), + editingState, + ); + }); + + test('should return editing state if composingText is null', () { + final EditingState editingState = EditingState( + text: 'Test', + baseOffset: 0, + extentOffset: 4, + ); + + final _MockWithCompositionAwareMixin mockWithCompositionAwareMixin = + _MockWithCompositionAwareMixin(); + + expect( + mockWithCompositionAwareMixin.determineCompositionState(editingState), + editingState, + ); + }); + + test('should return editing state if text is null', () { + final EditingState editingState = EditingState( + baseOffset: 0, + extentOffset: 0, + ); + + final _MockWithCompositionAwareMixin mockWithCompositionAwareMixin = + _MockWithCompositionAwareMixin(); + mockWithCompositionAwareMixin.composingText = 'Test'; + + expect( + mockWithCompositionAwareMixin.determineCompositionState(editingState), + editingState, + ); + }); + + test( + 'should return editing state if extentOffset is smaller than composingText length', + () { const String composingText = 'composeMe'; final EditingState editingState = EditingState( - extentOffset: baseOffset, - text: 'testing', + text: 'Test', + baseOffset: 0, + extentOffset: 4, + ); + + final _MockWithCompositionAwareMixin mockWithCompositionAwareMixin = + _MockWithCompositionAwareMixin(); + mockWithCompositionAwareMixin.composingText = composingText; + + expect( + mockWithCompositionAwareMixin.determineCompositionState(editingState), + editingState, + ); + }); + + test('should return new composition state - compositing middle of text', + () { + const int baseOffset = 7; + const String composingText = 'Test'; + + final EditingState editingState = EditingState( + text: 'Testing', baseOffset: baseOffset, + extentOffset: baseOffset, ); final _MockWithCompositionAwareMixin mockWithCompositionAwareMixin = @@ -123,13 +190,17 @@ Future testMain() async { const int expectedComposingBase = baseOffset - composingText.length; expect( - mockWithCompositionAwareMixin.determineCompositionState(editingState), - editingState.copyWith( - composingBaseOffset: expectedComposingBase, - composingExtentOffset: expectedComposingBase + composingText.length)); + mockWithCompositionAwareMixin.determineCompositionState(editingState), + editingState.copyWith( + composingBaseOffset: expectedComposingBase, + composingExtentOffset: expectedComposingBase + composingText.length, + ), + ); }); - test('should return new composition state - compositing from beginning of text', () { + test( + 'should return new composition state - compositing from beginning of text', + () { const String composingText = '今日は'; final EditingState editingState = EditingState(