Skip to content

Commit

Permalink
Add unit tests for custom emojis and smileys
Browse files Browse the repository at this point in the history
  • Loading branch information
mlaily committed Jan 16, 2020
1 parent 3033284 commit 0057b36
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions src/Markdig.Tests/TestCustomEmojis.cs
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);
}
}
}

0 comments on commit 0057b36

Please sign in to comment.