import { Actual } from "../Actual" ; import { Expected } from "../Expected" ; import { assert } from "../assert" ; export function toIncludeEqualComparison < T , U > ( actual , expected , negated , message ) { if ( ! isDefined ( actual [ 0 ] ) ) ERROR ( "Cannot call toIncludeEquals on actual value of type T where T does not have an index signature." ) ; Actual . report ( actual ) ; Expected . report ( "null" , 1 ) ; assert ( i32 ( changetype < usize > ( actual ) != 0 ) , "" ) ; Expected . report ( "Included" , negated ) ; let includes = false ; if ( actual instanceof Set ) { if ( actual . has ( expected ) ) { includes = true ; } else { let values = actual . values ( ) ; let length = values . length ; for ( let i = 0 ; i < length ; i ++ ) { let key = unchecked ( values [ i ] ) ; if ( Reflect . equals ( key , expected ) === Reflect . SUCCESSFUL_MATCH ) { includes = true ; break ; } } } } else { if ( ! isDefined ( actual . length ) ) ERROR ( "Can only call toIncludeEquals on array-like objects or Sets." ) ; if ( isNullable < T > ( ) ) { let actualNotNull = actual ! ; if ( isDefined ( unchecked ( actualNotNull [ 0 ] ) ) ) { let length = < indexof < T > > actualNotNull . length ; for ( let i = < indexof < T > > 0 ; i < length ; i ++ ) { if ( Reflect . equals ( unchecked ( actualNotNull [ i ] ) , expected ) == Reflect . SUCCESSFUL_MATCH ) { includes = true ; break ; } } } } else { if ( isDefined ( unchecked ( actual [ 0 ] ) ) ) { let length = < indexof < T > > actual . length ; for ( let i = < indexof < T > > 0 ; i < length ; i ++ ) { if ( Reflect . equals ( unchecked ( actual [ i ] ) , expected ) == Reflect . SUCCESSFUL_MATCH ) { includes = true ; break ; } } } } } Actual . report ( includes ? "Included" : "Not Included" ) ; assert ( negated ^ i32 ( includes ) , message ) ; }