import { describe , it } from 'mocha' ; import { dedent } from '../../__testUtils__/dedent' ; import { genFuzzStrings } from '../../__testUtils__/genFuzzStrings' ; import { inspectStr } from '../../__testUtils__/inspectStr' ; import { invariant } from '../../jsutils/invariant' ; import { Lexer } from '../../language/lexer' ; import { Source } from '../../language/source' ; import { stripIgnoredCharacters } from '../stripIgnoredCharacters' ; function lexValue ( str ) { const lexer = new Lexer ( new Source ( str ) ) ; const value = lexer . advance ( ) . value ; invariant ( lexer . advance ( ) . kind === '<EOF>' , 'Expected EOF' ) ; return value ; } describe ( 'stripIgnoredCharacters' , ( ) => { it ( 'strips ignored characters inside random block strings' , ( ) => { for ( const fuzzStr of genFuzzStrings ( { allowedChars : [ '\n' , '\t' , ' ' , '"' , 'a' , '\\' ] , maxLength : 7 , } ) ) { const testStr = '"""' + fuzzStr + '"""' ; let testValue ; try { testValue = lexValue ( testStr ) ; } catch ( e ) { continue ; } const strippedValue = lexValue ( stripIgnoredCharacters ( testStr ) ) ; invariant ( testValue === strippedValue , dedent `
          Expected lexValue(stripIgnoredCharacters(${ inspectStr ( testStr ) }))
            to equal ${ inspectStr ( testValue ) }
            but got  ${ inspectStr ( strippedValue ) }
        ` ) ; } } ) . timeout ( 20000 ) ; } ) ;