From 25ebf1c4d4e9b0de7f47a3500c86947a1330b109 Mon Sep 17 00:00:00 2001 From: Amir Panahandeh Date: Tue, 15 Aug 2023 11:43:07 +0330 Subject: [PATCH 1/2] Add more tests for CompositionAwareMixin --- lib/web_ui/test/engine/composition_test.dart | 85 ++++++++++++++++++-- 1 file changed, 78 insertions(+), 7 deletions(-) diff --git a/lib/web_ui/test/engine/composition_test.dart b/lib/web_ui/test/engine/composition_test.dart index 31e97266dd4ef..b41c70bccefe0 100644 --- a/lib/web_ui/test/engine/composition_test.dart +++ b/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), + mockWithCompositionAwareMixin + .determineCompositionState(editingState), editingState.copyWith( composingBaseOffset: expectedComposingBase, - composingExtentOffset: expectedComposingBase + composingText.length)); + 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( From c66c2ac298d2c0c0537f9b5f926d43454bc93648 Mon Sep 17 00:00:00 2001 From: Amir Panahandeh Date: Tue, 15 Aug 2023 22:29:08 +0330 Subject: [PATCH 2/2] Format --- lib/web_ui/test/engine/composition_test.dart | 36 ++++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/web_ui/test/engine/composition_test.dart b/lib/web_ui/test/engine/composition_test.dart index b41c70bccefe0..dcfc100865324 100644 --- a/lib/web_ui/test/engine/composition_test.dart +++ b/lib/web_ui/test/engine/composition_test.dart @@ -114,9 +114,9 @@ Future testMain() async { mockWithCompositionAwareMixin.composingText = 'Test'; expect( - mockWithCompositionAwareMixin - .determineCompositionState(editingState), - editingState); + mockWithCompositionAwareMixin.determineCompositionState(editingState), + editingState, + ); }); test('should return editing state if composingText is null', () { @@ -130,9 +130,9 @@ Future testMain() async { _MockWithCompositionAwareMixin(); expect( - mockWithCompositionAwareMixin - .determineCompositionState(editingState), - editingState); + mockWithCompositionAwareMixin.determineCompositionState(editingState), + editingState, + ); }); test('should return editing state if text is null', () { @@ -146,9 +146,9 @@ Future testMain() async { mockWithCompositionAwareMixin.composingText = 'Test'; expect( - mockWithCompositionAwareMixin - .determineCompositionState(editingState), - editingState); + mockWithCompositionAwareMixin.determineCompositionState(editingState), + editingState, + ); }); test( @@ -167,9 +167,9 @@ Future testMain() async { mockWithCompositionAwareMixin.composingText = composingText; expect( - mockWithCompositionAwareMixin - .determineCompositionState(editingState), - editingState); + mockWithCompositionAwareMixin.determineCompositionState(editingState), + editingState, + ); }); test('should return new composition state - compositing middle of text', @@ -190,12 +190,12 @@ 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(