@@ -2122,137 +2122,194 @@ void main() {
21222122 // Put linkage tests here; rendering tests should go to the appropriate
21232123 // [Class], [Extension], etc groups.
21242124 group ('Comment References link tests' , () {
2125- ModelFunction doesStuff, function1, topLevelFunction;
2126- TopLevelVariable incorrectDocReference, incorrectDocReferenceFromEx, nameWithTwoUnderscores, nameWithSingleUnderscore, theOnlyThingInTheLibrary;
2127- Class Apple , BaseClass , baseForDocComments, ExtraSpecialList , string;
2128- Method doAwesomeStuff, anotherMethod;
2129- // ignore: unused_local_variable
2130- Operator bracketOperator, bracketOperatorOtherClass;
2131- Parameter doAwesomeStuffParam;
2132- Field forInheriting, action;
2133-
2134- setUpAll (() async {
2135- nameWithTwoUnderscores = fakeLibrary.constants.firstWhere ((v) => v.name == 'NAME_WITH_TWO_UNDERSCORES' );
2136- nameWithSingleUnderscore = fakeLibrary.constants.firstWhere ((v) => v.name == 'NAME_SINGLEUNDERSCORE' );
2137- string = packageGraph.allLibraries.values
2138- .firstWhere ((e) => e.name == 'dart:core' )
2139- .allClasses
2140- .firstWhere ((c) => c.name == 'String' );
2141- baseForDocComments =
2142- fakeLibrary.classes.firstWhere ((c) => c.name == 'BaseForDocComments' );
2143- doAwesomeStuff = baseForDocComments.instanceMethods
2144- .firstWhere ((m) => m.name == 'doAwesomeStuff' );
2145- anotherMethod = baseForDocComments.instanceMethods
2146- .firstWhere ((m) => m.name == 'anotherMethod' );
2147- doAwesomeStuffParam = doAwesomeStuff.parameters.first;
2148- topLevelFunction = fakeLibrary.functions.firstWhere ((f) => f.name == 'topLevelFunction' );
2149- function1 = exLibrary.functions.firstWhere ((f) => f.name == 'function1' );
2150- Apple = exLibrary.classes.firstWhere ((c) => c.name == 'Apple' );
2151- incorrectDocReference = fakeLibrary.constants.firstWhere ((v) => v.name == 'incorrectDocReference' );
2152- incorrectDocReferenceFromEx = exLibrary.constants.firstWhere ((v) => v.name == 'incorrectDocReferenceFromEx' );
2153- theOnlyThingInTheLibrary = packageGraph.libraries.firstWhere ((l) => l.name == 'csspub' ).properties.firstWhere ((v) => v.name == 'theOnlyThingInTheLibrary' );
2154- doesStuff = packageGraph.allLibraries.values.firstWhere ((l) => l.name == 'anonymous_library' ).functions.firstWhere ((f) => f.name == 'doesStuff' );
2155- BaseClass = packageGraph.allLibraries.values.firstWhere ((l) => l.name == 'two_exports.src.base' ).classes.firstWhere ((c) => c.name == 'BaseClass' );
2156- bracketOperator = baseForDocComments.instanceOperators
2157- .firstWhere ((o) => o.name == 'operator []' );
2158- bracketOperatorOtherClass = fakeLibrary.classes.firstWhere ((c) => c.name == 'SpecialList' )
2159- .instanceOperators.firstWhere ((o) => o.name == 'operator []' );
2160- ExtraSpecialList = fakeLibrary.classes.firstWhere ((c) => c.name == 'ExtraSpecialList' );
2161- forInheriting = fakeLibrary.classes.firstWhere ((c) => c.name == 'ImplicitProperties' ).allFields.firstWhere ((n) => n.name == 'forInheriting' );
2162- action = packageGraph.allLibraries.values.firstWhere ((l) => l.name == 'reexport.somelib' ).classes.firstWhere ((c) => c.name == 'BaseReexported' ).allFields.firstWhere ((f) => f.name == 'action' );
2163- });
2164-
2165- /// For comparison purposes, return an equivalent [MatchingLinkResult]
2166- /// for the defining element returned. May return [originalResult] .
2167- /// We do this to eliminate canonicalization effects from comparison,
2168- /// as the original lookup code returns canonicalized results and the
2169- /// new lookup code is only guaranteed to return equivalent results.
2170- MatchingLinkResult definingLinkResult (MatchingLinkResult originalResult) {
2171- if (originalResult.modelElement != null ) {
2172- return MatchingLinkResult (ModelElement .fromElement (originalResult.modelElement.element, originalResult.modelElement.packageGraph), warn: originalResult.warn);
2173- }
2174- return originalResult;
2175- }
2125+ ModelFunction doesStuff, function1, topLevelFunction;
2126+ TopLevelVariable incorrectDocReference,
2127+ incorrectDocReferenceFromEx,
2128+ nameWithTwoUnderscores,
2129+ nameWithSingleUnderscore,
2130+ theOnlyThingInTheLibrary;
2131+ Class Apple , BaseClass , baseForDocComments, ExtraSpecialList , string;
2132+ Method doAwesomeStuff, anotherMethod;
2133+ // ignore: unused_local_variable
2134+ Operator bracketOperator, bracketOperatorOtherClass;
2135+ Parameter doAwesomeStuffParam;
2136+ Field forInheriting, action;
21762137
2177- MatchingLinkResult originalLookup (Warnable element, String codeRef) => definingLinkResult (getMatchingLinkElement (element, codeRef, experimentalReferenceLookup: false ));
2178- MatchingLinkResult newLookup (Warnable element, String codeRef) => definingLinkResult (getMatchingLinkElement (element, codeRef, experimentalReferenceLookup: true ));
2179-
2180- MatchingLinkResult bothLookup (Warnable element, String codeRef) {
2181- var originalLookupResult = originalLookup (element, codeRef);
2182- var newLookupResult = newLookup (element, codeRef);
2183- expect (newLookupResult, equals (originalLookupResult));
2184- return newLookupResult;
2138+ setUpAll (() async {
2139+ nameWithTwoUnderscores = fakeLibrary.constants
2140+ .firstWhere ((v) => v.name == 'NAME_WITH_TWO_UNDERSCORES' );
2141+ nameWithSingleUnderscore = fakeLibrary.constants
2142+ .firstWhere ((v) => v.name == 'NAME_SINGLEUNDERSCORE' );
2143+ string = packageGraph.allLibraries.values
2144+ .firstWhere ((e) => e.name == 'dart:core' )
2145+ .allClasses
2146+ .firstWhere ((c) => c.name == 'String' );
2147+ baseForDocComments =
2148+ fakeLibrary.classes.firstWhere ((c) => c.name == 'BaseForDocComments' );
2149+ doAwesomeStuff = baseForDocComments.instanceMethods
2150+ .firstWhere ((m) => m.name == 'doAwesomeStuff' );
2151+ anotherMethod = baseForDocComments.instanceMethods
2152+ .firstWhere ((m) => m.name == 'anotherMethod' );
2153+ doAwesomeStuffParam = doAwesomeStuff.parameters.first;
2154+ topLevelFunction =
2155+ fakeLibrary.functions.firstWhere ((f) => f.name == 'topLevelFunction' );
2156+ function1 = exLibrary.functions.firstWhere ((f) => f.name == 'function1' );
2157+ Apple = exLibrary.classes.firstWhere ((c) => c.name == 'Apple' );
2158+ incorrectDocReference = fakeLibrary.constants
2159+ .firstWhere ((v) => v.name == 'incorrectDocReference' );
2160+ incorrectDocReferenceFromEx = exLibrary.constants
2161+ .firstWhere ((v) => v.name == 'incorrectDocReferenceFromEx' );
2162+ theOnlyThingInTheLibrary = packageGraph.libraries
2163+ .firstWhere ((l) => l.name == 'csspub' )
2164+ .properties
2165+ .firstWhere ((v) => v.name == 'theOnlyThingInTheLibrary' );
2166+ doesStuff = packageGraph.allLibraries.values
2167+ .firstWhere ((l) => l.name == 'anonymous_library' )
2168+ .functions
2169+ .firstWhere ((f) => f.name == 'doesStuff' );
2170+ BaseClass = packageGraph.allLibraries.values
2171+ .firstWhere ((l) => l.name == 'two_exports.src.base' )
2172+ .classes
2173+ .firstWhere ((c) => c.name == 'BaseClass' );
2174+ bracketOperator = baseForDocComments.instanceOperators
2175+ .firstWhere ((o) => o.name == 'operator []' );
2176+ bracketOperatorOtherClass = fakeLibrary.classes
2177+ .firstWhere ((c) => c.name == 'SpecialList' )
2178+ .instanceOperators
2179+ .firstWhere ((o) => o.name == 'operator []' );
2180+ ExtraSpecialList =
2181+ fakeLibrary.classes.firstWhere ((c) => c.name == 'ExtraSpecialList' );
2182+ forInheriting = fakeLibrary.classes
2183+ .firstWhere ((c) => c.name == 'ImplicitProperties' )
2184+ .allFields
2185+ .firstWhere ((n) => n.name == 'forInheriting' );
2186+ action = packageGraph.allLibraries.values
2187+ .firstWhere ((l) => l.name == 'reexport.somelib' )
2188+ .classes
2189+ .firstWhere ((c) => c.name == 'BaseReexported' )
2190+ .allFields
2191+ .firstWhere ((f) => f.name == 'action' );
2192+ });
2193+
2194+ /// For comparison purposes, return an equivalent [MatchingLinkResult]
2195+ /// for the defining element returned. May return [originalResult] .
2196+ /// We do this to eliminate canonicalization effects from comparison,
2197+ /// as the original lookup code returns canonicalized results and the
2198+ /// new lookup code is only guaranteed to return equivalent results.
2199+ MatchingLinkResult definingLinkResult (MatchingLinkResult originalResult) {
2200+ if (originalResult.modelElement != null ) {
2201+ return MatchingLinkResult (
2202+ ModelElement .fromElement (originalResult.modelElement.element,
2203+ originalResult.modelElement.packageGraph),
2204+ warn: originalResult.warn);
21852205 }
2206+ return originalResult;
2207+ }
21862208
2187- test ('Verify basic linking inside class' , () {
2188- // parameter of [doAwesomeStuff]
2189- // Parameter lookups are discarded with the original lookup code
2190- expect (originalLookup (doAwesomeStuff, 'value' ), equals (MatchingLinkResult (null , warn: false )));
2191- expect (newLookup (doAwesomeStuff, 'value' ), equals (MatchingLinkResult (doAwesomeStuffParam)));
2192-
2193- // Parent class of [doAwesomeStuff].
2194- expect (bothLookup (doAwesomeStuff, 'BaseForDocComments' ), equals (MatchingLinkResult (baseForDocComments)));
2195-
2196- // Top level constants in the same library as [doAwesomeStuff].
2197- expect (bothLookup (doAwesomeStuff, 'NAME_WITH_TWO_UNDERSCORES' ), equals (MatchingLinkResult (nameWithTwoUnderscores)));
2198- expect (bothLookup (doAwesomeStuff, 'NAME_SINGLEUNDERSCORE' ), equals (MatchingLinkResult (nameWithSingleUnderscore)));
2199-
2200- // Top level class from [dart:core].
2201- // TODO(jcollins-g): dart:core not recognized yet with new lookup code.
2202- expect (originalLookup (doAwesomeStuff, 'String' ), equals (MatchingLinkResult (string)));
2203-
2204- // Another method in the same class.
2205- expect (bothLookup (doAwesomeStuff, 'anotherMethod' ), equals (MatchingLinkResult (anotherMethod)));
2206-
2207- // A top level function in this library.
2208- // TODO(jcollins-g): top level functions not recognized yet with new lookup code.
2209- expect (originalLookup (doAwesomeStuff, 'topLevelFunction' ), equals (MatchingLinkResult (topLevelFunction)));
2210-
2211- // A top level function in another library imported into this library.
2212- // TODO(jcollins-g): namespace lookups are not yet implemented with new lookup code.
2213- expect (originalLookup (doAwesomeStuff, 'function1' ), equals (MatchingLinkResult (function1)));
2214-
2215- // A class in another library imported into this library.
2216- // TODO(jcollins-g): namespace lookups are not yet implemented with new lookup code.
2217- expect (originalLookup (doAwesomeStuff, 'Apple' ), equals (MatchingLinkResult (Apple )));
2218-
2219- // A top level constant in this library sharing the same name as a name in another library.
2220- // TODO(jcollins-g): namespace lookups are not yet implemented with new lookup code.
2221- expect (originalLookup (doAwesomeStuff, 'incorrectDocReference' ), equals (MatchingLinkResult (incorrectDocReference)));
2222-
2223- // A top level constant in another library.
2224- // TODO(jcollins-g): namespace lookups are not yet implemented with new lookup code.
2225- expect (originalLookup (doAwesomeStuff, 'incorrectDocReferenceFromEx' ), equals (MatchingLinkResult (incorrectDocReferenceFromEx)));
2226-
2227- // A prefixed constant in another library.
2228- // TODO(jcollins-g): prefixed namespace lookups are not yet implemented with new lookup code.
2229- expect (originalLookup (doAwesomeStuff, 'css.theOnlyThingInTheLibrary' ), equals (MatchingLinkResult (theOnlyThingInTheLibrary)));
2230-
2231- // A name that exists in this package but is not imported.
2232- // TODO(jcollins-g): package-wide lookups are not yet implemented with the new lookup code.
2233- expect (originalLookup (doAwesomeStuff, 'doesStuff' ), equals (MatchingLinkResult (doesStuff)));
2234-
2235- // A name of a class from an import of a library that exported that name.
2236- expect (originalLookup (doAwesomeStuff, 'BaseClass' ), equals (MatchingLinkResult (BaseClass )));
2237-
2238- // A bracket operator within this class.
2239- // TODO(jcollins-g): operator lookups not yet implemented with the new lookup code.
2240- expect (originalLookup (doAwesomeStuff, 'operator []' ), equals (MatchingLinkResult (bracketOperator)));
2241-
2242- // A bracket operator in another class.
2243- // TODO(jcollins-g): This has never worked...
2244- //expect(bothLookup(doAwesomeStuff, 'SpecialList.operator []'), equals(MatchingLinkResult(bracketOperatorOtherClass)));
2245-
2246- // Reference containing a type parameter.
2247- expect (bothLookup (doAwesomeStuff, 'ExtraSpecialList<Object>' ), equals (MatchingLinkResult (ExtraSpecialList )));
2248-
2249- // Reference to an inherited member.
2250- expect (bothLookup (doAwesomeStuff, 'ClassWithUnusualProperties.forInheriting' ), equals (MatchingLinkResult (forInheriting)));
2209+ MatchingLinkResult originalLookup (Warnable element, String codeRef) =>
2210+ definingLinkResult (getMatchingLinkElement (element, codeRef,
2211+ experimentalReferenceLookup: false ));
2212+ MatchingLinkResult newLookup (Warnable element, String codeRef) =>
2213+ definingLinkResult (getMatchingLinkElement (element, codeRef,
2214+ experimentalReferenceLookup: true ));
2215+
2216+ MatchingLinkResult bothLookup (Warnable element, String codeRef) {
2217+ var originalLookupResult = originalLookup (element, codeRef);
2218+ var newLookupResult = newLookup (element, codeRef);
2219+ expect (newLookupResult, equals (originalLookupResult));
2220+ return newLookupResult;
2221+ }
22512222
2252- // Reference to an inherited member in another library via class name.
2253- // TODO(jcollins-g): reference to non-imported symbols isn't implemented yet in new lookup.
2254- expect (originalLookup (doAwesomeStuff, 'ExtendedBaseReexported.action' ), equals (MatchingLinkResult (action)));
2255- });
2223+ test ('Verify basic linking inside class' , () {
2224+ // parameter of [doAwesomeStuff]
2225+ // Parameter lookups are discarded with the original lookup code
2226+ expect (originalLookup (doAwesomeStuff, 'value' ),
2227+ equals (MatchingLinkResult (null , warn: false )));
2228+ expect (newLookup (doAwesomeStuff, 'value' ),
2229+ equals (MatchingLinkResult (doAwesomeStuffParam)));
2230+
2231+ // Parent class of [doAwesomeStuff].
2232+ expect (bothLookup (doAwesomeStuff, 'BaseForDocComments' ),
2233+ equals (MatchingLinkResult (baseForDocComments)));
2234+
2235+ // Top level constants in the same library as [doAwesomeStuff].
2236+ expect (bothLookup (doAwesomeStuff, 'NAME_WITH_TWO_UNDERSCORES' ),
2237+ equals (MatchingLinkResult (nameWithTwoUnderscores)));
2238+ expect (bothLookup (doAwesomeStuff, 'NAME_SINGLEUNDERSCORE' ),
2239+ equals (MatchingLinkResult (nameWithSingleUnderscore)));
2240+
2241+ // Top level class from [dart:core].
2242+ // TODO(jcollins-g): dart:core not recognized yet with new lookup code.
2243+ expect (originalLookup (doAwesomeStuff, 'String' ),
2244+ equals (MatchingLinkResult (string)));
2245+
2246+ // Another method in the same class.
2247+ expect (bothLookup (doAwesomeStuff, 'anotherMethod' ),
2248+ equals (MatchingLinkResult (anotherMethod)));
2249+
2250+ // A top level function in this library.
2251+ // TODO(jcollins-g): top level functions not recognized yet with new lookup code.
2252+ expect (originalLookup (doAwesomeStuff, 'topLevelFunction' ),
2253+ equals (MatchingLinkResult (topLevelFunction)));
2254+
2255+ // A top level function in another library imported into this library.
2256+ // TODO(jcollins-g): namespace lookups are not yet implemented with new lookup code.
2257+ expect (originalLookup (doAwesomeStuff, 'function1' ),
2258+ equals (MatchingLinkResult (function1)));
2259+
2260+ // A class in another library imported into this library.
2261+ // TODO(jcollins-g): namespace lookups are not yet implemented with new lookup code.
2262+ expect (originalLookup (doAwesomeStuff, 'Apple' ),
2263+ equals (MatchingLinkResult (Apple )));
2264+
2265+ // A top level constant in this library sharing the same name as a name in another library.
2266+ // TODO(jcollins-g): namespace lookups are not yet implemented with new lookup code.
2267+ expect (originalLookup (doAwesomeStuff, 'incorrectDocReference' ),
2268+ equals (MatchingLinkResult (incorrectDocReference)));
2269+
2270+ // A top level constant in another library.
2271+ // TODO(jcollins-g): namespace lookups are not yet implemented with new lookup code.
2272+ expect (originalLookup (doAwesomeStuff, 'incorrectDocReferenceFromEx' ),
2273+ equals (MatchingLinkResult (incorrectDocReferenceFromEx)));
2274+
2275+ // A prefixed constant in another library.
2276+ // TODO(jcollins-g): prefixed namespace lookups are not yet implemented with new lookup code.
2277+ expect (originalLookup (doAwesomeStuff, 'css.theOnlyThingInTheLibrary' ),
2278+ equals (MatchingLinkResult (theOnlyThingInTheLibrary)));
2279+
2280+ // A name that exists in this package but is not imported.
2281+ // TODO(jcollins-g): package-wide lookups are not yet implemented with the new lookup code.
2282+ expect (originalLookup (doAwesomeStuff, 'doesStuff' ),
2283+ equals (MatchingLinkResult (doesStuff)));
2284+
2285+ // A name of a class from an import of a library that exported that name.
2286+ expect (originalLookup (doAwesomeStuff, 'BaseClass' ),
2287+ equals (MatchingLinkResult (BaseClass )));
2288+
2289+ // A bracket operator within this class.
2290+ // TODO(jcollins-g): operator lookups not yet implemented with the new lookup code.
2291+ expect (originalLookup (doAwesomeStuff, 'operator []' ),
2292+ equals (MatchingLinkResult (bracketOperator)));
2293+
2294+ // A bracket operator in another class.
2295+ // TODO(jcollins-g): This has never worked...
2296+ //expect(bothLookup(doAwesomeStuff, 'SpecialList.operator []'), equals(MatchingLinkResult(bracketOperatorOtherClass)));
2297+
2298+ // Reference containing a type parameter.
2299+ expect (bothLookup (doAwesomeStuff, 'ExtraSpecialList<Object>' ),
2300+ equals (MatchingLinkResult (ExtraSpecialList )));
2301+
2302+ // Reference to an inherited member.
2303+ expect (
2304+ bothLookup (
2305+ doAwesomeStuff, 'ClassWithUnusualProperties.forInheriting' ),
2306+ equals (MatchingLinkResult (forInheriting)));
2307+
2308+ // Reference to an inherited member in another library via class name.
2309+ // TODO(jcollins-g): reference to non-imported symbols isn't implemented yet in new lookup.
2310+ expect (originalLookup (doAwesomeStuff, 'ExtendedBaseReexported.action' ),
2311+ equals (MatchingLinkResult (action)));
2312+ });
22562313 });
22572314
22582315 group ('Extension' , () {
0 commit comments