Skip to content

Commit

Permalink
[BUG] Fix bug with hasSetter helper on Variable (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
mobrien-ghost authored Apr 3, 2024
1 parent 0c23bb5 commit d4dd1c8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct VariableSemanticsResolver: SemanticsResolving {

func resolveHasSetter() -> Bool {
// If setter exists in accessors can return true
let hasSetterAccessor = resolveAccessors().contains(where: { $0.kind == .set || $0.kind == .willSet })
let hasSetterAccessor = resolveAccessors().contains(where: { $0.kind == .set || $0.kind == .willSet || $0.kind == .didSet })
if hasSetterAccessor {
return true
}
Expand Down
46 changes: 46 additions & 0 deletions Tests/SyntaxSparrowTests/Declarations/VariableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,52 @@ final class VariableTests: XCTestCase {
XCTAssertEqual(protocolOne.variables[2].accessors.map(\.kind), [])
}

func test_variable_hasSetterHelper_nested_willResolveExpectedValues() {
let source = #"""
protocol Example {
var name: String { get }
var name: String { get set }
}
class Example {
let name: String = "test"
var nameTwo: String = "test"
var nameThree: String = "test" {
didSet {}
}
}
struct Example {
let name: String = "test"
var nameTwo: String = "test"
var nameThree: String = "test" {
didSet {}
}
}
"""#
instanceUnderTest.updateToSource(source)
XCTAssertTrue(instanceUnderTest.isStale)
instanceUnderTest.collectChildren()
XCTAssertFalse(instanceUnderTest.isStale)
// Protocols
var variables = instanceUnderTest.protocols[0].variables
XCTAssertEqual(variables.count, 2)
XCTAssertFalse(variables[0].hasSetter)
XCTAssertTrue(variables[1].hasSetter)
// Class
variables = instanceUnderTest.classes[0].variables
XCTAssertEqual(variables.count, 3)
XCTAssertFalse(variables[0].hasSetter)
XCTAssertTrue(variables[1].hasSetter)
XCTAssertTrue(variables[2].hasSetter)
// Struct
variables = instanceUnderTest.structures[0].variables
XCTAssertEqual(variables.count, 3)
XCTAssertFalse(variables[0].hasSetter)
XCTAssertTrue(variables[1].hasSetter)
XCTAssertTrue(variables[2].hasSetter)
}

func test_variable_hasSetterHelper_willResolveExpectedValues() {
let source = #"""
var name: String {
Expand Down

0 comments on commit d4dd1c8

Please sign in to comment.