@@ -1959,69 +1959,23 @@ namespace FourSlash {
19591959 }
19601960 }
19611961
1962- public verifyNavigationBarCount ( expected : number ) {
1962+ public verifyNavigationBar ( json : any ) {
19631963 const items = this . languageService . getNavigationBarItems ( this . activeFile . fileName ) ;
1964- const actual = this . getNavigationBarItemsCount ( items ) ;
1965-
1966- if ( expected !== actual ) {
1967- this . raiseError ( `verifyNavigationBarCount failed - found: ${ actual } navigation items, expected: ${ expected } .` ) ;
1968- }
1969- }
1970-
1971- private getNavigationBarItemsCount ( items : ts . NavigationBarItem [ ] ) {
1972- let result = 0 ;
1973- if ( items ) {
1974- for ( let i = 0 , n = items . length ; i < n ; i ++ ) {
1975- result ++ ;
1976- result += this . getNavigationBarItemsCount ( items [ i ] . childItems ) ;
1977- }
1978- }
1979-
1980- return result ;
1981- }
1982-
1983- public verifyNavigationBarContains ( name : string , kind : string , fileName ?: string , parentName ?: string , isAdditionalSpan ?: boolean , markerPosition ?: number ) {
1984- fileName = fileName || this . activeFile . fileName ;
1985- const items = this . languageService . getNavigationBarItems ( fileName ) ;
1986-
1987- if ( ! items || items . length === 0 ) {
1988- this . raiseError ( "verifyNavigationBarContains failed - found 0 navigation items, expected at least one." ) ;
1989- }
1990-
1991- if ( this . navigationBarItemsContains ( items , name , kind , parentName ) ) {
1992- return ;
1993- }
1994-
1995- const missingItem = { name, kind, parentName } ;
1996- this . raiseError ( `verifyNavigationBarContains failed - could not find the item: ${ JSON . stringify ( missingItem , undefined , 2 ) } in the returned list: (${ JSON . stringify ( items , undefined , 2 ) } )` ) ;
1997- }
1998-
1999- private navigationBarItemsContains ( items : ts . NavigationBarItem [ ] , name : string , kind : string , parentName ?: string ) {
2000- function recur ( items : ts . NavigationBarItem [ ] , curParentName : string ) {
2001- for ( let i = 0 ; i < items . length ; i ++ ) {
2002- const item = items [ i ] ;
2003- if ( item && item . text === name && item . kind === kind && ( ! parentName || curParentName === parentName ) ) {
2004- return true ;
2005- }
2006- if ( recur ( item . childItems , item . text ) ) {
2007- return true ;
2008- }
2009- }
2010- return false ;
1964+ if ( JSON . stringify ( items , replacer ) !== JSON . stringify ( json ) ) {
1965+ this . raiseError ( `verifyNavigationBar failed - expected: ${ JSON . stringify ( json , undefined , 2 ) } , got: ${ JSON . stringify ( items , replacer , 2 ) } ` ) ;
20111966 }
2012- return recur ( items , "" ) ;
2013- }
2014-
2015- public verifyNavigationBarChildItem ( parent : string , name : string , kind : string ) {
2016- const items = this . languageService . getNavigationBarItems ( this . activeFile . fileName ) ;
20171967
2018- for ( let i = 0 ; i < items . length ; i ++ ) {
2019- const item = items [ i ] ;
2020- if ( item . text === parent ) {
2021- if ( this . navigationBarItemsContains ( item . childItems , name , kind ) )
2022- return ;
2023- const missingItem = { name, kind } ;
2024- this . raiseError ( `verifyNavigationBarChildItem failed - could not find the item: ${ JSON . stringify ( missingItem ) } in the children list: (${ JSON . stringify ( item . childItems , undefined , 2 ) } )` ) ;
1968+ // Make the data easier to read.
1969+ function replacer ( key : string , value : any ) {
1970+ switch ( key ) {
1971+ case "spans" :
1972+ // We won't ever check this.
1973+ return undefined ;
1974+ case "childItems" :
1975+ return value . length === 0 ? undefined : value ;
1976+ default :
1977+ // Omit falsy values, those are presumed to be the default.
1978+ return value || undefined ;
20251979 }
20261980 }
20271981 }
@@ -3042,23 +2996,8 @@ namespace FourSlashInterface {
30422996 this . DocCommentTemplate ( /*expectedText*/ undefined , /*expectedOffset*/ undefined , /*empty*/ true ) ;
30432997 }
30442998
3045- public navigationBarCount ( count : number ) {
3046- this . state . verifyNavigationBarCount ( count ) ;
3047- }
3048-
3049- // TODO: figure out what to do with the unused arguments.
3050- public navigationBarContains (
3051- name : string ,
3052- kind : string ,
3053- fileName ?: string ,
3054- parentName ?: string ,
3055- isAdditionalSpan ?: boolean ,
3056- markerPosition ?: number ) {
3057- this . state . verifyNavigationBarContains ( name , kind , fileName , parentName , isAdditionalSpan , markerPosition ) ;
3058- }
3059-
3060- public navigationBarChildItem ( parent : string , name : string , kind : string ) {
3061- this . state . verifyNavigationBarChildItem ( parent , name , kind ) ;
2999+ public navigationBar ( json : any ) {
3000+ this . state . verifyNavigationBar ( json ) ;
30623001 }
30633002
30643003 public navigationItemsListCount ( count : number , searchValue : string , matchKind ?: string ) {
0 commit comments