-
Notifications
You must be signed in to change notification settings - Fork 48
Add unit test for test coverage #722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e02d5eb
update
v-fuquanli db8b05f
update
v-fuquanli 08c4999
update
v-fuquanli 7416f75
update
v-fuquanli f172dab
update
v-fuquanli 0760612
update
v-fuquanli afeee11
update
v-fuquanli c70f687
update
v-fuquanli a52a380
update
v-fuquanli 5f11e26
update
v-fuquanli 1072b6e
update
v-fuquanli 7b1b8ce
update
v-fuquanli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
using Mono.Documentation; | ||
using NUnit.Framework; | ||
using System.Text; | ||
using System.Xml; | ||
|
||
namespace mdoc.Test | ||
{ | ||
[TestFixture] | ||
public class DelegatingXmlWriterTests | ||
{ | ||
private StringBuilder output; | ||
private XmlWriter baseWriter; | ||
private DelegatingXmlWriter delegatingWriter; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
output = new StringBuilder(); | ||
XmlWriterSettings settings = new XmlWriterSettings | ||
{ | ||
OmitXmlDeclaration = true, | ||
ConformanceLevel = ConformanceLevel.Fragment | ||
}; | ||
baseWriter = XmlWriter.Create(output, settings); | ||
delegatingWriter = new DelegatingXmlWriter(baseWriter); | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
delegatingWriter.Close(); | ||
} | ||
|
||
[Test] | ||
public void TestWriteStartElement() | ||
{ | ||
delegatingWriter.WriteStartElement("prefix", "localName", "namespace"); | ||
delegatingWriter.WriteEndElement(); | ||
delegatingWriter.Flush(); | ||
|
||
Assert.AreEqual("<prefix:localName xmlns:prefix=\"namespace\" />", output.ToString()); | ||
} | ||
|
||
[Test] | ||
public void TestWriteString() | ||
{ | ||
delegatingWriter.WriteStartElement("root"); | ||
delegatingWriter.WriteString("content"); | ||
delegatingWriter.WriteEndElement(); | ||
delegatingWriter.Flush(); | ||
|
||
Assert.AreEqual("<root>content</root>", output.ToString()); | ||
} | ||
|
||
[Test] | ||
public void TestWriteFullEndElement() | ||
{ | ||
delegatingWriter.WriteStartElement("root"); | ||
delegatingWriter.WriteFullEndElement(); | ||
delegatingWriter.Flush(); | ||
|
||
Assert.AreEqual("<root></root>", output.ToString()); | ||
} | ||
|
||
[Test] | ||
public void TestWriteCData() | ||
{ | ||
delegatingWriter.WriteStartElement("root"); | ||
delegatingWriter.WriteCData("cdata content"); | ||
delegatingWriter.WriteEndElement(); | ||
delegatingWriter.Flush(); | ||
|
||
Assert.AreEqual("<root><![CDATA[cdata content]]></root>", output.ToString()); | ||
} | ||
|
||
[Test] | ||
public void TestWriteComment() | ||
{ | ||
delegatingWriter.WriteComment("comment"); | ||
delegatingWriter.Flush(); | ||
|
||
Assert.AreEqual("<!--comment-->", output.ToString()); | ||
} | ||
|
||
[Test] | ||
public void TestWriteProcessingInstruction() | ||
{ | ||
delegatingWriter.WriteProcessingInstruction("xml-stylesheet", "type=\"text/xsl\" href=\"style.xsl\""); | ||
delegatingWriter.Flush(); | ||
|
||
Assert.AreEqual("<?xml-stylesheet type=\"text/xsl\" href=\"style.xsl\"?>", output.ToString()); | ||
} | ||
|
||
[Test] | ||
public void TestWriteWhitespace() | ||
{ | ||
delegatingWriter.WriteWhitespace(" "); | ||
delegatingWriter.Flush(); | ||
|
||
Assert.AreEqual(" ", output.ToString()); | ||
} | ||
|
||
[Test] | ||
public void TestWriteRaw() | ||
{ | ||
delegatingWriter.WriteRaw("<raw>data</raw>"); | ||
delegatingWriter.Flush(); | ||
|
||
Assert.AreEqual("<raw>data</raw>", output.ToString()); | ||
} | ||
|
||
[Test] | ||
public void TestWriteEntityRef() | ||
{ | ||
delegatingWriter.WriteEntityRef("entity"); | ||
delegatingWriter.Flush(); | ||
|
||
Assert.AreEqual("&entity;", output.ToString()); | ||
} | ||
|
||
[Test] | ||
public void TestWriteCharEntity() | ||
{ | ||
delegatingWriter.WriteCharEntity('c'); | ||
delegatingWriter.Flush(); | ||
|
||
Assert.AreEqual("c", output.ToString()); | ||
} | ||
[Test] | ||
public void TestWriteBase64() | ||
{ | ||
byte[] buffer = Encoding.UTF8.GetBytes("base64 content"); | ||
delegatingWriter.WriteStartElement("root"); | ||
delegatingWriter.WriteBase64(buffer, 0, buffer.Length); | ||
delegatingWriter.WriteEndElement(); | ||
delegatingWriter.Flush(); | ||
|
||
Assert.AreEqual("<root>YmFzZTY0IGNvbnRlbnQ=</root>", output.ToString()); | ||
} | ||
|
||
[Test] | ||
public void TestWriteBinHex() | ||
{ | ||
byte[] buffer = Encoding.UTF8.GetBytes("binhex content"); | ||
delegatingWriter.WriteStartElement("root"); | ||
delegatingWriter.WriteBinHex(buffer, 0, buffer.Length); | ||
delegatingWriter.WriteEndElement(); | ||
delegatingWriter.Flush(); | ||
|
||
Assert.AreEqual("<root>62696E68657820636F6E74656E74</root>", output.ToString()); | ||
} | ||
|
||
[Test] | ||
public void TestWriteChars() | ||
{ | ||
char[] buffer = "char content".ToCharArray(); | ||
delegatingWriter.WriteStartElement("root"); | ||
delegatingWriter.WriteChars(buffer, 0, buffer.Length); | ||
delegatingWriter.WriteEndElement(); | ||
delegatingWriter.Flush(); | ||
|
||
Assert.AreEqual("<root>char content</root>", output.ToString()); | ||
} | ||
|
||
[Test] | ||
public void TestWriteStartAttribute() | ||
{ | ||
delegatingWriter.WriteStartElement("root"); | ||
delegatingWriter.WriteStartAttribute("prefix", "attrName", "namespace"); | ||
delegatingWriter.WriteString("attrValue"); | ||
delegatingWriter.WriteEndAttribute(); | ||
delegatingWriter.WriteEndElement(); | ||
delegatingWriter.Flush(); | ||
|
||
Assert.AreEqual("<root prefix:attrName=\"attrValue\" xmlns:prefix=\"namespace\" />", output.ToString()); | ||
} | ||
|
||
[Test] | ||
public void TestWriteQualifiedName() | ||
{ | ||
delegatingWriter.WriteStartElement("root"); | ||
delegatingWriter.WriteAttributeString("xmlns", "namespace", null, "namespace"); | ||
delegatingWriter.WriteQualifiedName("qualifiedName", "namespace"); | ||
delegatingWriter.WriteEndElement(); | ||
delegatingWriter.Flush(); | ||
|
||
Assert.AreEqual("<root xmlns:namespace=\"namespace\">namespace:qualifiedName</root>", output.ToString()); | ||
} | ||
|
||
[Test] | ||
public void TestWriteSurrogateCharEntity() | ||
{ | ||
delegatingWriter.WriteStartElement("root"); | ||
delegatingWriter.WriteSurrogateCharEntity('\uDC00', '\uD800'); | ||
delegatingWriter.WriteEndElement(); | ||
delegatingWriter.Flush(); | ||
|
||
Assert.AreEqual("<root>𐀀</root>", output.ToString()); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.