-
-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for custom emojis and smileys
- Loading branch information
Showing
1 changed file
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,99 @@ | ||
using System.Collections.Generic; | ||
using Markdig.Extensions.Emoji; | ||
using NUnit.Framework; | ||
|
||
namespace Markdig.Tests | ||
{ | ||
[TestFixture] | ||
public class TestCustomEmojis | ||
{ | ||
[Test] | ||
[TestCase(":smiley:", "<p>♥</p>\n")] | ||
[TestCase(":confused:", "<p>:confused:</p>\n")] // default emoji does not work | ||
[TestCase(":/", "<p>:/</p>\n")] // default smiley does not work | ||
public void TestCustomEmoji(string input, string expected) | ||
{ | ||
var emojiToUnicode = new Dictionary<string, string>(); | ||
var smileyToEmoji = new Dictionary<string, string>(); | ||
|
||
emojiToUnicode[":smiley:"] = "♥"; | ||
|
||
var customMapping = new EmojiMapping(emojiToUnicode, smileyToEmoji); | ||
|
||
var pipeline = new MarkdownPipelineBuilder() | ||
.UseEmojiAndSmiley(customEmojiMapping: customMapping) | ||
.Build(); | ||
|
||
var actual = Markdown.ToHtml(input, pipeline); | ||
Assert.AreEqual(expected, actual); | ||
} | ||
|
||
[Test] | ||
[TestCase(":testheart:", "<p>♥</p>\n")] | ||
[TestCase("hello", "<p>♥</p>\n")] | ||
[TestCase(":confused:", "<p>:confused:</p>\n")] // default emoji does not work | ||
[TestCase(":/", "<p>:/</p>\n")] // default smiley does not work | ||
public void TestCustomSmiley(string input, string expected) | ||
{ | ||
var emojiToUnicode = new Dictionary<string, string>(); | ||
var smileyToEmoji = new Dictionary<string, string>(); | ||
|
||
emojiToUnicode[":testheart:"] = "♥"; | ||
smileyToEmoji["hello"] = ":testheart:"; | ||
|
||
var customMapping = new EmojiMapping(emojiToUnicode, smileyToEmoji); | ||
|
||
var pipeline = new MarkdownPipelineBuilder() | ||
.UseEmojiAndSmiley(customEmojiMapping: customMapping) | ||
.Build(); | ||
|
||
var actual = Markdown.ToHtml(input, pipeline); | ||
Assert.AreEqual(expected, actual); | ||
} | ||
|
||
[Test] | ||
[TestCase(":smiley:", "<p>♥</p>\n")] | ||
[TestCase(":)", "<p>♥</p>\n")] | ||
[TestCase(":confused:", "<p>😕</p>\n")] // default emoji still works | ||
[TestCase(":/", "<p>😕</p>\n")] // default smiley still works | ||
public void TestOverrideDefaultWithCustomEmoji(string input, string expected) | ||
{ | ||
var emojiToUnicode = EmojiMapping.GetDefaultEmojiToUnicode(); | ||
var smileyToEmoji = EmojiMapping.GetDefaultSmileyToEmoji(); | ||
|
||
emojiToUnicode[":smiley:"] = "♥"; | ||
|
||
var customMapping = new EmojiMapping(emojiToUnicode, smileyToEmoji); | ||
|
||
var pipeline = new MarkdownPipelineBuilder() | ||
.UseEmojiAndSmiley(customEmojiMapping: customMapping) | ||
.Build(); | ||
|
||
var actual = Markdown.ToHtml(input, pipeline); | ||
Assert.AreEqual(expected, actual); | ||
} | ||
|
||
[Test] | ||
[TestCase(":testheart:", "<p>♥</p>\n")] | ||
[TestCase("hello", "<p>♥</p>\n")] | ||
[TestCase(":confused:", "<p>😕</p>\n")] // default emoji still works | ||
[TestCase(":/", "<p>😕</p>\n")] // default smiley still works | ||
public void TestOverrideDefaultWithCustomSmiley(string input, string expected) | ||
{ | ||
var emojiToUnicode = EmojiMapping.GetDefaultEmojiToUnicode(); | ||
var smileyToEmoji = EmojiMapping.GetDefaultSmileyToEmoji(); | ||
|
||
emojiToUnicode[":testheart:"] = "♥"; | ||
smileyToEmoji["hello"] = ":testheart:"; | ||
|
||
var customMapping = new EmojiMapping(emojiToUnicode, smileyToEmoji); | ||
|
||
var pipeline = new MarkdownPipelineBuilder() | ||
.UseEmojiAndSmiley(customEmojiMapping: customMapping) | ||
.Build(); | ||
|
||
var actual = Markdown.ToHtml(input, pipeline); | ||
Assert.AreEqual(expected, actual); | ||
} | ||
} | ||
} |