mirror of
https://github.com/unclebob/crapper.git
synced 2026-11-26 18:18:49 +00:00
Skip Swift requirements that have no statements.
Protocol subscripts and `{ get set }` properties were scored as functions
even though they contain no executable body, unlike protocol methods.
The new test lists those requirements and a real subscript, and failed
until entries required a statements node. Accessor tests still pass.
Co-authored-by: Robert C. Martin <[email protected]>
This commit is contained in:
co-authored by
Robert C. Martin
parent
10c4e43f7b
commit
ccbf312645
@@ -164,6 +164,28 @@ func outer(flag: Bool) -> Int {
|
||||
assert "map" in source.encode()[make.start_byte : make.end_byte].decode()
|
||||
|
||||
|
||||
def test_a_requirement_without_a_body_is_not_a_function():
|
||||
source = """
|
||||
protocol P {
|
||||
func req()
|
||||
var name: String { get set }
|
||||
subscript(i: Int) -> Int { get set }
|
||||
init()
|
||||
}
|
||||
struct S {
|
||||
var name: String { get set }
|
||||
subscript(i: Int) -> Int { i > 0 ? i : 0 }
|
||||
}
|
||||
class C {
|
||||
var label: String { get set }
|
||||
}
|
||||
"""
|
||||
functions = functions_in_source(source, "Sources/Demo/Box.swift", "/proj")
|
||||
assert [(fn.namespace, fn.name, fn.complexity) for fn in functions] == [
|
||||
("Demo.S", "subscript", 2)
|
||||
]
|
||||
|
||||
|
||||
def test_swiftui_body_is_the_view_type():
|
||||
source = """
|
||||
import SwiftUI
|
||||
|
||||
Reference in New Issue
Block a user