@@ -1959,70 +1959,42 @@ namespace FourSlash {
19591959 }
19601960 }
19611961
1962- public verifyNavigationBarCount ( expected : number ) {
1963- const items = this . languageService . getNavigationBarItems ( this . activeFile . fileName ) ;
1964- const actual = this . getNavigationBarItemsCount ( items [ 0 ] ) ;
1965-
1966- if ( expected !== actual ) {
1967- this . raiseError ( `verifyNavigationBarCount failed - found: ${ actual } navigation items, expected: ${ expected } .` ) ;
1968- }
1969- }
1970-
1971- private getNavigationBarItemsCount ( root : ts . NavigationBarItem ) {
1972- ts . Debug . assert ( root . kind === ts . ScriptElementKind . moduleElement ) ;
1973- function recur ( item : ts . NavigationBarItem ) {
1974- let count = 1 ;
1975- for ( const child of item . childItems )
1976- count += recur ( child ) ;
1977- return count ;
1978- }
1979- return recur ( root ) ;
1980- }
1981-
1982- public verifyNavigationBarContains ( name : string , kind : string , fileName ?: string , parentName ?: string , isAdditionalSpan ?: boolean , markerPosition ?: number ) {
1983- fileName = fileName || this . activeFile . fileName ;
1984- const items = this . languageService . getNavigationBarItems ( fileName ) ;
1985-
1986- if ( ! items || items . length === 0 ) {
1987- this . raiseError ( "verifyNavigationBarContains failed - found 0 navigation items, expected at least one." ) ;
1988- }
1989-
1990- if ( this . navigationBarItemsContains ( items , name , kind , parentName ) ) {
1991- return ;
1992- }
1993-
1994- const missingItem = { name, kind, parentName } ;
1995- this . raiseError ( `verifyNavigationBarContains failed - could not find the item: ${ JSON . stringify ( missingItem , undefined , 2 ) } in the returned list: (${ JSON . stringify ( items , undefined , 2 ) } )` ) ;
1996- }
1997-
1998- private navigationBarItemsContains ( items : ts . NavigationBarItem [ ] , name : string , kind : string , parentName ?: string ) {
1999- function recur ( items : ts . NavigationBarItem [ ] , curParentName : string ) {
2000- for ( let i = 0 ; i < items . length ; i ++ ) {
2001- const item = items [ i ] ;
2002- if ( item && item . text === name && item . kind === kind && ( ! parentName || curParentName === parentName ) ) {
2003- return true ;
2004- }
2005- if ( recur ( item . childItems , item . text ) ) {
2006- return true ;
2007- }
2008- }
2009- return false ;
2010- }
2011- return recur ( items , "" ) ;
2012- }
2013-
2014- public verifyNavigationBarChildItem ( parent : string , name : string , kind : string ) {
2015- const items = this . languageService . getNavigationBarItems ( this . activeFile . fileName ) ;
2016-
2017- for ( let i = 0 ; i < items . length ; i ++ ) {
2018- const item = items [ i ] ;
2019- if ( item . text === parent ) {
2020- if ( this . navigationBarItemsContains ( item . childItems , name , kind ) )
2021- return ;
2022- const missingItem = { name, kind } ;
2023- this . raiseError ( `verifyNavigationBarChildItem failed - could not find the item: ${ JSON . stringify ( missingItem ) } in the children list: (${ JSON . stringify ( item . childItems , undefined , 2 ) } )` ) ;
2024- }
2025- }
1962+ public verifyNavigationBar ( json : any ) {
1963+ let items = this . languageService . getNavigationBarItems ( this . activeFile . fileName ) ;
1964+ items = this . simplifyNavigationBar ( items ) ;
1965+ if ( JSON . stringify ( items ) !== JSON . stringify ( json ) ) {
1966+ this . raiseError ( `verifyNavigationBar failed - expected: ${ JSON . stringify ( json , undefined , 2 ) } , got: ${ JSON . stringify ( items , undefined , 2 ) } ` )
1967+ }
1968+ }
1969+
1970+ // Remove any properties that tend to all have the same value so that test data is easier to read.
1971+ private simplifyNavigationBar ( items : ts . NavigationBarItem [ ] ) : any {
1972+ return items . map ( item => {
1973+ item = ts . clone ( item ) ;
1974+ if ( item . kindModifiers === "" )
1975+ delete item . kindModifiers ;
1976+ delete item . spans ;
1977+ item . childItems = item . childItems . map ( child => {
1978+ child = ts . clone ( child ) ;
1979+ ts . Debug . assert ( child . childItems . length === 0 ) ;
1980+ ts . Debug . assert ( child . indent === 0 ) ;
1981+ ts . Debug . assert ( child . bolded === false ) ;
1982+ ts . Debug . assert ( child . grayed === false ) ;
1983+ delete child . childItems ;
1984+ delete child . indent ;
1985+ delete child . bolded ;
1986+ delete child . grayed ;
1987+ delete child . spans ;
1988+ if ( child . kindModifiers === "" )
1989+ delete child . kindModifiers ;
1990+ return child ;
1991+ } ) ;
1992+ if ( item . bolded === false )
1993+ delete item . bolded ;
1994+ if ( item . grayed === false )
1995+ delete item . grayed ;
1996+ return item ;
1997+ } )
20261998 }
20271999
20282000 public printNavigationItems ( searchValue : string ) {
@@ -3041,23 +3013,8 @@ namespace FourSlashInterface {
30413013 this . DocCommentTemplate ( /*expectedText*/ undefined , /*expectedOffset*/ undefined , /*empty*/ true ) ;
30423014 }
30433015
3044- public navigationBarCount ( count : number ) {
3045- this . state . verifyNavigationBarCount ( count ) ;
3046- }
3047-
3048- // TODO: figure out what to do with the unused arguments.
3049- public navigationBarContains (
3050- name : string ,
3051- kind : string ,
3052- fileName ?: string ,
3053- parentName ?: string ,
3054- isAdditionalSpan ?: boolean ,
3055- markerPosition ?: number ) {
3056- this . state . verifyNavigationBarContains ( name , kind , fileName , parentName , isAdditionalSpan , markerPosition ) ;
3057- }
3058-
3059- public navigationBarChildItem ( parent : string , name : string , kind : string ) {
3060- this . state . verifyNavigationBarChildItem ( parent , name , kind ) ;
3016+ public navigationBar ( json : any ) {
3017+ this . state . verifyNavigationBar ( json ) ;
30613018 }
30623019
30633020 public navigationItemsListCount ( count : number , searchValue : string , matchKind ?: string ) {
0 commit comments