@@ -344,6 +344,85 @@ final class ObjectiveCFocusedCodeFinder_Selection_Tests: XCTestCase {
344344 }
345345}
346346
347+ final class ObjectiveCFocusedCodeFinder_Focus_Tests : XCTestCase {
348+ func test_get_focused_code_inside_method_the_method_should_be_the_focused_code( ) {
349+ let code = """
350+ @implementation Foo
351+ - (void)fooWith:(NSInteger)foo {
352+ NSInteger foo = 0;
353+ NSLog(@ " Hello " );
354+ NSLog(@ " World " );
355+ }
356+ @end
357+ """
358+ let range = CursorRange (
359+ start: CursorPosition ( line: 2 , character: 0 ) ,
360+ end: CursorPosition ( line: 2 , character: 0 )
361+ )
362+ let context = ObjectiveCFocusedCodeFinder ( ) . findFocusedCode (
363+ in: document ( code: code) ,
364+ containingRange: range
365+ )
366+ XCTAssertEqual ( context, . init(
367+ scope: . scope( signature: [
368+ . init(
369+ signature: " @implementation Foo " ,
370+ name: " Foo " ,
371+ range: . init( startPair: ( 0 , 0 ) , endPair: ( 6 , 4 ) )
372+ ) ,
373+ ] ) ,
374+ contextRange: . init( startPair: ( 0 , 0 ) , endPair: ( 6 , 4 ) ) ,
375+ focusedRange: . init( startPair: ( 1 , 0 ) , endPair: ( 5 , 1 ) ) ,
376+ focusedCode: """
377+ - (void)fooWith:(NSInteger)foo {
378+ NSInteger foo = 0;
379+ NSLog(@ " Hello " );
380+ NSLog(@ " World " );
381+ }
382+
383+ """ ,
384+ imports: [ ] ,
385+ includes: [ ]
386+ ) )
387+ }
388+
389+ func test_get_focused_code_inside_an_interface_category_the_focused_code_should_be_the_interface( ) {
390+ let code = """
391+ @interface __GENERICS(NSArray, ObjectType) (BlocksKit)
392+ - (void)fooWith:(NSInteger)foo;
393+ - (void)fooWith:(NSInteger)foo;
394+ - (void)fooWith:(NSInteger)foo;
395+ @end
396+
397+ @implementation Foo
398+ @end
399+ """
400+ let range = CursorRange (
401+ start: CursorPosition ( line: 1 , character: 0 ) ,
402+ end: CursorPosition ( line: 1 , character: 0 )
403+ )
404+ let context = ObjectiveCFocusedCodeFinder ( ) . findFocusedCode (
405+ in: document ( code: code) ,
406+ containingRange: range
407+ )
408+ XCTAssertEqual ( context, . init(
409+ scope: . file,
410+ contextRange: . init( startPair: ( 0 , 0 ) , endPair: ( 0 , 0 ) ) ,
411+ focusedRange: . init( startPair: ( 0 , 0 ) , endPair: ( 4 , 4 ) ) ,
412+ focusedCode: """
413+ @interface __GENERICS(NSArray, ObjectType) (BlocksKit)
414+ - (void)fooWith:(NSInteger)foo;
415+ - (void)fooWith:(NSInteger)foo;
416+ - (void)fooWith:(NSInteger)foo;
417+ @end
418+
419+ """ ,
420+ imports: [ ] ,
421+ includes: [ ]
422+ ) )
423+ }
424+ }
425+
347426final class ObjectiveCFocusedCodeFinder_Imports_Tests : XCTestCase {
348427 func test_parsing_imports( ) {
349428 let code = """
0 commit comments