@@ -24,8 +24,7 @@ class TemplatePropertyTypesTestFormatter extends Formatter {
2424 }
2525
2626 protected getVariableValue ( variableName : string ) : string {
27- const value = this . variables . get ( variableName ) ;
28- return typeof value === 'string' ? value : '' ;
27+ return ( this . variables . get ( variableName ) as string ) ?? '' ;
2928 }
3029
3130 protected suggestForValue (
@@ -85,6 +84,14 @@ class TemplatePropertyTypesTestFormatter extends Formatter {
8584 public async testFormat ( input : string ) : Promise < string > {
8685 return await this . format ( input ) ;
8786 }
87+
88+ public async testFormatWithTemplatePropertyCollection (
89+ input : string ,
90+ ) : Promise < string > {
91+ return await this . withTemplatePropertyCollection ( ( ) =>
92+ this . testFormat ( input ) ,
93+ ) ;
94+ }
8895}
8996
9097describe ( 'Formatter template property type inference' , ( ) => {
@@ -110,37 +117,68 @@ describe('Formatter template property type inference', () => {
110117
111118 it ( 'collects comma-separated values as YAML arrays' , async ( ) => {
112119 ( formatter as any ) . variables . set ( 'tags' , 'tag1, tag2, awesomeproject' ) ;
113- await formatter . testFormat ( '---\ntags: {{VALUE:tags}}\n---' ) ;
120+ await formatter . testFormatWithTemplatePropertyCollection (
121+ '---\ntags: {{VALUE:tags}}\n---' ,
122+ ) ;
114123 const vars = formatter . getAndClearTemplatePropertyVars ( ) ;
115124 expect ( vars . get ( 'tags' ) ) . toEqual ( [ 'tag1' , 'tag2' , 'awesomeproject' ] ) ;
116125 } ) ;
117126
118127 it ( 'does not collect comma text for scalar properties' , async ( ) => {
119128 ( formatter as any ) . variables . set ( 'description' , 'Hello, world' ) ;
120- await formatter . testFormat ( '---\ndescription: {{VALUE:description}}\n---' ) ;
129+ await formatter . testFormatWithTemplatePropertyCollection (
130+ '---\ndescription: {{VALUE:description}}\n---' ,
131+ ) ;
121132 const vars = formatter . getAndClearTemplatePropertyVars ( ) ;
122133 expect ( vars . has ( 'description' ) ) . toBe ( false ) ;
123134 } ) ;
124135
125136 it ( 'collects bullet list values as YAML arrays' , async ( ) => {
126137 ( formatter as any ) . variables . set ( 'projects' , '- project1\n- project2' ) ;
127- await formatter . testFormat ( '---\nprojects: {{VALUE:projects}}\n---' ) ;
138+ await formatter . testFormatWithTemplatePropertyCollection (
139+ '---\nprojects: {{VALUE:projects}}\n---' ,
140+ ) ;
128141 const vars = formatter . getAndClearTemplatePropertyVars ( ) ;
129142 expect ( vars . get ( 'projects' ) ) . toEqual ( [ 'project1' , 'project2' ] ) ;
130143 } ) ;
131144
132- it ( 'uses a YAML-safe placeholder for collected arrays before post-processing ' , async ( ) => {
145+ it ( 'preserves raw structured replacements outside template property collection ' , async ( ) => {
133146 ( formatter as any ) . variables . set ( 'tags' , [ '[[John Doe]]' , '[[Jane Doe]]' ] ) ;
134147 const output = await formatter . testFormat ( '---\ntags: {{VALUE:tags}}\n---' ) ;
135148 const vars = formatter . getAndClearTemplatePropertyVars ( ) ;
136149
150+ expect ( output ) . toBe ( '---\ntags: [[John Doe]],[[Jane Doe]]\n---' ) ;
151+ expect ( vars . size ) . toBe ( 0 ) ;
152+ } ) ;
153+
154+ it ( 'uses a YAML-safe placeholder for collected arrays before post-processing' , async ( ) => {
155+ ( formatter as any ) . variables . set ( 'tags' , [ '[[John Doe]]' , '[[Jane Doe]]' ] ) ;
156+ const output = await formatter . testFormatWithTemplatePropertyCollection (
157+ '---\ntags: {{VALUE:tags}}\n---' ,
158+ ) ;
159+ const vars = formatter . getAndClearTemplatePropertyVars ( ) ;
160+
137161 expect ( output ) . toBe ( '---\ntags: []\n---' ) ;
138162 expect ( vars . get ( 'tags' ) ) . toEqual ( [ '[[John Doe]]' , '[[Jane Doe]]' ] ) ;
139163 } ) ;
140164
165+ it ( 'does not apply case transforms to YAML placeholders' , async ( ) => {
166+ ( formatter as any ) . variables . set ( 'done' , null ) ;
167+ const output =
168+ await formatter . testFormatWithTemplatePropertyCollection (
169+ '---\ndone: {{VALUE:done|case:upper}}\n---' ,
170+ ) ;
171+ const vars = formatter . getAndClearTemplatePropertyVars ( ) ;
172+
173+ expect ( output ) . toBe ( '---\ndone: null\n---' ) ;
174+ expect ( vars . get ( 'done' ) ) . toBeNull ( ) ;
175+ } ) ;
176+
141177 it ( 'ignores wiki links with commas to avoid incorrect splitting' , async ( ) => {
142178 ( formatter as any ) . variables . set ( 'source' , '[[test, a]]' ) ;
143- await formatter . testFormat ( '---\nsource: {{VALUE:source}}\n---' ) ;
179+ await formatter . testFormatWithTemplatePropertyCollection (
180+ '---\nsource: {{VALUE:source}}\n---' ,
181+ ) ;
144182 const vars = formatter . getAndClearTemplatePropertyVars ( ) ;
145183 expect ( vars . has ( 'source' ) ) . toBe ( false ) ;
146184 } ) ;
0 commit comments