@@ -728,6 +728,69 @@ describe("GhostInlineCompletionProvider", () => {
728728 } )
729729 } )
730730
731+ describe ( "cachedSuggestionAvailable" , ( ) => {
732+ it ( "should return true when prefix and suffix match" , ( ) => {
733+ const suggestions = new GhostSuggestionsState ( )
734+ suggestions . setFillInAtCursor ( {
735+ text : "console.log('cached');" ,
736+ prefix : "const x = 1" ,
737+ suffix : "\nconst y = 2" ,
738+ } )
739+ provider . updateSuggestions ( suggestions )
740+
741+ const result = provider . cachedSuggestionAvailable ( "const x = 1" , "\nconst y = 2" )
742+ expect ( result ) . toBe ( true )
743+ } )
744+
745+ it ( "should return false when no matching suggestion exists" , ( ) => {
746+ const suggestions = new GhostSuggestionsState ( )
747+ suggestions . setFillInAtCursor ( {
748+ text : "console.log('test');" ,
749+ prefix : "const x = 1" ,
750+ suffix : "\nconst y = 2" ,
751+ } )
752+ provider . updateSuggestions ( suggestions )
753+
754+ const result = provider . cachedSuggestionAvailable ( "different prefix" , "different suffix" )
755+ expect ( result ) . toBe ( false )
756+ } )
757+
758+ it ( "should return true for partial typing" , ( ) => {
759+ const suggestions = new GhostSuggestionsState ( )
760+ suggestions . setFillInAtCursor ( {
761+ text : "console.log('test');" ,
762+ prefix : "const x = 1" ,
763+ suffix : "\nconst y = 2" ,
764+ } )
765+ provider . updateSuggestions ( suggestions )
766+
767+ // User typed "cons" after the prefix
768+ const result = provider . cachedSuggestionAvailable ( "const x = 1cons" , "\nconst y = 2" )
769+ expect ( result ) . toBe ( true )
770+ } )
771+
772+ it ( "should return true when most recent matching suggestion exists" , ( ) => {
773+ const suggestions1 = new GhostSuggestionsState ( )
774+ suggestions1 . setFillInAtCursor ( {
775+ text : "first" ,
776+ prefix : "const x = 1" ,
777+ suffix : "\nconst y = 2" ,
778+ } )
779+ provider . updateSuggestions ( suggestions1 )
780+
781+ const suggestions2 = new GhostSuggestionsState ( )
782+ suggestions2 . setFillInAtCursor ( {
783+ text : "second" ,
784+ prefix : "const x = 1" ,
785+ suffix : "\nconst y = 2" ,
786+ } )
787+ provider . updateSuggestions ( suggestions2 )
788+
789+ const result = provider . cachedSuggestionAvailable ( "const x = 1" , "\nconst y = 2" )
790+ expect ( result ) . toBe ( true )
791+ } )
792+ } )
793+
731794 describe ( "updateSuggestions" , ( ) => {
732795 it ( "should accept new suggestions state" , ( ) => {
733796 const suggestions = new GhostSuggestionsState ( )
0 commit comments