Skip to content

Commit

Permalink
Add testcase to test the new config option
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Klein committed Jan 19, 2021
1 parent 5c9cf02 commit 51296aa
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions test/DocumentFormat.OpenXml.Tests/ofapiTest/OpenXmlReaderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,42 @@ public void PartReaderMiscNodeTest()
reader.Close();
}

/// <summary>
///A test for OpenXmlPartReader to test the ignoreWhitespace option
///</summary>
[Theory]
[InlineData(true)]
[InlineData(false)]
public void PartReaderIgnoreWhitespaceTest(bool ignoreWhitespace)
{
string partText = "<w:document xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\">" +
"<w:body>" +
"<w:p w:rsidP=\"001\"><w:r><w:t> </w:t></w:r></w:p>" +
"</w:body>" +
"</w:document>";

UTF8Encoding utf8Encoding = new UTF8Encoding();
Stream stream = new MemoryStream(utf8Encoding.GetBytes(partText), false);

//======== new test with a new reader ========
OpenXmlReader reader = OpenXmlReader.Create(stream, false, ignoreWhitespace); // ignore whitespaces
Assert.False(reader.EOF);

reader.Read();
Assert.False(reader.EOF);

reader.ReadFirstChild(); // to <w:body>
reader.Read(); // to <w:p>
reader.Read(); // to <w:r>
reader.Read(); // to <w:t>
Assert.True(reader.IsStartElement);
Assert.Equal(typeof(Text), reader.ElementType);
Assert.Equal(ignoreWhitespace, reader.GetText() == string.Empty);

reader.Close();
}


/// <summary>
///A test for OpenXmlPartReader
///</summary>
Expand Down

0 comments on commit 51296aa

Please sign in to comment.