@@ -171,18 +171,22 @@ public void DA259(string name, string data, bool err)
171171 Assert . Equal ( 4 , brCount ) ;
172172 }
173173
174- [ Theory ]
175- [ InlineData ( "DA240-ListPunctuation.docx" , "DA-DataList.xml" , false ) ]
176- public void DA240 ( string name , string data , bool err )
174+ [ Fact ]
175+ public void DA240 ( )
177176 {
178- DA101 ( name , data , err ) ;
177+ string name = "DA240-Whitespace.docx" ;
178+ DA101 ( name , "DA240-Whitespace.xml" , false ) ;
179179 var assembledDocx = new FileInfo ( Path . Combine ( TestUtil . TempDir . FullName , name . Replace ( ".docx" , "-processed-by-DocumentAssembler.docx" ) ) ) ;
180180 WmlDocument afterAssembling = new WmlDocument ( assembledDocx . FullName ) ;
181181
182- // when elements are inserted that begin or end with white space (such as the list punctuation
183- // in this example), make sure white space is preserved
184- string firstParaText = afterAssembling . MainDocumentPart . Element ( W . body ) . Elements ( W . p ) . First ( ) . Value ;
185- Assert . Equal ( "The children’s names are Greg, Marcia, Peter, Jan, Bobby and Cindy." , firstParaText ) ;
182+ // when elements are inserted that begin or end with white space, make sure white space is preserved
183+ string firstParaTextIncorrect = afterAssembling . MainDocumentPart . Element ( W . body ) . Elements ( W . p ) . First ( ) . Value ;
184+ Assert . Equal ( "Content may or may not have spaces: he/she; he, she; he and she." , firstParaTextIncorrect ) ;
185+ // warning: XElement.Value returns the string resulting from direct concatenation of all W.t elements. This is fast but ignores
186+ // proper handling of xml:space="preserve" attributes, which Word honors when rendering content. Below we also check
187+ // the result of UnicodeMapper.RunToString, which has been enhanced to take xml:space="preserve" into account.
188+ string firstParaTextCorrect = InnerText ( afterAssembling . MainDocumentPart . Element ( W . body ) . Elements ( W . p ) . First ( ) ) ;
189+ Assert . Equal ( "Content may or may not have spaces: he/she; he, she; he and she." , firstParaTextCorrect ) ;
186190 }
187191
188192 [ Theory ]
@@ -235,6 +239,14 @@ public void DA103_UseXmlDocument(string name, string data, bool err)
235239 Assert . Equal ( err , returnedTemplateError ) ;
236240 }
237241
242+ private static string InnerText ( XContainer e )
243+ {
244+ return e . Descendants ( W . r )
245+ . Where ( r => r . Parent . Name != W . del )
246+ . Select ( UnicodeMapper . RunToString )
247+ . StringConcatenate ( ) ;
248+ }
249+
238250 private static List < string > s_ExpectedErrors = new List < string > ( )
239251 {
240252 "The 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:evenHBand' attribute is not declared." ,
0 commit comments