import { Actual } from "../Actual" ; import { Expected } from "../Expected" ; import { assert } from "../assert" ; export function toIncludeComparison < 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 ) ; if ( isNullable < T > ( ) ) { Expected . report ( "null" , 1 ) ; assert ( i32 ( actual !== null ) , "" ) ; } Expected . report ( "Included" , negated ) ; let includes = false ; if ( actual instanceof Set ) { includes = actual . has ( expected ) ; } else { if ( isNullable ( actual ) ) { includes = includesCheck ( actual ! , expected ) ; } else { includes = includesCheck ( actual , expected ) ; } } Actual . report ( includes ? "Included" : "Not Included" ) ; assert ( negated ^ i32 ( includes ) , message ) ; } function includesCheck < T , U > ( actual , expected ) { if ( ! isDefined ( actual . length ) ) ERROR ( "Can only call toInclude on array-like objects or Sets." ) ; if ( ! isDefined ( unchecked ( actual [ 0 ] ) ) ) ERROR ( "Can only call toInclude on array-like objects or Sets." ) ; let length = < indexof < T > > actual . length ; if ( isDefined ( unchecked ( actual [ 0 ] ) ) ) { for ( let i = < indexof < T > > 0 ; i < length ; i ++ ) { if ( unchecked ( actual [ i ] ) === expected ) { return true ; } } } return false ; }