@@ -73,6 +73,48 @@ public ValueTask<string> LoadAsync(TemplateContext context, SourceSpan callerSpa
7373 }
7474 }
7575
76+ private sealed class SwitchingLoader : ITemplateLoader
77+ {
78+ public string Content { get ; set ; } = string . Empty ;
79+
80+ public string GetPath ( TemplateContext context , SourceSpan callerSpan , string templateName )
81+ {
82+ return templateName ;
83+ }
84+
85+ public string Load ( TemplateContext context , SourceSpan callerSpan , string templatePath )
86+ {
87+ return Content ;
88+ }
89+
90+ public ValueTask < string > LoadAsync ( TemplateContext context , SourceSpan callerSpan , string templatePath )
91+ {
92+ return ValueTask . FromResult ( Load ( context , callerSpan , templatePath ) ) ;
93+ }
94+ }
95+
96+ [ Test ]
97+ public void ResetShouldClearCachedTemplates ( )
98+ {
99+ var loader = new SwitchingLoader { Content = "admin-only" } ;
100+ var context = new TemplateContext
101+ {
102+ TemplateLoader = loader
103+ } ;
104+ var template = Template . Parse ( "{{ include 'profile' }}" ) ;
105+
106+ var first = template . Render ( context ) ;
107+ Assert . AreEqual ( "admin-only" , first ) ;
108+ Assert . That ( context . CachedTemplates , Does . ContainKey ( "profile" ) ) ;
109+
110+ context . Reset ( ) ;
111+ loader . Content = "guest-view" ;
112+
113+ var second = template . Render ( context ) ;
114+ Assert . AreEqual ( "guest-view" , second ) ;
115+ Assert . That ( context . CachedTemplates , Does . ContainKey ( "profile" ) ) ;
116+ }
117+
76118 [ Test ]
77119 public void TestIndentedNestedIncludes ( )
78120 {
@@ -557,4 +599,4 @@ public void TestIncludeJoinWithTemplateDelimiters()
557599 Assert . AreEqual ( expectedString , template . Render ( context ) ) ;
558600 }
559601 }
560- }
602+ }
0 commit comments