Skip to content

Commit a25e9e7

Browse files
author
Lars Klein
committed
Add testcase to test the new config option
1 parent 31db0b7 commit a25e9e7

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

test/DocumentFormat.OpenXml.Tests/ofapiTest/OpenXmlReaderTest.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,42 @@ public void PartReaderMiscNodeTest()
385385
reader.Close();
386386
}
387387

388+
/// <summary>
389+
///A test for OpenXmlPartReader to test the ignoreWhitespace option
390+
///</summary>
391+
[Theory]
392+
[InlineData(true)]
393+
[InlineData(false)]
394+
public void PartReaderIgnoreWhitespaceTest(bool ignoreWhitespace)
395+
{
396+
string partText = "<w:document xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">" +
397+
"<w:body>" +
398+
"<w:p w:rsidP=\"001\"><w:r><w:t> </w:t></w:r></w:p>" +
399+
"</w:body>" +
400+
"</w:document>";
401+
402+
UTF8Encoding utf8Encoding = new UTF8Encoding();
403+
Stream stream = new MemoryStream(utf8Encoding.GetBytes(partText), false);
404+
405+
//======== new test with a new reader ========
406+
OpenXmlReader reader = OpenXmlReader.Create(stream, false, ignoreWhitespace); // ignore whitespaces
407+
Assert.False(reader.EOF);
408+
409+
reader.Read();
410+
Assert.False(reader.EOF);
411+
412+
reader.ReadFirstChild(); // to <w:body>
413+
reader.Read(); // to <w:p>
414+
reader.Read(); // to <w:r>
415+
reader.Read(); // to <w:t>
416+
Assert.True(reader.IsStartElement);
417+
Assert.Equal(typeof(Text), reader.ElementType);
418+
Assert.Equal(ignoreWhitespace, reader.GetText() == string.Empty);
419+
420+
reader.Close();
421+
}
422+
423+
388424
/// <summary>
389425
///A test for OpenXmlPartReader
390426
///</summary>

0 commit comments

Comments
 (0)