import assert from 'assert' ; import * as debug from '../common/debug' ; test ( 'DebugAssertTrue' , ( ) => { assert . doesNotThrow ( ( ) => { debug . assert ( true , "doesn't throw" ) ; } ) ; } ) ; test ( 'DebugAssertFalse' , ( ) => { assert . throws ( ( ) => { debug . assert ( false , 'should throw' ) ; } , ( err ) => err instanceof Error , 'unexpected' ) ; } ) ; test ( 'DebugAssertDetailInfo' , ( ) => { const detailInfo = 'Detail Info' ; assert . throws ( ( ) => { debug . assert ( false , 'should throw' , ( ) => detailInfo ) ; } , ( err ) => err instanceof Error && err . message . includes ( detailInfo ) , 'unexpected' ) ; } ) ; test ( 'DebugAssertStackTrace' , ( ) => { assert . throws ( ( ) => { debug . assert ( false , 'should throw' , undefined , assert . throws ) ; } , ( err ) => err instanceof Error && ! err . message . includes ( 'assert.throws' ) , 'unexpected' ) ; } ) ; test ( 'DebugAssertUndefined' , ( ) => { const unused = undefined ; assert . throws ( ( ) => debug . assertDefined ( unused ) , ( err ) => err instanceof Error , 'unexpected' ) ; } ) ; test ( 'DebugAssertDefined' , ( ) => { const unused = 1 ; assert . doesNotThrow ( ( ) => debug . assertDefined ( unused ) ) ; } ) ; test ( 'DebugAssertEachUndefined' , ( ) => { type T = number | undefined ; const unused = [ 1 , 2 , 3 , undefined ] ; assert . throws ( ( ) => debug . assertEachDefined ( unused ) , ( err ) => err instanceof Error , 'unexpected' ) ; } ) ; test ( 'DebugAssertEachDefined' , ( ) => { const unused = [ 1 , 2 , 3 ] ; assert . doesNotThrow ( ( ) => debug . assertEachDefined ( unused ) ) ; } ) ; test ( 'DebugAssertNever' , ( ) => { const enum MyEnum { A , B , C } const unused = 5 as MyEnum ; assert . throws ( ( ) => { switch ( unused ) { case MyEnum . A : case MyEnum . B : case MyEnum . C : break ; default : debug . assertNever ( unused ) ; } } , ( err ) => err instanceof Error , 'unexpected' ) ; } ) ; test ( 'DebugGetFunctionName' , ( ) => { assert ( debug . getFunctionName ( assert . throws ) === 'throws' ) ; } ) ; test ( 'DebugFormatEnum' , ( ) => { enum MyEnum { A , B , C } assert ( debug . formatEnum ( MyEnum . A , MyEnum , false ) === 'A' ) ; } ) ;