Flutter Engine
The Flutter Engine
Instance Methods | Properties | List of all members
FlutterSpellCheckPluginTest Class Reference
Inheritance diagram for FlutterSpellCheckPluginTest:

Instance Methods

(void) - setUp [implementation]
 
(void) - tearDown [implementation]
 
(void) - testFindAllSpellCheckSuggestionsForText [implementation]
 
(void) - testStopFindingMoreWhenTheLastWordIsMisspelled [implementation]
 
(void) - testStopFindingMoreWhenTheWholeStringIsAMisspelledWord [implementation]
 
(void) - testInitiateSpellCheckWithNoMisspelledWord [implementation]
 
(void) - testUnsupportedLanguageShouldReturnNil [implementation]
 
(void) - testSupportSubLanguage [implementation]
 
(void) - testEmptyStringShouldReturnEmptyResults [implementation]
 
(void) - testNullStringArgumentShouldReturnNilResults [implementation]
 
(void) - testNullLanguageArgumentShouldReturnNilResults [implementation]
 
(void) - testUITextCheckerIsInitializedAfterMethodChannelCall [implementation]
 
(void) - mockUITextCheckerWithExpectedMisspelledWordRange:startingIndex:suggestions: [implementation]
 

Properties

id mockMethodChannel
 
FlutterSpellCheckPluginplugin
 
id mockTextChecker
 
id partialMockPlugin
 

Detailed Description

Definition at line 92 of file FlutterSpellCheckPluginTest.mm.

Method Documentation

◆ mockUITextCheckerWithExpectedMisspelledWordRange:startingIndex:suggestions:

- (void) mockUITextCheckerWithExpectedMisspelledWordRange: (NSRange)  expectedRange
startingIndex: (NSInteger)  startingIndex
suggestions: (NSArray*)  suggestions 
implementation

Definition at line 97 of file FlutterSpellCheckPluginTest.mm.

356 :(NSRange)expectedRange
357 startingIndex:(NSInteger)startingIndex
358 suggestions:(NSArray*)suggestions {
359 [self.mockTextChecker mockResultRange:expectedRange
360 suggestions:suggestions
361 withStartingIndex:startingIndex];
362}

◆ setUp

- (void) setUp
implementation

Definition at line 97 of file FlutterSpellCheckPluginTest.mm.

105 {
106 [super setUp];
107 self.mockMethodChannel = OCMClassMock([FlutterMethodChannel class]);
108 self.plugin = [[FlutterSpellCheckPlugin alloc] init];
109 __weak FlutterSpellCheckPlugin* weakPlugin = self.plugin;
110 OCMStub([self.mockMethodChannel invokeMethod:[OCMArg any]
111 arguments:[OCMArg any]
112 result:[OCMArg any]])
113 .andDo(^(NSInvocation* invocation) {
114 NSString* name;
115 id args;
117 [invocation getArgument:&name atIndex:2];
118 [invocation getArgument:&args atIndex:3];
119 [invocation getArgument:&result atIndex:4];
121 arguments:args];
122 [weakPlugin handleMethodCall:methodCall result:result];
123 });
124 self.mockTextChecker = [[MockTextChecker alloc] init];
125}
void(^ FlutterResult)(id _Nullable result)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
GAsyncResult * result
instancetype methodCallWithMethodName:arguments:(NSString *method,[arguments] id _Nullable arguments)
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
SIT bool any(const Vec< 1, T > &x)
Definition: SkVx.h:530

◆ tearDown

- (void) tearDown
implementation

Definition at line 97 of file FlutterSpellCheckPluginTest.mm.

127 {
128 self.plugin = nil;
129 [super tearDown];
130}

◆ testEmptyStringShouldReturnEmptyResults

- (void) testEmptyStringShouldReturnEmptyResults
implementation

Definition at line 97 of file FlutterSpellCheckPluginTest.mm.

296 {
297 self.partialMockPlugin = OCMPartialMock(self.plugin);
298 OCMStub([self.partialMockPlugin textChecker]).andReturn(self.mockTextChecker);
299 // Use real UITextChecker for this as we want to rely on the actual behavior of UITextChecker
300 // to ensure that spell checks on an empty result always return empty.
301 [self.partialMockPlugin stopMocking];
302
303 id textCheckerClassMock = OCMClassMock([UITextChecker class]);
304 [[[textCheckerClassMock stub] andReturn:@[ @"en" ]] availableLanguages];
305 __block id capturedResult;
306 [self.mockMethodChannel invokeMethod:@"SpellCheck.initiateSpellCheck"
307 arguments:@[ @"en", @"" ]
308 result:^(id _Nullable result) {
309 capturedResult = result;
310 }];
311 XCTAssertEqualObjects(capturedResult, @[]);
312 [textCheckerClassMock stopMocking];
313}

