11import { ddescribe , describe , it , iit , xit , expect , beforeEach , afterEach } from 'angular2/test_lib' ;
2+ import { isBlank } from 'angular2/src/facade/lang' ;
23
34import { coalesce } from 'angular2/src/change_detection/coalesce' ;
45import { RecordType , ProtoRecord } from 'angular2/src/change_detection/proto_record' ;
6+ import { DirectiveIndex } from 'angular2/src/change_detection/directive_record' ;
57
68export function main ( ) {
7- function r ( funcOrValue , args , contextIndex , selfIndex , lastInBinding = false ,
8- mode = RecordType . PROPERTY , name = "name" ) {
9- return new ProtoRecord ( mode , name , funcOrValue , args , null , contextIndex , null , selfIndex , null ,
10- null , lastInBinding , false ) ;
9+ function r (
10+ funcOrValue , args , contextIndex , selfIndex ,
11+ { lastInBinding, mode, name,
12+ directiveIndex} : { lastInBinding ?: any , mode ?: any , name ?: any , directiveIndex ?: any } = { } ) {
13+ if ( isBlank ( lastInBinding ) ) lastInBinding = false ;
14+ if ( isBlank ( mode ) ) mode = RecordType . PROPERTY ;
15+ if ( isBlank ( name ) ) name = "name" ;
16+ if ( isBlank ( directiveIndex ) ) directiveIndex = null ;
17+ return new ProtoRecord ( mode , name , funcOrValue , args , null , contextIndex , directiveIndex ,
18+ selfIndex , null , null , lastInBinding , false ) ;
1119 }
1220
1321 describe ( "change detection - coalesce" , ( ) => {
@@ -44,18 +52,18 @@ export function main() {
4452 [ r ( "user1" , [ ] , 0 , 1 ) , r ( "user2" , [ ] , 0 , 2 ) , r ( "hi" , [ 1 ] , 0 , 3 ) , r ( "hi" , [ 2 ] , 0 , 4 ) ] ) ;
4553 } ) ;
4654
47- it ( "should replace duplicate terminal records with" + " self records", ( ) => {
48-
49- var rs = coalesce ( [ r ( "user" , [ ] , 0 , 1 , true ) , r ( "user" , [ ] , 0 , 2 , true ) ] ) ;
55+ it ( "should replace duplicate terminal records with self records" , ( ) => {
56+ var rs = coalesce (
57+ [ r ( "user" , [ ] , 0 , 1 , { lastInBinding : true } ) , r ( "user" , [ ] , 0 , 2 , { lastInBinding : true } ) ] ) ;
5058
5159 expect ( rs [ 1 ] ) . toEqual ( new ProtoRecord ( RecordType . SELF , "self" , null , [ ] , null , 1 , null , 2 ,
5260 null , null , true , false ) ) ;
5361 } ) ;
5462
5563 it ( "should not coalesce directive lifecycle records" , ( ) => {
5664 var rs = coalesce ( [
57- r ( "onCheck" , [ ] , 0 , 1 , true , RecordType . DIRECTIVE_LIFECYCLE ) ,
58- r ( "onCheck" , [ ] , 0 , 1 , true , RecordType . DIRECTIVE_LIFECYCLE )
65+ r ( "onCheck" , [ ] , 0 , 1 , { mode : RecordType . DIRECTIVE_LIFECYCLE } ) ,
66+ r ( "onCheck" , [ ] , 0 , 1 , { mode : RecordType . DIRECTIVE_LIFECYCLE } )
5967 ] ) ;
6068
6169 expect ( rs . length ) . toEqual ( 2 ) ;
@@ -64,10 +72,22 @@ export function main() {
6472 it ( "should not coalesce protos with different names but same value" , ( ) => {
6573 var nullFunc = ( ) => { } ;
6674 var rs = coalesce ( [
67- r ( nullFunc , [ ] , 0 , 1 , false , RecordType . PROPERTY , "foo" ) ,
68- r ( nullFunc , [ ] , 0 , 1 , false , RecordType . PROPERTY , "bar" ) ,
75+ r ( nullFunc , [ ] , 0 , 1 , { name : "foo" } ) ,
76+ r ( nullFunc , [ ] , 0 , 1 , { name : "bar" } ) ,
6977 ] ) ;
7078 expect ( rs . length ) . toEqual ( 2 ) ;
7179 } ) ;
80+
81+ it ( "should not coalesce protos with the same context index but different directive indices" ,
82+ ( ) => {
83+ var nullFunc = ( ) => { } ;
84+ var rs = coalesce ( [
85+ r ( nullFunc , [ ] , 0 , 1 , { directiveIndex : new DirectiveIndex ( 0 , 0 ) } ) ,
86+ r ( nullFunc , [ ] , 0 , 1 , { directiveIndex : new DirectiveIndex ( 0 , 1 ) } ) ,
87+ r ( nullFunc , [ ] , 0 , 1 , { directiveIndex : new DirectiveIndex ( 1 , 0 ) } ) ,
88+ r ( nullFunc , [ ] , 0 , 1 , { directiveIndex : null } ) ,
89+ ] ) ;
90+ expect ( rs . length ) . toEqual ( 4 ) ;
91+ } ) ;
7292 } ) ;
7393}
0 commit comments