Skip to content

Commit 810b6a9

Browse files
committed
test(symbols): Track the symbols we export from the angular library
Closes dart-archive#398
1 parent 1571459 commit 810b6a9

File tree

1 file changed

+278
-0
lines changed

1 file changed

+278
-0
lines changed

test/angular_spec.dart

Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ library angular_spec;
22

33
import '_specs.dart';
44
import 'package:angular/utils.dart';
5+
import 'dart:mirrors';
56

67
main() {
78
describe('angular.dart unittests', () {
@@ -40,4 +41,281 @@ main() {
4041
}).toThrow('Unknown function type, expecting 0 to 5 args.');
4142
});
4243
});
44+
45+
describe('angular symbols', () {
46+
iit('should not export symbols that we do not know about', () {
47+
_getSymbolsFromLibrary(String libraryName) {
48+
var names = [];
49+
var SYMBOL_NAME = new RegExp('"(.*)"');
50+
_unwrapSymbol(sym) => SYMBOL_NAME.firstMatch(sym.toString()).group(1);
51+
52+
var seen = {};
53+
54+
// TODO(deboer): Add types once Dart VM 1.2 is deprecated.
55+
extractSymbols(/* LibraryMirror */ lib) {
56+
lib.declarations.forEach((symbol, _) {
57+
names.add([_unwrapSymbol(symbol), _unwrapSymbol(lib.qualifiedName)]);
58+
});
59+
60+
lib.libraryDependencies.forEach((/* LibraryDependencyMirror */ libDep) {
61+
LibraryMirror target = libDep.targetLibrary;
62+
if (!libDep.isExport) return;
63+
if (!seen.containsKey(target)) {
64+
seen[target] = true;
65+
extractSymbols(target);
66+
}
67+
});
68+
};
69+
70+
var lib = currentMirrorSystem().findLibrary(new Symbol(libraryName));
71+
72+
extractSymbols(lib);
73+
return names;
74+
}
75+
76+
var names;
77+
try { // Not impleneted in Dart VM 1.2
78+
names = _getSymbolsFromLibrary("angular");
79+
} on UnimplementedError catch (e) {
80+
return; // Not implemented, quietly skip.
81+
} catch (e) {
82+
print("Error: $e");
83+
return; // On VMes <1.2, quietly skip.
84+
}
85+
86+
var ALLOWED_PREFIXS = [
87+
"Ng",
88+
"ng",
89+
"Angular",
90+
"_"
91+
];
92+
93+
var ALLOWED_NAMES = [
94+
"di.FactoryFn",
95+
"di.CreationStrategy",
96+
"di.Injector",
97+
"di.TypeFactory",
98+
"di.Visibility",
99+
"di.NoProviderError",
100+
"di.CircularDependencyError",
101+
"di.ObjectFactory",
102+
"di.Module",
103+
"angular.core.AnnotationMap",
104+
"angular.core.LruCache",
105+
"angular.core.ScopeStats",
106+
"angular.core.ArrayFn",
107+
"angular.core.Interpolation",
108+
"angular.core.LongStackTrace",
109+
"angular.core.Cache",
110+
"angular.core.ExpressionVisitor",
111+
"angular.core.ScopeEvent",
112+
"angular.core.MapFn",
113+
"angular.core.EvalFunction1",
114+
"angular.core.MetadataExtractor",
115+
"angular.core.ExceptionHandler",
116+
"angular.core.ZoneOnTurn",
117+
"angular.core.ZoneOnError",
118+
"angular.core.ScopeDigestTTL",
119+
"angular.core.EvalFunction0",
120+
"angular.core.AnnotationsMap",
121+
"angular.core.RootScope",
122+
"angular.core.CacheStats",
123+
"angular.core.ScopeLocals",
124+
"angular.core.ScopeStreamSubscription",
125+
"angular.core.Interpolate",
126+
"angular.core.NOT_IMPLEMENTED",
127+
"angular.core.Scope",
128+
"angular.core.AttrFieldAnnotation",
129+
"angular.core.UnboundedCache",
130+
"angular.core.ScopeStream",
131+
"angular.core.FilterMap",
132+
"angular.core.AstParser",
133+
"angular.watch_group.FunctionApply",
134+
"angular.watch_group.WatchGroup",
135+
"angular.watch_group.ContextReferenceAST",
136+
"angular.watch_group.ConstantAST",
137+
"angular.watch_group.Watch",
138+
"angular.watch_group.ReactionFn",
139+
"angular.watch_group.ChangeLog",
140+
"angular.watch_group.FieldReadAST",
141+
"angular.watch_group.PureFunctionAST",
142+
"angular.watch_group.PrototypeMap",
143+
"angular.watch_group.CollectionAST",
144+
"angular.watch_group.MethodAST",
145+
"angular.watch_group.AST",
146+
"angular.watch_group.RootWatchGroup",
147+
"angular.core.dom.AnimationResult",
148+
"angular.core.dom.WalkingViewFactory",
149+
"angular.core.dom.ResponseError",
150+
"angular.core.dom.View",
151+
"angular.core.dom.ElementBinder",
152+
"angular.core.dom.NoOpAnimation",
153+
"angular.core.dom.AttributeChanged",
154+
"angular.core.dom.HttpBackend",
155+
"angular.core.dom.HttpDefaults",
156+
"angular.core.dom.TaggedElementBinder",
157+
"angular.core.dom.LocationWrapper",
158+
"angular.core.dom.Cookies",
159+
"angular.core.dom.ElementBinderTreeRef",
160+
"angular.core.dom.EventHandler",
161+
"angular.core.dom.Response",
162+
"angular.core.dom.HttpDefaultHeaders",
163+
"angular.core.dom.Animation",
164+
"angular.core.dom.ViewPort",
165+
"angular.core.dom.TemplateLoader",
166+
"angular.core.dom.RequestErrorInterceptor",
167+
"angular.core.dom.TaggedTextBinder",
168+
"angular.core.dom.Http",
169+
"angular.core.dom.BoundViewFactory",
170+
"angular.core.dom.ElementBinderFactory",
171+
"angular.core.dom.DirectiveMap",
172+
"angular.core.dom.BrowserCookies",
173+
"angular.core.dom.HttpInterceptor",
174+
"angular.core.dom.cloneElements",
175+
"angular.core.dom.EventFunction",
176+
"angular.core.dom.RequestInterceptor",
177+
"angular.core.dom.DefaultTransformDataHttpInterceptor",
178+
"angular.core.dom.HttpResponseConfig",
179+
"angular.core.dom.ElementProbe",
180+
"angular.core.dom.ApplyMapping",
181+
"angular.core.dom.ViewCache",
182+
"angular.core.dom.FieldMetadataExtractor",
183+
"angular.core.dom.Compiler",
184+
"angular.core.dom.HttpResponse",
185+
"angular.core.dom.UrlRewriter",
186+
"angular.core.dom.DirectiveRef",
187+
"angular.core.dom.HttpInterceptors",
188+
"angular.core.dom.forceNewDirectivesAndFilters",
189+
"angular.core.dom.DirectiveSelectorFactory",
190+
"angular.core.dom.ObserverChanged",
191+
"angular.core.dom.TaggingViewFactory",
192+
"angular.core.dom.NodeCursor",
193+
"angular.core.dom.TemplateCache",
194+
"angular.core.dom.ViewFactory",
195+
"angular.core.dom.NullTreeSanitizer",
196+
"angular.core.dom.NodeAttrs",
197+
"angular.core.dom.ElementBinderTree",
198+
"angular.core.dom.WalkingCompiler",
199+
"angular.core.dom.TaggingCompiler",
200+
"angular.core.dom.DirectiveSelector",
201+
"angular.core.parser.BoundGetter",
202+
"angular.core.parser.LocalsWrapper",
203+
"angular.core.parser.Getter",
204+
"angular.core.parser.Parser",
205+
"angular.core.parser.ParserBackend",
206+
"angular.core.parser.BoundSetter",
207+
"angular.core.parser.Setter",
208+
"angular.core.parser.syntax.LiteralObject",
209+
"angular.core.parser.syntax.CallMember",
210+
"angular.core.parser.syntax.Filter",
211+
"angular.core.parser.syntax.defaultFilterMap",
212+
"angular.core.parser.syntax.BoundExpression",
213+
"angular.core.parser.syntax.AccessMember",
214+
"angular.core.parser.syntax.Expression",
215+
"angular.core.parser.syntax.AccessScope",
216+
"angular.core.parser.syntax.Assign",
217+
"angular.core.parser.syntax.AccessKeyed",
218+
"angular.core.parser.syntax.CallScope",
219+
"angular.core.parser.syntax.CallFunction",
220+
"angular.core.parser.syntax.Conditional",
221+
"angular.core.parser.syntax.Binary",
222+
"angular.core.parser.syntax.Chain",
223+
"angular.core.parser.syntax.Prefix",
224+
"angular.core.parser.syntax.Literal",
225+
"angular.core.parser.syntax.LiteralString",
226+
"angular.core.parser.syntax.LiteralArray",
227+
"angular.core.parser.syntax.LiteralPrimitive",
228+
"angular.core.parser.syntax.Visitor",
229+
"angular.core.parser.dynamic_parser.DynamicExpression",
230+
"angular.core.parser.dynamic_parser.ClosureMap",
231+
"angular.core.parser.dynamic_parser.DynamicParser",
232+
"angular.core.parser.dynamic_parser.DynamicParserBackend",
233+
"angular.core.parser.static_parser.StaticParserFunctions",
234+
"angular.core.parser.static_parser.StaticExpression",
235+
"angular.core.parser.static_parser.StaticParser",
236+
"angular.core.parser.lexer.Scanner",
237+
"angular.core.parser.lexer.OPERATORS",
238+
"angular.core.parser.lexer.NumberToken",
239+
"angular.core.parser.lexer.Token",
240+
"angular.core.parser.lexer.IdentifierToken",
241+
"angular.core.parser.lexer.StringToken",
242+
"angular.core.parser.lexer.CharacterToken",
243+
"angular.core.parser.lexer.Lexer",
244+
"angular.core.parser.lexer.KEYWORDS",
245+
"angular.core.parser.lexer.OperatorToken",
246+
"angular.directive.ItemEval",
247+
"angular.directive.OptionValueDirective",
248+
"angular.directive.InputSelectDirective",
249+
"angular.directive.InputTextLikeDirective",
250+
"angular.directive.InputNumberLikeDirective",
251+
"angular.directive.ContentEditableDirective",
252+
"angular.directive.InputCheckboxDirective",
253+
"angular.directive.InputRadioDirective",
254+
"angular.filter.JsonFilter",
255+
"angular.filter.Equals",
256+
"angular.filter.Mapper",
257+
"angular.filter.FilterFilter",
258+
"angular.filter.NumberFilter",
259+
"angular.filter.DateFilter",
260+
"angular.filter.LowercaseFilter",
261+
"angular.filter.UppercaseFilter",
262+
"angular.filter.OrderByFilter",
263+
"angular.filter.CurrencyFilter",
264+
"angular.filter.LimitToFilter",
265+
"angular.filter.Predicate",
266+
"angular.routing.RouteInitializerFn",
267+
"angular.routing.RouteProvider",
268+
"angular.routing.RouteInitializer",
269+
"angular.routing.RouteViewFactory",
270+
"route.client.RouteHandle",
271+
"route.client.RouteEnterEvent",
272+
"route.client.RouteStartEvent",
273+
"route.client.Router",
274+
"route.client.RouteEvent",
275+
"route.client.childRoute",
276+
"route.client.RouteLeaveEventHandler",
277+
"route.client.Route",
278+
"route.client.RouteLeaveEvent",
279+
"route.client.RoutePreEnterEventHandler",
280+
"route.client.RoutePreEnterEvent",
281+
"route.client.Routable",
282+
"route.client.RouteEnterEventHandler",
283+
"url_matcher.UrlMatcher",
284+
"url_matcher.UrlMatch",
285+
"dirty_checking_change_detector.FieldGetter",
286+
"dirty_checking_change_detector.DirtyCheckingChangeDetector",
287+
"dirty_checking_change_detector.DirtyCheckingRecord",
288+
"dirty_checking_change_detector.ItemRecord",
289+
"dirty_checking_change_detector.KeyValueRecord",
290+
"dirty_checking_change_detector.DuplicateMap",
291+
"dirty_checking_change_detector.GetterCache",
292+
"dirty_checking_change_detector.DirtyCheckingChangeDetectorGroup"
293+
];
294+
295+
var _nameMap = {};
296+
ALLOWED_NAMES.forEach((x) => _nameMap[x] = true);
297+
298+
assertSymbolNameIsOk(List nameInfo) {
299+
String name = nameInfo[0];
300+
String libName = nameInfo[1];
301+
302+
if (ALLOWED_PREFIXS.any((prefix) => name.startsWith(prefix))) return;
303+
304+
var key = "$libName.$name";
305+
if (_nameMap.containsKey(key)) {
306+
_nameMap[key] = false;
307+
return;
308+
}
309+
310+
throw "Symbol $key is exported thru the angular library, but it shouldn't be";
311+
};
312+
313+
names.forEach(assertSymbolNameIsOk);
314+
315+
// If there are keys that no longer need to be in the ALLOWED_NAMES list, complain.
316+
_nameMap.forEach((k,v) {
317+
if (v) print("angular_spec.dart: Unused ALLOWED_NAMES key $k");
318+
});
319+
});
320+
});
43321
}

0 commit comments

Comments
 (0)