Browse Source

add blockquote (>>>) formatting + test

pull/1348/head
Chris Johnston 6 years ago
parent
commit
0d65f74da1
2 changed files with 28 additions and 1 deletions
  1. +15
    -1
      src/Discord.Net.Core/Format.cs
  2. +13
    -0
      test/Discord.Net.Tests.Unit/FormatTests.cs

+ 15
- 1
src/Discord.Net.Core/Format.cs View File

@@ -44,7 +44,7 @@ namespace Discord
/// Formats a string as a quote. /// Formats a string as a quote.
/// </summary> /// </summary>
/// <param name="text">The text to format.</param> /// <param name="text">The text to format.</param>
/// <returns>Gets the formatted quote text.</returns> // TODO: better xmldoc
/// <returns>Gets the formatted quote text.</returns>
public static string Quote(string text) public static string Quote(string text)
{ {
// do not modify null or whitespace text // do not modify null or whitespace text
@@ -77,5 +77,19 @@ namespace Discord


return result.ToString(); return result.ToString();
} }
/// <summary>
/// Formats a string as a block quote.
/// </summary>
/// <param name="text">The text to format.</param>
/// <returns>Gets the formatted block quote text.</returns>
public static string BlockQuote(string text)
{
// do not modify null or whitespace
if (string.IsNullOrWhiteSpace(text))
return text;

return $">>> {text}";
}
} }
} }

+ 13
- 0
test/Discord.Net.Tests.Unit/FormatTests.cs View File

@@ -46,5 +46,18 @@ namespace Discord
{ {
Assert.Equal(expected, Format.Quote(input)); Assert.Equal(expected, Format.Quote(input));
} }
[Theory]
[InlineData(null, null)]
[InlineData("", "")]
[InlineData("\n", "\n")]
[InlineData("foo\n\nbar", ">>> foo\n\nbar")]
[InlineData("input", ">>> input")] // single line
// should work with CR or CRLF
[InlineData("inb4\ngreentext", ">>> inb4\ngreentext")]
[InlineData("inb4\r\ngreentext", ">>> inb4\r\ngreentext")]
public void BlockQuote(string input, string expected)
{
Assert.Equal(expected, Format.BlockQuote(input));
}
} }
} }

Loading…
Cancel
Save