/**
 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 */ import { EXPECTED_COLOR , INVERTED_COLOR , RECEIVED_COLOR , printReceived , stringify , } from './matcher-utils' ; const printSubstring = ( val ) : string => val . replace ( /"|\\/g , '\\$&' ) ; export const printReceivedStringContainExpectedSubstring = ( received , start , length ) : string => RECEIVED_COLOR ( '"' + printSubstring ( received . slice ( 0 , start ) ) + INVERTED_COLOR ( printSubstring ( received . slice ( start , start + length ) ) ) + printSubstring ( received . slice ( start + length ) ) + '"' ) ; export const printReceivedStringContainExpectedResult = ( received , result ) : string => result === null ? printReceived ( received ) : printReceivedStringContainExpectedSubstring ( received , result . index , result [ 0 ] . length ) ; export const printReceivedArrayContainExpectedItem = ( received , index ) : string => RECEIVED_COLOR ( '[' + received . map ( ( item , i ) => { const stringified = stringify ( item ) ; return i === index ? INVERTED_COLOR ( stringified ) : stringified ; } ) . join ( ', ' ) + ']' ) ; export const printCloseTo = ( receivedDiff , expectedDiff , precision , isNot ) : string => { const receivedDiffString = stringify ( receivedDiff ) ; const expectedDiffString = receivedDiffString . includes ( 'e' ) ? expectedDiff . toExponential ( 0 ) : 0 <= precision && precision < 20 ? expectedDiff . toFixed ( precision + 1 ) : stringify ( expectedDiff ) ; return ( `Expected precision:  ${ isNot ? '    ' : '' }  ${ stringify ( precision ) }\n` + `Expected difference: ${ isNot ? 'not ' : '' }< ${ EXPECTED_COLOR ( expectedDiffString ) }\n` + `Received difference: ${ isNot ? '    ' : '' }  ${ RECEIVED_COLOR ( receivedDiffString ) }` ) ; } ; export const printExpectedConstructorName = ( label , expected ) : string => printConstructorName ( label , expected , false , true ) + '\n' ; export const printExpectedConstructorNameNot = ( label , expected ) : string => printConstructorName ( label , expected , true , true ) + '\n' ; export const printReceivedConstructorName = ( label , received ) : string => printConstructorName ( label , received , false , false ) + '\n' ; export const printReceivedConstructorNameNot = ( label , received , expected ) : string => typeof expected . name === 'string' && expected . name . length !== 0 && typeof received . name === 'string' && received . name . length !== 0 ? printConstructorName ( label , received , true , false ) + ` ${ Object . getPrototypeOf ( received ) === expected ? 'extends' : 'extends … extends' } ${ EXPECTED_COLOR ( expected . name ) }` + '\n' : printConstructorName ( label , received , false , false ) + '\n' ; const printConstructorName = ( label , constructor , isNot , isExpected ) : string => typeof constructor . name !== 'string' ? `${ label } name is not a string` : constructor . name . length === 0 ? `${ label } name is an empty string` : `${ label }: ${ ! isNot ? '' : isExpected ? 'not ' : '    ' }${ isExpected ? EXPECTED_COLOR ( constructor . name ) : RECEIVED_COLOR ( constructor . name ) }` ;