◆ testFindAllSpellCheckSuggestionsForText

- (void) testFindAllSpellCheckSuggestionsForText
implementation

Definition at line 97 of file FlutterSpellCheckPluginTest.mm.

136 {
137 self.partialMockPlugin = OCMPartialMock(self.plugin);
138 OCMStub([self.partialMockPlugin textChecker]).andReturn(self.mockTextChecker);
139 id textCheckerClassMock = OCMClassMock([UITextChecker class]);
140 [[[textCheckerClassMock stub] andReturn:@[ @"en" ]] availableLanguages];
141 NSArray* suggestions1 = @[ @"suggestion 1", @"suggestion 2" ];
142 NSArray* suggestions2 = @[ @"suggestion 3", @"suggestion 4" ];
143 // 0-4 is a misspelled word.
144 [self mockUITextCheckerWithExpectedMisspelledWordRange:NSMakeRange(0, 5)
145 startingIndex:0
146 suggestions:suggestions1];
147 // 5-9 is a misspelled word.
148 [self mockUITextCheckerWithExpectedMisspelledWordRange:NSMakeRange(5, 5)
149 startingIndex:5
150 suggestions:suggestions2];
151 // No misspelled word after index 10.
152 [self mockUITextCheckerWithExpectedMisspelledWordRange:NSMakeRange(NSNotFound, 0)
153 startingIndex:10
154 suggestions:@[]];
155 __block NSArray* capturedResult;
156 [self.mockMethodChannel invokeMethod:@"SpellCheck.initiateSpellCheck"
157 arguments:@[ @"en", @"ksajlkdf aslkdfl kasdf asdfjk" ]
158 result:^(id _Nullable result) {
159 capturedResult = result;
160 }];
161 XCTAssertTrue(capturedResult.count == 2);
162 NSDictionary* suggestionsJSON1 = capturedResult.firstObject;
163 XCTAssertEqualObjects(suggestionsJSON1[@"startIndex"], @0);
164 XCTAssertEqualObjects(suggestionsJSON1[@"endIndex"], @5);
165 XCTAssertEqualObjects(suggestionsJSON1[@"suggestions"], suggestions1);
166 NSDictionary* suggestionsJSON2 = capturedResult[1];
167 XCTAssertEqualObjects(suggestionsJSON2[@"startIndex"], @5);
168 XCTAssertEqualObjects(suggestionsJSON2[@"endIndex"], @10);
169 XCTAssertEqualObjects(suggestionsJSON2[@"suggestions"], suggestions2);
170 [self.mockTextChecker reset];
171 [textCheckerClassMock stopMocking];
172}

◆ testInitiateSpellCheckWithNoMisspelledWord

- (void) testInitiateSpellCheckWithNoMisspelledWord
implementation

Definition at line 97 of file FlutterSpellCheckPluginTest.mm.

237 {
238 self.partialMockPlugin = OCMPartialMock(self.plugin);
239 OCMStub([self.partialMockPlugin textChecker]).andReturn(self.mockTextChecker);
240 id textCheckerClassMock = OCMClassMock([UITextChecker class]);
241 [[[textCheckerClassMock stub] andReturn:@[ @"en" ]] availableLanguages];
242 [self mockUITextCheckerWithExpectedMisspelledWordRange:NSMakeRange(NSNotFound, 0)
243 startingIndex:0
244 suggestions:@[]];
245 __block id capturedResult;
246 [self.mockMethodChannel invokeMethod:@"SpellCheck.initiateSpellCheck"
247 arguments:@[ @"en", @"helloo" ]
248 result:^(id _Nullable result) {
249 capturedResult = result;
250 }];
251 XCTAssertEqualObjects(capturedResult, @[]);
252 [textCheckerClassMock stopMocking];
253}

◆ testNullLanguageArgumentShouldReturnNilResults

- (void) testNullLanguageArgumentShouldReturnNilResults
implementation

Definition at line 97 of file FlutterSpellCheckPluginTest.mm.

330 {
331 self.partialMockPlugin = OCMPartialMock(self.plugin);
332 OCMStub([self.partialMockPlugin textChecker]).andReturn(self.mockTextChecker);
333 id textCheckerClassMock = OCMClassMock([UITextChecker class]);
334 [[[textCheckerClassMock stub] andReturn:@[ @"en" ]] availableLanguages];
335 __block id capturedResult;
336 [self.mockMethodChannel invokeMethod:@"SpellCheck.initiateSpellCheck"
337 arguments:@[ [NSNull null], @"some string" ]
338 result:^(id _Nullable result) {
339 capturedResult = result;
340 }];
341 XCTAssertNil(capturedResult);
342 [textCheckerClassMock stopMocking];
343}

