| 
									
										
										
										
											2015-04-09 23:17:05 -07:00
										 |  |  | /// This file contains tests that make sense only in Dart world, such as
 | 
					
						
							|  |  |  | /// verifying that things are valid constants.
 | 
					
						
							| 
									
										
										
										
											2015-04-15 18:17:22 -07:00
										 |  |  | library angular2.test.di.binding_dart_spec; | 
					
						
							| 
									
										
										
										
											2015-04-09 23:17:05 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | import 'dart:mirrors'; | 
					
						
							|  |  |  | import 'package:angular2/test_lib.dart'; | 
					
						
							|  |  |  | import 'package:angular2/di.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | main() { | 
					
						
							|  |  |  |   describe('Binding', () { | 
					
						
							|  |  |  |     it('can create constant from token', () { | 
					
						
							|  |  |  |       expect(const Binding(Foo).token).toBe(Foo); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('can create constant from class', () { | 
					
						
							|  |  |  |       expect(const Binding(Foo, toClass: Bar).toClass).toBe(Bar); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('can create constant from value', () { | 
					
						
							|  |  |  |       expect(const Binding(Foo, toValue: 5).toValue).toBe(5); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('can create constant from alias', () { | 
					
						
							|  |  |  |       expect(const Binding(Foo, toAlias: Bar).toAlias).toBe(Bar); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('can create constant from factory', () { | 
					
						
							|  |  |  |       expect(const Binding(Foo, toFactory: fn).toFactory).toBe(fn); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('can be used in annotation', () { | 
					
						
							|  |  |  |       ClassMirror mirror = reflectType(Annotated); | 
					
						
							|  |  |  |       var bindings = mirror.metadata[0].reflectee.bindings; | 
					
						
							| 
									
										
										
										
											2015-06-26 15:59:18 -07:00
										 |  |  |       expect(bindings.length).toBe(5); | 
					
						
							| 
									
										
										
										
											2015-04-09 23:17:05 -07:00
										 |  |  |       bindings.forEach((b) { | 
					
						
							|  |  |  |         expect(b).toBeA(Binding); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Foo {} | 
					
						
							| 
									
										
										
										
											2015-08-04 12:05:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-09 23:17:05 -07:00
										 |  |  | class Bar extends Foo {} | 
					
						
							| 
									
										
										
										
											2015-08-04 12:05:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-09 23:17:05 -07:00
										 |  |  | fn() => null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Annotation { | 
					
						
							|  |  |  |   final List bindings; | 
					
						
							|  |  |  |   const Annotation(this.bindings); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Annotation(const [ | 
					
						
							|  |  |  |   const Binding(Foo), | 
					
						
							|  |  |  |   const Binding(Foo, toClass: Bar), | 
					
						
							|  |  |  |   const Binding(Foo, toValue: 5), | 
					
						
							|  |  |  |   const Binding(Foo, toAlias: Bar), | 
					
						
							| 
									
										
										
										
											2015-06-26 15:59:18 -07:00
										 |  |  |   const Binding(Foo, toFactory: fn) | 
					
						
							| 
									
										
										
										
											2015-04-09 23:17:05 -07:00
										 |  |  | ]) | 
					
						
							|  |  |  | class Annotated {} |