import '../monaco.contribution' ; import { loadLanguage } from '../_.contribution' ; import * as test from 'tape' ; import { editor } from '../fillers/monaco-editor-core' ; export interface IRelaxedToken { startIndex : number ; type : string ; } export interface ITestItem { line : string ; tokens : IRelaxedToken [ ] ; } export function testTokenization ( _language , tests ) { let languages ; if ( typeof _language === 'string' ) { languages = [ _language ] ; } else { languages = _language ; } let mainLanguage = languages [ 0 ] ; test ( mainLanguage + ' tokenization' , ( t ) => { Promise . all ( languages . map ( ( l ) => loadLanguage ( l ) ) ) . then ( ( ) => { setTimeout ( ( ) => { runTests ( t , mainLanguage , tests ) ; t . end ( ) ; } ) ; } ) . then ( null , ( ) => t . end ( ) ) ; } ) ; } function runTests ( t , languageId , tests ) { tests . forEach ( ( test ) => runTest ( t , languageId , test ) ) ; } function runTest ( t , languageId , test ) { let text = test . map ( ( t ) => t . line ) . join ( '\n' ) ; let actualTokens = editor . tokenize ( text , languageId ) ; let actual = actualTokens . map ( ( lineTokens , index ) => { return { line : test [ index ] . line , tokens : lineTokens . map ( ( t ) => { return { startIndex : t . offset , type : t . type } ; } ) } ; } ) ; t . deepEqual ( actual , test ) ; }