Skip to content

Commit

Permalink
Merge branch 'master' into fixture_validation
Browse files Browse the repository at this point in the history
# Conflicts:
#	Tests/MockoloTestCase.swift
#	Tests/TestActor/FixtureGlobalActor.swift
#	Tests/TestArgumentsHistory/FixtureArgumentsHistory.swift
#	Tests/TestEmojis/FixtureEmojis.swift
#	Tests/TestFuncs/TestBasicFuncs/FixtureNonSimpleFuncs.swift
#	Tests/TestFuncs/TestFuncAsync/FixtureFuncAsync.swift
#	Tests/TestOverloads/FixtureInheritance.swift
#	Tests/TestPATs/FixturePAT.swift
  • Loading branch information
sidepelican committed Dec 9, 2024
2 parents f2c4533 + e15f91f commit 2bb97d6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
21 changes: 16 additions & 5 deletions Sources/MockoloFramework/Parsers/SwiftSyntaxExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// limitations under the License.
//

import Algorithms
import Foundation
import SwiftSyntax
import SwiftParser
Expand Down Expand Up @@ -259,7 +260,7 @@ extension IfConfigDeclSyntax {
in: subModels,
exclude: [:],
fullnames: []
).map({ $0 })
).sorted(path: \.value.offset, fallback: \.key)

let macroModel = IfMacroModel(name: name, offset: self.offset, entities: uniqueSubModels)
return (macroModel, attrDesc, hasInit)
Expand Down Expand Up @@ -300,7 +301,12 @@ extension ProtocolDeclSyntax: EntityNode {
}

func annotationMetadata(with annotation: String) -> AnnotationMetadata? {
return leadingTrivia.annotationMetadata(with: annotation)
let trivias = [
leadingTrivia,
protocolKeyword.leadingTrivia,
modifiers.leadingTrivia,
] + attributes.map(\.leadingTrivia)
return trivias.firstNonNil { $0.annotationMetadata(with: annotation) }
}

var hasBlankInit: Bool {
Expand Down Expand Up @@ -358,7 +364,12 @@ extension ClassDeclSyntax: EntityNode {
}

func annotationMetadata(with annotation: String) -> AnnotationMetadata? {
return leadingTrivia.annotationMetadata(with: annotation)
let trivias = [
leadingTrivia,
classKeyword.leadingTrivia,
modifiers.leadingTrivia,
] + attributes.map(\.leadingTrivia)
return trivias.firstNonNil { $0.annotationMetadata(with: annotation) }
}

func subContainer(metadata: AnnotationMetadata?, declKind: NominalTypeDeclKind, path: String?, isProcessed: Bool) -> EntityNodeSubContainer {
Expand Down Expand Up @@ -863,9 +874,9 @@ extension Trivia {
// See metadata(with:, in:) for more info on the annotation arguments.
func annotationMetadata(with annotation: String) -> AnnotationMetadata? {
guard !annotation.isEmpty else { return nil }

var ret: AnnotationMetadata?
for i in 0..<count {
let trivia = self[i]
for trivia in self {
switch trivia {
case .docLineComment(let val):
ret = metadata(with: annotation, in: val)
Expand Down
6 changes: 6 additions & 0 deletions Tests/TestActor/ActorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ final class ActorTests: MockoloTestCase {
verify(srcContent: globalActorProtocol._source,
dstContent: globalActorProtocol.expected._source)
}

func testAttributeAboveAnnotationComment() {
verify(srcContent: attributeAboveAnnotationComment._source,
dstContent: attributeAboveAnnotationComment.expected._source,
declType: .all)
}
}
34 changes: 34 additions & 0 deletions Tests/TestActor/FixtureActor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,37 @@
}
}
}

@Fixture enum attributeAboveAnnotationComment {
@MainActor
/// @mockable
protocol P0 {
}

@MainActor
/// @mockable
@available(iOS 18.0, *) protocol P1 {
}

@MainActor
/// @mockable
public class C0 {
init() {}
}

@Fixture enum expected {
class P0Mock: P0 {
init() { }
}

class P1Mock: P1 {
init() { }
}

public class C0Mock: C0 {
override init() {
super.init()
}
}
}
}

0 comments on commit 2bb97d6

Please sign in to comment.