@@ -297,6 +297,79 @@ final class FunctionTests: XCTestCase {
297297 XCTAssertEqual ( instanceUnderTest. functions [ 0 ] . signature. node, instanceUnderTest. functions [ 0 ] . node. signature)
298298 }
299299
300+ func test_function_inoutWithinClosure_resolvesExpectedTypes( ) {
301+ let source = #"""
302+ func closure(_ handler: @escaping (inout Int, String) -> Void, name: inout String) {}
303+ """#
304+ instanceUnderTest. updateToSource ( source)
305+ XCTAssertTrue ( instanceUnderTest. isStale)
306+ instanceUnderTest. collectChildren ( )
307+ XCTAssertFalse ( instanceUnderTest. isStale)
308+ XCTAssertEqual ( instanceUnderTest. functions. count, 1 )
309+ let function = instanceUnderTest. functions [ 0 ]
310+
311+ XCTAssertEqual ( function. keyword, " func " )
312+ XCTAssertEqual ( function. identifier, " closure " )
313+ XCTAssertNil ( function. signature. effectSpecifiers)
314+ XCTAssertEqual ( function. signature. input. count, 2 )
315+ // Closure Input with inout input
316+ XCTAssertEqual ( function. signature. input [ 0 ] . attributes. map ( \. name) , [ " escaping " ] )
317+ XCTAssertEqual ( function. signature. input [ 0 ] . attributes. flatMap ( \. arguments) , [ ] )
318+ XCTAssertEqual ( function. signature. input [ 0 ] . modifiers, [ ] )
319+ XCTAssertEqual ( function. signature. input [ 0 ] . name, " _ " )
320+ XCTAssertEqual ( function. signature. input [ 0 ] . secondName, " handler " )
321+ XCTAssertTrue ( function. signature. input [ 0 ] . isLabelOmitted)
322+ XCTAssertFalse ( function. signature. input [ 0 ] . isVariadic)
323+ XCTAssertFalse ( function. signature. input [ 0 ] . isOptional)
324+ XCTAssertFalse ( function. signature. input [ 0 ] . isInOut)
325+ XCTAssertNil ( function. signature. input [ 0 ] . defaultArgument)
326+ XCTAssertEqual ( function. signature. input [ 0 ] . rawType, " @escaping (inout Int, String) -> Void " )
327+ XCTAssertEqual ( function. signature. input [ 0 ] . description, " _ handler: @escaping (inout Int, String) -> Void " )
328+ // Closure type assessment
329+ if case let EntityType . closure( closure) = function. signature. input [ 0 ] . type {
330+ XCTAssertEqual ( closure. output, . void( " Void " , false ) )
331+ XCTAssertTrue ( closure. isVoidOutput)
332+ XCTAssertFalse ( closure. isOptional)
333+ XCTAssertTrue ( closure. isEscaping)
334+ XCTAssertFalse ( closure. isAutoEscaping)
335+ XCTAssertEqual ( closure. description, " (inout Int, String) -> Void " )
336+ // Input
337+ XCTAssertFalse ( closure. isVoidInput)
338+ if case let EntityType . tuple( tuple) = closure. input {
339+ XCTAssertEqual ( tuple. elements. count, 2 )
340+ // Inout Int
341+ XCTAssertFalse ( tuple. elements [ 0 ] . isOptional)
342+ XCTAssertTrue ( tuple. elements [ 0 ] . isInOut)
343+ XCTAssertEqual ( tuple. elements [ 0 ] . type, . simple( " Int " ) )
344+ XCTAssertEqual ( tuple. elements [ 0 ] . description, " inout Int " )
345+ // Standard String
346+ XCTAssertFalse ( tuple. elements [ 1 ] . isOptional)
347+ XCTAssertFalse ( tuple. elements [ 1 ] . isInOut)
348+ XCTAssertEqual ( tuple. elements [ 1 ] . type, . simple( " String " ) )
349+ XCTAssertEqual ( tuple. elements [ 1 ] . description, " String " )
350+ } else {
351+ XCTFail ( " The closure input should be a tuple type " )
352+ }
353+ } else {
354+ XCTFail ( " function.signature.input[0] type should be closure " )
355+ }
356+
357+ // inout name String
358+ XCTAssertEqual ( function. signature. input [ 1 ] . attributes. map ( \. name) , [ ] )
359+ XCTAssertEqual ( function. signature. input [ 1 ] . attributes. flatMap ( \. arguments) , [ ] )
360+ XCTAssertEqual ( function. signature. input [ 1 ] . modifiers, [ ] )
361+ XCTAssertEqual ( function. signature. input [ 1 ] . name, " name " )
362+ XCTAssertNil ( function. signature. input [ 1 ] . secondName)
363+ XCTAssertFalse ( function. signature. input [ 1 ] . isLabelOmitted)
364+ XCTAssertFalse ( function. signature. input [ 1 ] . isVariadic)
365+ XCTAssertFalse ( function. signature. input [ 1 ] . isOptional)
366+ XCTAssertTrue ( function. signature. input [ 1 ] . isInOut)
367+ XCTAssertNil ( function. signature. input [ 1 ] . defaultArgument)
368+ XCTAssertEqual ( function. signature. input [ 1 ] . type. description, " String " )
369+ XCTAssertEqual ( function. signature. input [ 1 ] . rawType, " inout String " )
370+ XCTAssertEqual ( function. signature. input [ 1 ] . description, " name: inout String " )
371+ }
372+
300373 func test_function_parameters_willResolveExpectedTypes( ) throws {
301374 let source = #"""
302375 func noParameters() throws {}
0 commit comments