import test from 'ava' ; import { getGlobalType , getSuperClassInfo , isClass , isExtendOf , symbolString } from '../lib/utils' ; test ( 'getGlobalType, error.' , t => { t . throws ( ( ) => getGlobalType ( undefined ) ) ; t . throws ( ( ) => getGlobalType ( 123 ) ) ; t . throws ( ( ) => getGlobalType ( ( ) => { } ) ) ; } ) ; test ( 'getGlobalType, string.' , t => { t . true ( getGlobalType ( 'stringkey' ) === 'stringkey' ) ; } ) ; test ( 'getGlobalType, a class.' , t => { class A { } const typeA = getGlobalType ( A ) ; t . true ( typeA === 'A' ) ; function test ( ) { } t . true ( getGlobalType ( test ) === 'test' ) ; } ) ; test ( 'getSuperClassInfo.' , t => { class A { } class B extends A { } const typeAs = getSuperClassInfo ( A ) ; const typeBs = getSuperClassInfo ( B ) ; t . true ( typeAs . length === 0 ) ; t . true ( typeBs . length === 1 ) ; t . true ( typeBs [ 0 ] . type === getGlobalType ( A ) ) ; t . true ( typeBs [ 0 ] . class === A ) ; t . throws ( ( ) => getSuperClassInfo ( 123 as any ) ) ; t . throws ( ( ) => getSuperClassInfo ( '123' as any ) ) ; t . throws ( ( ) => getSuperClassInfo ( ( ) => { } ) ) ; } ) ; test ( 'isExtendOf' , t => { class A { } class B extends A { } class C { } t . true ( isExtendOf ( B , A ) ) ; t . false ( isExtendOf ( A , B ) ) ; t . false ( isExtendOf ( C , A ) ) ; t . throws ( ( ) => isExtendOf ( A , 1 as any ) ) ; t . throws ( ( ) => isExtendOf ( 1 as any , A ) ) ; } ) ; test ( 'symbolString' , t => { const sym = Symbol ( 'TestSymbol' ) ; t . deepEqual ( symbolString ( sym ) , 'Symbol(TestSymbol)' ) ; } ) ; test ( 'isClass' , t => { t . true ( ! isClass ( 1 ) ) ; t . true ( ! isClass ( '' ) ) ; t . true ( ! isClass ( undefined ) ) ; t . true ( ! isClass ( null ) ) ; t . true ( ! isClass ( new Date ( ) ) ) ; class B { } class C extends B { } t . true ( isClass ( B ) ) ; t . true ( isClass ( C ) ) ; t . true ( isClass ( class { } ) ) ; } ) ;