krzysztofzablocki / Sourcery

Meta-programming for Swift, stop writing boilerplate code.
http://merowing.info
MIT License
7.65k stars 616 forks source link

Fixed incorrect case prefix parsing #1341

Closed art-divin closed 3 months ago

art-divin commented 3 months ago

Resolves #1340

Context

Given the following code:

// sourcery: AutoStubable
struct MyStruct {

    // sourcery: stub = "A"
    let basic: String

    // sourcery: stub = "B"
    let caseProperty: String

    // sourcery: stub = "C"
    let casesProperty: String

    // sourcery: stub = "D"
    let CaseProperty: String
}

and parsing implemented as follows:

let isInsideCaseDefinition = prefix.trimmingCharacters(in: .whitespacesAndNewlines).hasPrefix("case")
prefix = prefix.trimmingPrefix("case").trimmingCharacters(in: .whitespaces)

an incorrect result is produced, because of the variable names starting with case.