import * as vscode from "vscode" ; import { assert , expect } from "chai" ; import * as TestUtils from "./testUtils" ; import { Commands } from "./testUtils" ; export interface ExpectedDocumentSymbol { readonly name : string ; readonly kind : vscode . SymbolKind ; readonly children ? : ExpectedDocumentSymbol [ ] ; } export async function testDocumentSymbols ( docUri , expectedSymbols ) { const documentSymbols = await documentSymbolsBase ( docUri ) ; if ( documentSymbols === undefined ) { assert . fail ( "documentSymbols undefined" ) ; } const actualSymbols = documentSymbolArrayToExpectedSymbols ( documentSymbols ) ; expect ( actualSymbols ) . deep . equals ( expectedSymbols , "Expected document symbols to match." ) ; } async function documentSymbolsBase ( docUri ) { await TestUtils . activate ( docUri ) ; return vscode . commands . executeCommand ( Commands . DocumentSymbols , docUri ) ; } function documentSymbolArrayToExpectedSymbols ( documentSymbols ) { const expectedSymbols = [ ] ; documentSymbols . forEach ( ( element ) => { let children ; if ( element . children && element . children . length > 0 ) { children = documentSymbolArrayToExpectedSymbols ( element . children ) ; expectedSymbols . push ( { name : element . name , kind : element . kind , children } ) ; } else { expectedSymbols . push ( { name : element . name , kind : element . kind } ) ; } } ) ; return expectedSymbols ; }