Skip to content

Commit

Permalink
add plus operator
Browse files Browse the repository at this point in the history
  • Loading branch information
MeilCli committed May 28, 2017
1 parent f7b201d commit cb8b962
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Source/Plugin.CrossFormattedText.Abstractions/FormattedString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -739,5 +739,17 @@ public static implicit operator FormattedString(string text) {
public static explicit operator string(FormattedString text) {
return text.Text;
}

public static FormattedString operator+(FormattedString a,FormattedString b) {
return new FormattedString(a.spans.Concat(b.spans));
}

public static FormattedString operator+(FormattedString formattedString,Span span) {
return new FormattedString(formattedString.spans.Concat(Enumerable.Repeat(span,1)));
}

public static FormattedString operator+(Span span,FormattedString formattedString) {
return new FormattedString(Enumerable.Repeat(span,1).Concat(formattedString.spans));
}
}
}
13 changes: 13 additions & 0 deletions Test/Test.CrossFormattedText.Unit/FormattedStringTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,5 +290,18 @@ public void TrimSpanTest() {
Assert.AreEqual(newText1.Text,text.Subspan(1,3).Text);
Assert.AreEqual(newText1.AnySpanReferenceEquals(text),false);
}

[TestMethod]
public void PlusOperatorTest() {
FormattedString value = "aaa";

Assert.AreEqual((value + "ccc").Text,"aaaccc");
Assert.AreEqual(("ccc" + value).Text,"cccaaa");

Span a = new Span() { Text = "bbb" };

Assert.AreEqual((value + a).Text,"aaabbb");
Assert.AreEqual((a + value).Text,"bbbaaa");
}
}
}

0 comments on commit cb8b962

Please sign in to comment.