@@ -254,6 +254,18 @@ final class DeclarationTests: XCTestCase {
254254 XCTAssert ( source. declarations [ 5 ] . name == " enum Planet<Item> " )
255255 }
256256
257+ func test_macro( ) {
258+ let code =
259+ """
260+ @attached(member, names: named(_registerModule), named(moduleName), named(requiresMainQueueSetup), named(methodQueue))
261+ public macro ReactView(jsName: String? = nil) = #externalMacro(module: " ReactBridgeMacros " , type: " ReactView " )
262+ """
263+ let source = SwiftSource ( source: code)
264+ XCTAssert ( source. declarations. count == 1 )
265+ XCTAssert ( source. declarations [ 0 ] . name == " macro ReactView(jsName: String? = nil) " )
266+ XCTAssert ( source. declarations [ 0 ] . accessLevel == . public)
267+ }
268+
257269 func test_precedencegroup_operator( ) {
258270 let code =
259271 """
@@ -358,13 +370,30 @@ final class DeclarationTests: XCTestCase {
358370 XCTAssert ( source. declarations [ 10 ] . accessLevel == . internal)
359371 XCTAssert ( source. declarations [ 11 ] . accessLevel == . internal)
360372 }
373+
374+ func test_multilines( ) {
375+ let code =
376+ """
377+ func greet(
378+ id: Number,
379+ person: String,
380+ text: String) -> String
381+ {
382+ person + text
383+ }
384+ """
385+ let source = SwiftSource ( source: code)
386+ XCTAssert ( source. declarations. count == 1 )
387+ XCTAssert ( source. declarations [ 0 ] . name == " func greet( id: Number, person: String, text: String) -> String " )
388+ }
361389}
362390
363- final class DocumentationTests : XCTestCase {
391+ final class DocTests : XCTestCase {
364392
365393 func test_no_comments( ) {
366394 let code =
367395 """
396+
368397 public func eat(_ food: Food, quantity: Int) throws -> Int { return 0 }
369398 """
370399 let source = SwiftSource ( source: code)
@@ -378,7 +407,9 @@ final class DocumentationTests: XCTestCase {
378407 // A developer line comment
379408 /* A developer block comment */
380409 /// A documentation line comment
381- /** A documentation block comment */
410+ /** A documentation
411+ block comment */
412+
382413 mutating public func eat(_ food: Food, quantity: Int) throws -> Int { return 0 }
383414 """
384415 let source = SwiftSource ( source: code)
@@ -387,73 +418,27 @@ final class DocumentationTests: XCTestCase {
387418 XCTAssert ( source. declarations [ 0 ] . comments [ 0 ] . text == " // A developer line comment " )
388419 XCTAssert ( source. declarations [ 0 ] . comments [ 1 ] . text == " /* A developer block comment */" )
389420 XCTAssert ( source. declarations [ 0 ] . comments [ 2 ] . text == " /// A documentation line comment " )
390- XCTAssert ( source. declarations [ 0 ] . comments [ 3 ] . text == " /** A documentation block comment */" )
421+ XCTAssert ( source. declarations [ 0 ] . comments [ 3 ] . text == " /** A documentation \nblock comment */" )
391422 }
392423}
393424
394425final class FileTests : XCTestCase {
395426
396427 static let directoryURL = Bundle . module. url ( forResource: " Resources " , withExtension: nil , subdirectory: nil ) !
397428 static let fileURL = directoryURL. appendingPathComponent ( " Rect/Rect.swift " )
398- static let readmeURL = directoryURL. appendingPathComponent ( " README.md " )
399- static let emptyDirURL = directoryURL. appendingPathComponent ( " Empty " )
400-
401- func test_file( ) throws {
402- let source = try SwiftSource ( url: Self . fileURL)
403- XCTAssert ( source. declarations. count == 4 )
404- }
405-
406- func test_not_found( ) throws {
407- // XCTAssertThrowsError(try Coverage(paths: [Self.directoryURL.appendingPathComponent("NotFound").path])) { error in
408- // XCTAssert(error.localizedDescription == "Path not found.")
409- // }
410- }
411-
412- func test_not_swift_file( ) throws {
413- // XCTAssertThrowsError(try Coverage(paths: [Self.readmeURL.path])) { error in
414- // XCTAssert(error.localizedDescription == "Not swift file.")
415- // }
416- }
429+ //static let readmeURL = directoryURL.appendingPathComponent("README.md")
430+ //static let emptyDirURL = directoryURL.appendingPathComponent("Empty")
417431
418- func test_no_declarations( ) throws {
419- // let coverage = try Coverage(paths: [Self.fileURL.path], minAccessLevel: .open)
420- // XCTAssertThrowsError(try coverage.report()) { error in
421- // XCTAssert(error.localizedDescription == "Declarations not found.")
422- // }
423- }
424-
425- func test_report( ) throws {
426- // let coverage = try Coverage(paths: [Self.fileURL.path])
427- // let report = try coverage.report()
428- //
429- // XCTAssert(report.totalCount == 4)
430- // XCTAssert(report.totalUndocumentedCount == 2)
431- // XCTAssert(report.sources.count == 1)
432- //
433- // try coverage.reportStatistics()
434- }
435-
436- func test_empty_directory( ) throws {
437- // let tempDirectory = tempDirectory()
438- // defer { try? FileManager.default.removeItem(at: tempDirectory) }
439- //
440- // XCTAssertThrowsError(try Coverage(paths: [tempDirectory.path])) { error in
441- // XCTAssert(error.localizedDescription == "Swift files not found.")
442- // }
443- }
444-
445- func test_directory( ) throws {
446- // let coverage = try Coverage(paths: [Self.directoryURL.path])
447- // let report = try coverage.report()
448- //
449- // XCTAssert(report.totalCount == 4)
450- // XCTAssert(report.totalUndocumentedCount == 2)
451- // print(report.sources.count == 1)
432+ func test_no_file( ) throws {
433+ let fileURL = URL ( filePath: Self . directoryURL. appendingPathComponent ( " File.swift " ) . path)
434+ XCTAssertThrowsError ( try SwiftSource ( fileURL: fileURL) ) { error in
435+ XCTAssert ( error. localizedDescription == " The file “File.swift” couldn’t be opened because there is no such file. " )
436+ }
452437 }
453438
454- func test_warnings ( ) throws {
455- // let coverage = try Coverage(paths: [ Self.fileURL.path] )
456- // try coverage.reportWarnings( )
439+ func test_file ( ) throws {
440+ let source = try SwiftSource ( fileURL : Self . fileURL)
441+ XCTAssert ( source . declarations . count == 4 )
457442 }
458443}
459444
@@ -502,6 +487,54 @@ final class ToolTests: XCTestCase {
502487 XCTAssert ( process. terminationStatus == EXIT_FAILURE)
503488 }
504489
490+ // func test_directory() throws {
491+ // let coverage = try Coverage(paths: [Self.directoryURL.path])
492+ // let report = try coverage.report()
493+ //
494+ // XCTAssert(report.totalCount == 4)
495+ // XCTAssert(report.totalUndocumentedCount == 2)
496+ // print(report.sources.count == 1)
497+ // }
498+
499+ // func test_empty_directory() throws {
500+ // let tempDirectory = tempDirectory()
501+ // defer { try? FileManager.default.removeItem(at: tempDirectory) }
502+ //
503+ // XCTAssertThrowsError(try Coverage(paths: [tempDirectory.path])) { error in
504+ // XCTAssert(error.localizedDescription == "Swift files not found.")
505+ // }
506+ // }
507+
508+ //func test_not_found() throws {
509+ // XCTAssertThrowsError(try Coverage(paths: [Self.directoryURL.appendingPathComponent("NotFound").path])) { error in
510+ // XCTAssert(error.localizedDescription == "Path not found.")
511+ // }
512+ //}
513+
514+ //func test_not_swift_file() throws {
515+ // XCTAssertThrowsError(try Coverage(paths: [Self.readmeURL.path])) { error in
516+ // XCTAssert(error.localizedDescription == "Not swift file.")
517+ // }
518+ //}
519+
520+ // func test_no_declarations() throws {
521+ // let coverage = try Coverage(paths: [Self.fileURL.path], minAccessLevel: .open)
522+ // XCTAssertThrowsError(try coverage.report()) { error in
523+ // XCTAssert(error.localizedDescription == "Declarations not found.")
524+ // }
525+ // }
526+
527+ // func test_report() throws {
528+ // let coverage = try Coverage(paths: [Self.fileURL.path])
529+ // let report = try coverage.report()
530+ //
531+ // XCTAssert(report.totalCount == 4)
532+ // XCTAssert(report.totalUndocumentedCount == 2)
533+ // XCTAssert(report.sources.count == 1)
534+ //
535+ // try coverage.reportStatistics()
536+ // }
537+
505538 func test_output( ) throws {
506539 let process = Process ( )
507540 let output = try process. run ( swiftDocCoverageURL, arguments: [ fileURL. path] )
@@ -510,25 +543,30 @@ final class ToolTests: XCTestCase {
510543 XCTAssert ( output. contains ( " Total: 50% " ) )
511544 }
512545
546+ // func test_warnings() throws {
547+ // let coverage = try Coverage(paths: [Self.fileURL.path])
548+ // try coverage.reportWarnings()
549+ // }
550+
513551 func test_warninigs( ) throws {
514- let process = Process ( )
515- let output = try process. run ( swiftDocCoverageURL, arguments: [ fileURL. path, " --report " , " warnings " ] )
516- XCTAssert ( process. terminationStatus == EXIT_SUCCESS)
517- XCTAssert ( output. contains ( " warning: No documentation for 'Rect.size'. " ) )
552+ // let process = Process()
553+ // let output = try process.run(swiftDocCoverageURL, arguments: [fileURL.path, "--report", "warnings"])
554+ // XCTAssert(process.terminationStatus == EXIT_SUCCESS)
555+ // XCTAssert(output.contains("warning: No documentation for 'Rect.size'."))
518556 }
519557
520558 func test_json( ) throws {
521- let process = Process ( )
522- let output = try process. run ( swiftDocCoverageURL, arguments: [ fileURL. path, " --report " , " json " ] )
523- XCTAssert ( process. terminationStatus == EXIT_SUCCESS)
524-
525- if let data = output. data ( using: . utf8) ,
526- let json = try JSONSerialization . jsonObject ( with: data) as? [ String : Any ] {
527- XCTAssert ( json [ " sources " ] != nil )
528- }
529- else {
530- XCTFail ( )
531- }
559+ // let process = Process()
560+ // let output = try process.run(swiftDocCoverageURL, arguments: [fileURL.path, "--report", "json"])
561+ // XCTAssert(process.terminationStatus == EXIT_SUCCESS)
562+ //
563+ // if let data = output.data(using: .utf8),
564+ // let json = try JSONSerialization.jsonObject(with: data) as? [String : Any] {
565+ // XCTAssert(json["sources"] != nil)
566+ // }
567+ // else {
568+ // XCTFail()
569+ // }
532570 }
533571
534572 func test_file_output( ) throws {
0 commit comments