◆ testNullStringArgumentShouldReturnNilResults

- (void) testNullStringArgumentShouldReturnNilResults
implementation

Definition at line 97 of file FlutterSpellCheckPluginTest.mm.

315 {
316 self.partialMockPlugin = OCMPartialMock(self.plugin);
317 OCMStub([self.partialMockPlugin textChecker]).andReturn(self.mockTextChecker);
318 id textCheckerClassMock = OCMClassMock([UITextChecker class]);
319 [[[textCheckerClassMock stub] andReturn:@[ @"en" ]] availableLanguages];
320 __block id capturedResult;
321 [self.mockMethodChannel invokeMethod:@"SpellCheck.initiateSpellCheck"
322 arguments:@[ @"en", [NSNull null] ]
323 result:^(id _Nullable result) {
324 capturedResult = result;
325 }];
326 XCTAssertNil(capturedResult);
327 [textCheckerClassMock stopMocking];
328}

◆ testStopFindingMoreWhenTheLastWordIsMisspelled

- (void) testStopFindingMoreWhenTheLastWordIsMisspelled
implementation

Definition at line 97 of file FlutterSpellCheckPluginTest.mm.

176 {
177 self.partialMockPlugin = OCMPartialMock(self.plugin);
178 OCMStub([self.partialMockPlugin textChecker]).andReturn(self.mockTextChecker);
179 id textCheckerClassMock = OCMClassMock([UITextChecker class]);
180 [[[textCheckerClassMock stub] andReturn:@[ @"en" ]] availableLanguages];
181 NSArray* suggestions1 = @[ @"suggestion 1", @"suggestion 2" ];
182 NSArray* suggestions2 = @[ @"suggestion 3", @"suggestion 4" ];
183 // 0-4 is a misspelled word.
184 [self mockUITextCheckerWithExpectedMisspelledWordRange:NSMakeRange(0, 5)
185 startingIndex:0
186 suggestions:suggestions1];
187 // 5-9 is a misspelled word.
188 [self mockUITextCheckerWithExpectedMisspelledWordRange:NSMakeRange(6, 4)
189 startingIndex:5
190 suggestions:suggestions2];
191
192 __block NSArray* capturedResult;
193 [self.mockMethodChannel invokeMethod:@"SpellCheck.initiateSpellCheck"
194 arguments:@[ @"en", @"hejjo abcd" ]
195 result:^(id _Nullable result) {
196 capturedResult = result;
197 }];
198 XCTAssertTrue(capturedResult.count == 2);
199 NSDictionary* suggestionsJSON1 = capturedResult.firstObject;
200 XCTAssertEqualObjects(suggestionsJSON1[@"startIndex"], @0);
201 XCTAssertEqualObjects(suggestionsJSON1[@"endIndex"], @5);
202 XCTAssertEqualObjects(suggestionsJSON1[@"suggestions"], suggestions1);
203 NSDictionary* suggestionsJSON2 = capturedResult[1];
204 XCTAssertEqualObjects(suggestionsJSON2[@"startIndex"], @6);
205 XCTAssertEqualObjects(suggestionsJSON2[@"endIndex"], @10);
206 XCTAssertEqualObjects(suggestionsJSON2[@"suggestions"], suggestions2);
207 [self.mockTextChecker reset];
208 [textCheckerClassMock stopMocking];
209}

◆ testStopFindingMoreWhenTheWholeStringIsAMisspelledWord

- (void) testStopFindingMoreWhenTheWholeStringIsAMisspelledWord
implementation

Definition at line 97 of file FlutterSpellCheckPluginTest.mm.

211 {
212 self.partialMockPlugin = OCMPartialMock(self.plugin);
213 OCMStub([self.partialMockPlugin textChecker]).andReturn(self.mockTextChecker);
214 id textCheckerClassMock = OCMClassMock([UITextChecker class]);
215 [[[textCheckerClassMock stub] andReturn:@[ @"en" ]] availableLanguages];
216 NSArray* suggestions1 = @[ @"suggestion 1", @"suggestion 2" ];
217 // 0-4 is a misspelled word.
218 [self mockUITextCheckerWithExpectedMisspelledWordRange:NSMakeRange(0, 5)
219 startingIndex:0
220 suggestions:suggestions1];
221
222 __block NSArray* capturedResult;
223 [self.mockMethodChannel invokeMethod:@"SpellCheck.initiateSpellCheck"
224 arguments:@[ @"en", @"hejjo" ]
225 result:^(id _Nullable result) {
226 capturedResult = result;
227 }];
228 XCTAssertTrue(capturedResult.count == 1);
229 NSDictionary* suggestionsJSON1 = capturedResult.firstObject;
230 XCTAssertEqualObjects(suggestionsJSON1[@"startIndex"], @0);
231 XCTAssertEqualObjects(suggestionsJSON1[@"endIndex"], @5);
232 XCTAssertEqualObjects(suggestionsJSON1[@"suggestions"], suggestions1);
233 [self.mockTextChecker reset];
234 [textCheckerClassMock stopMocking];
235}

