Skip to content

Commit

Permalink
add Clear method
Browse files Browse the repository at this point in the history
  • Loading branch information
MeilCli committed May 6, 2017
1 parent 3722dcc commit 20e2233
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ public FormattedStringBuilder AppendLine(string value,Span span) {
return this;
}

public FormattedStringBuilder Clear() {
Length = 0;
return this;
}

public FormattedString ToFormattedString() {
return MergeCharSpan();
}
Expand Down
21 changes: 21 additions & 0 deletions Test/Test.CrossFormattedText.Unit/FormattedStringBuilderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,26 @@ public void AppendLineTest() {

Assert.AreEqual(fsb.ToFormattedString().Text,sb.ToString());
}

[TestMethod]
public void ClearTest() {
var sb = new StringBuilder();
var fsb = new FormattedStringBuilder();

sb.AppendLine();
fsb.AppendLine();
sb.Append("aaa");
fsb.Append("aaa");
sb.Clear();
fsb.Clear();

Assert.AreEqual(fsb.Length,sb.Length);
Assert.AreEqual(fsb.ToFormattedString().Text,sb.ToString());

sb.Append("aaa");
fsb.Append("aaa");

Assert.AreEqual(fsb.ToFormattedString().Text,sb.ToString());
}
}
}

0 comments on commit 20e2233

Please sign in to comment.