@@ -90,37 +90,78 @@ func assertLexicalNameLookup(
9090 useNilAsTheParameter: Bool = false ,
9191 config: LookupConfig = LookupConfig ( )
9292) {
93+ let expectedResults = references. mapValues { expectations in
94+ expectations. flatMap { expectation in
95+ expectation. expectedNames. flatMap { expectedName in
96+ expectedName. marker
97+ }
98+ }
99+ }
100+
101+ // Perform test without cache
102+ assertLexicalScopeQuery (
103+ source: source,
104+ methodUnderTest: { marker, tokenAtMarker in
105+ testFunction (
106+ marker: marker,
107+ tokenAtMarker: tokenAtMarker,
108+ references: references,
109+ useNilAsTheParameter: useNilAsTheParameter,
110+ config: config,
111+ cache: nil
112+ )
113+ } ,
114+ expected: expectedResults,
115+ expectedResultTypes: expectedResultTypes
116+ )
117+
118+ // Perform test with cache
119+ let cache = LookupCache ( )
93120 assertLexicalScopeQuery (
94121 source: source,
95122 methodUnderTest: { marker, tokenAtMarker in
96- let lookupIdentifier = Identifier ( tokenAtMarker)
123+ testFunction (
124+ marker: marker,
125+ tokenAtMarker: tokenAtMarker,
126+ references: references,
127+ useNilAsTheParameter: useNilAsTheParameter,
128+ config: config,
129+ cache: cache
130+ )
131+ } ,
132+ expected: expectedResults,
133+ expectedResultTypes: expectedResultTypes
134+ )
135+ }
97136
98- let result = tokenAtMarker. lookup ( useNilAsTheParameter ? nil : lookupIdentifier, with: config)
137+ /// Asserts result of unqualified lookup for the given `marker` and `tokenAtMarker`.
138+ /// Returns flattened array of syntax nodes returned by the query.
139+ private func testFunction(
140+ marker: String ,
141+ tokenAtMarker: TokenSyntax ,
142+ references: [ String : [ ResultExpectation ] ] ,
143+ useNilAsTheParameter: Bool ,
144+ config: LookupConfig ,
145+ cache: LookupCache ?
146+ ) -> [ SyntaxProtocol ] {
147+ let lookupIdentifier = Identifier ( tokenAtMarker)
99148
100- guard let expectedValues = references [ marker] else {
101- XCTFail ( " For marker \( marker) , couldn't find result expectation " )
102- return [ ]
103- }
149+ let result = tokenAtMarker. lookup ( useNilAsTheParameter ? nil : lookupIdentifier, with: config, cache: cache)
104150
105- ResultExpectation . assertResult ( marker: marker, result: result, expectedValues: expectedValues)
151+ guard let expectedValues = references [ marker] else {
152+ XCTFail ( " For marker \( marker) , couldn't find result expectation " )
153+ return [ ]
154+ }
106155
107- return result. flatMap { lookUpResult in
108- lookUpResult. names. flatMap { lookupName in
109- if case . equivalentNames( let names) = lookupName {
110- return names. map ( \. syntax)
111- } else {
112- return [ lookupName. syntax]
113- }
114- }
115- }
116- } ,
117- expected: references. mapValues { expectations in
118- expectations. flatMap { expectation in
119- expectation. expectedNames. flatMap { expectedName in
120- expectedName. marker
121- }
156+ ResultExpectation . assertResult ( marker: marker, result: result, expectedValues: expectedValues)
157+
158+ return result. flatMap { lookUpResult in
159+ lookUpResult. names. flatMap { lookupName in
160+ if case . equivalentNames( let names) = lookupName {
161+ return names. map ( \. syntax)
162+ } else {
163+ return [ lookupName. syntax]
122164 }
123- } ,
124- expectedResultTypes: expectedResultTypes
125- )
165+ }
166+ }
126167}
0 commit comments