◆ testSupportSubLanguage

- (void) testSupportSubLanguage
implementation

Definition at line 97 of file FlutterSpellCheckPluginTest.mm.

273 {
274 self.partialMockPlugin = OCMPartialMock(self.plugin);
275 OCMStub([self.partialMockPlugin textChecker]).andReturn(self.mockTextChecker);
276 id textCheckerClassMock = OCMClassMock([UITextChecker class]);
277 [[[textCheckerClassMock stub] andReturn:@[ @"en_US" ]] availableLanguages];
278 NSArray* suggestions1 = @[ @"suggestion 1", @"suggestion 2" ];
279
280 [self mockUITextCheckerWithExpectedMisspelledWordRange:NSMakeRange(0, 5)
281 startingIndex:0
282 suggestions:suggestions1];
283 __block NSArray* capturedResult;
284 [self.mockMethodChannel invokeMethod:@"SpellCheck.initiateSpellCheck"
285 arguments:@[ @"en-us", @"hejjo" ]
286 result:^(id _Nullable result) {
287 capturedResult = result;
288 }];
289 NSDictionary* suggestionsJSON1 = capturedResult.firstObject;
290 XCTAssertEqualObjects(suggestionsJSON1[@"startIndex"], @0);
291 XCTAssertEqualObjects(suggestionsJSON1[@"endIndex"], @5);
292 XCTAssertEqualObjects(suggestionsJSON1[@"suggestions"], suggestions1);
293 [textCheckerClassMock stopMocking];
294}

◆ testUITextCheckerIsInitializedAfterMethodChannelCall

- (void) testUITextCheckerIsInitializedAfterMethodChannelCall
implementation

Definition at line 97 of file FlutterSpellCheckPluginTest.mm.

345 {
346 XCTAssertNil([self.plugin textChecker]);
347 __block id capturedResult;
348 [self.mockMethodChannel invokeMethod:@"SpellCheck.initiateSpellCheck"
349 arguments:@[ [NSNull null], @"some string" ]
350 result:^(id _Nullable result) {
351 capturedResult = result;
352 }];
353 XCTAssertNotNil([self.plugin textChecker]);
354}

◆ testUnsupportedLanguageShouldReturnNil

- (void) testUnsupportedLanguageShouldReturnNil
implementation

Definition at line 97 of file FlutterSpellCheckPluginTest.mm.

255 {
256 self.partialMockPlugin = OCMPartialMock(self.plugin);
257 OCMStub([self.partialMockPlugin textChecker]).andReturn(self.mockTextChecker);
258 id textCheckerClassMock = OCMClassMock([UITextChecker class]);
259 [[[textCheckerClassMock stub] andReturn:@[ @"en" ]] availableLanguages];
260 [self mockUITextCheckerWithExpectedMisspelledWordRange:NSMakeRange(0, 5)
261 startingIndex:0
262 suggestions:@[]];
263 __block id capturedResult;
264 [self.mockMethodChannel invokeMethod:@"SpellCheck.initiateSpellCheck"
265 arguments:@[ @"xx", @"helloo" ]
266 result:^(id _Nullable result) {
267 capturedResult = result;
268 }];
269 XCTAssertNil(capturedResult);
270 [textCheckerClassMock stopMocking];
271}

Property Documentation

◆ mockMethodChannel

- (id) mockMethodChannel
readwritenonatomicstrong

Definition at line 94 of file FlutterSpellCheckPluginTest.mm.

◆ mockTextChecker

- (id) mockTextChecker
readwritenonatomicstrong

Definition at line 96 of file FlutterSpellCheckPluginTest.mm.

◆ partialMockPlugin

- (id) partialMockPlugin
readwritenonatomicstrong

Definition at line 97 of file FlutterSpellCheckPluginTest.mm.

◆ plugin

- (FlutterSpellCheckPlugin*) plugin
readwritenonatomicstrong

Definition at line 95 of file FlutterSpellCheckPluginTest.mm.


The documentation for this class was generated from the following file: