Skip to content
This repository has been archived by the owner on Jul 23, 2019. It is now read-only.

Fixes #546 #554

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
448 changes: 235 additions & 213 deletions lib/js/emojione.js

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions lib/js/emojione.min.js

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions lib/js/tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# TESTS
This folder contains tests for the js lib.
## HTML tests
### How to run
Run the `generate.js` script and open the `tests.html` in a browser.
### How to contribute
Add your tests in `validate.json`.
## Backwards Tests
This tests will allow you to compare 2 different versions.
### How to run
* Generate the `translations.json` file using the `generateCurrentTranslations.js` script.
* Checkout a different version.
* Run `mocha -u tdd backwardsTest.js` to compare the 2 versions
### How to test different options/functions
Simply add the required functions and options in the `functionsAndOptionsToCheck.json` and regenerate the `translations.json`
55 changes: 55 additions & 0 deletions lib/js/tests/backwardsTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
'use strict';

var emojione = require("../emojione");
var assert = require("assert");

var asciiEmojis = Object.keys(emojione.asciiList);
var shortnames = Object.keys(emojione.emojioneList);

for (var short in emojione.emojioneList)
if (emojione.emojioneList[short].shortnames)
shortnames = shortnames.concat(emojione.emojioneList[short].shortnames);

try {
var translations = require("./translations.json");
} catch (e) {
throw new Error("No translation.json found. Use generateCurrentTranslations.js to generate it for this version.");
}


var functions = require("./functionsAndOptionsToCheck.json");

Object.keys(functions).forEach(function (functionName) {
suite(functionName,function () {
functions[functionName].forEach(function (options) {
var optionsName = JSON.stringify(options);
suite(optionsName, function () {
var oldOptions = {};
for (var k in options)
oldOptions[k] = emojione[k];
suiteSetup(function () {
for (var k in options)
emojione[k] = options[k];
});
suiteTeardown(function () {
for (var k in options)
emojione[k] = oldOptions[k];
});
suite("ascii", function () {
asciiEmojis.forEach(function (k) {
test(k, function () {
assert.equal(emojione.toImage(k), translations[functionName][optionsName][k]);
});
});
});
suite("shortnames", function () {
shortnames.forEach(function (k) {
test(k, function () {
assert.equal(emojione.toImage(k), translations[functionName][optionsName][k]);
});
});
});
});
});
});
});
10 changes: 10 additions & 0 deletions lib/js/tests/functionsAndOptionsToCheck.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"toImage": [
{
"ascii": true
}, {
"ascii": true,
"riskyMatchShortNames": false
}
]
}
33 changes: 33 additions & 0 deletions lib/js/tests/generateCurrentTranslations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict';

var functions = require("./functionsAndOptionsToCheck.json");


var emojione = require("../emojione");

var asciiEmojis = Object.keys(emojione.asciiList);
var shortnames = Object.keys(emojione.emojioneList);

for (var short in emojione.emojioneList)
if (emojione.emojioneList[short].shortnames)
shortnames = shortnames.concat(emojione.emojioneList[short].shortnames);

emojione.ascii = true;

var bigOne = {};

Object.keys(functions).forEach(function (functionName) {
bigOne[functionName] = {};
functions[functionName].forEach(function (options) {
var optionsName = JSON.stringify(options);
var smallOne = bigOne[functionName][optionsName] = {};
asciiEmojis.forEach(function (k) {
smallOne[k] = emojione[functionName](k);
});
shortnames.forEach(function (k) {
smallOne[k] = emojione[functionName](k);
});
});
});

require('fs').writeFileSync("./translations.json",JSON.stringify(bigOne));
4 changes: 4 additions & 0 deletions lib/js/tests/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@
<script src="http://cdn.jsdelivr.net/qunit/1.14.0/qunit.js"></script>
<script src="../emojione.js"></script>
<script>
emojione.emojiSize = '64';
emojione.spriteSize = '64';
<% _.each(data, function(collection) { %>
QUnit.module("<%= collection.module %>");
<% _.each(collection.tests, function(test) { %>
QUnit.test( "<%= test.description %>", function( assert ) {
<%= test.start %>
assert.equal(emojione.<%= collection.module %>("<%= test.text %>"), "<%= test.expected %>");
<%= test.end %>
});
<% }); %>
<% }); %>
Expand Down
98 changes: 97 additions & 1 deletion lib/js/tests/tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,128 +10,224 @@
<script src="http://cdn.jsdelivr.net/qunit/1.14.0/qunit.js"></script>
<script src="../emojione.js"></script>
<script>
emojione.emojiSize = '64';
emojione.spriteSize = '64';

QUnit.module("toImage");

QUnit.test( "test toImage", function( assert ) {
assert.equal(emojione.toImage("Hello world! 😄 :smile:"), "Hello world! <img class=\"emojione\" alt=\"😄\" title=\":smile:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.0/png/64/1f604.png\"/> <img class=\"emojione\" alt=\"😄\" title=\":smile:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f604.png\"/>");

assert.equal(emojione.toImage("Hello world! 😄 :smile:"), "Hello world! <img class=\"emojione\" alt=\"😄\" title=\":smile:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f604.png\"/> <img class=\"emojione\" alt=\"😄\" title=\":smile:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f604.png\"/>");

});

QUnit.test( "mixed ascii, regular unicode and duplicate emoji", function( assert ) {

assert.equal(emojione.toImage(":alien: is 👽 and 저 is not :alien: or :alien: also :randomy: is not emoji"), "<img class=\"emojione\" alt=\"👽\" title=\":alien:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f47d.png\"/> is <img class=\"emojione\" alt=\"👽\" title=\":alien:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f47d.png\"/> and 저 is not <img class=\"emojione\" alt=\"👽\" title=\":alien:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f47d.png\"/> or <img class=\"emojione\" alt=\"👽\" title=\":alien:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f47d.png\"/> also :randomy: is not emoji");

});


QUnit.module("unifyUnicode");

QUnit.test( "test unifyUnicode", function( assert ) {

assert.equal(emojione.unifyUnicode("Hello world! 😄 :smile:"), "Hello world! 😄 😄");

});

QUnit.test( "mixed ascii, regular unicode and duplicate emoji", function( assert ) {

assert.equal(emojione.unifyUnicode(":alien: is 👽 and 저 is not :alien: or :alien: also :randomy: is not emoji"), "👽 is 👽 and 저 is not 👽 or 👽 also :randomy: is not emoji");

});

QUnit.test( "multiline emoji string", function( assert ) {

assert.equal(emojione.unifyUnicode(":dancer:\
:dancer:"), "💃\
💃");

});

QUnit.test( "triple emoji string", function( assert ) {

assert.equal(emojione.unifyUnicode(":dancer::dancer::alien:"), "💃💃👽");

});


QUnit.module("shortnameToUnicode");

QUnit.test( "single unicode character conversion", function( assert ) {

assert.equal(emojione.shortnameToUnicode("Hello world! 😄 :smile:"), "Hello world! 😄 😄");

});

QUnit.test( "shortname at start of sentence with apostrophe", function( assert ) {

assert.equal(emojione.shortnameToUnicode(":snail:'s are cool!"), "🐌's are cool!");

});

QUnit.test( "shortname shares a colon", function( assert ) {

assert.equal(emojione.shortnameToUnicode(":invalid:snail:"), ":invalid🐌");

});

QUnit.test( "mixed ascii, regular unicode and duplicate emoji", function( assert ) {

assert.equal(emojione.shortnameToUnicode(":alien: is 👽 and 저 is not :alien: or :alien: also :randomy: is not emoji"), "👽 is 👽 and 저 is not 👽 or 👽 also :randomy: is not emoji");

});

QUnit.test( "multiline emoji string", function( assert ) {

assert.equal(emojione.shortnameToUnicode(":dancer:\n:dancer:"), "💃\n💃");

});

QUnit.test( "triple emoji string", function( assert ) {

assert.equal(emojione.shortnameToUnicode(":dancer::dancer::alien:"), "💃💃👽");

});


QUnit.module("shortnameToImage");

QUnit.test( "single shortname character conversion", function( assert ) {

assert.equal(emojione.shortnameToImage("Hello world! 😄 :smile:"), "Hello world! 😄 <img class=\"emojione\" alt=\"😄\" title=\":smile:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f604.png\"/>");

});

QUnit.test( "shortname at start of sentence with apostrophe", function( assert ) {

assert.equal(emojione.shortnameToImage(":snail:'s are cool!"), "<img class=\"emojione\" alt=\"🐌\" title=\":snail:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f40c.png\"/>'s are cool!");

});

QUnit.test( "shortname shares a colon", function( assert ) {

assert.equal(emojione.shortnameToImage(":invalid:snail:"), ":invalid<img class=\"emojione\" alt=\"🐌\" title=\":snail:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f40c.png\"/>");

});

QUnit.test( "mixed ascii, regular unicode and duplicate emoji", function( assert ) {

assert.equal(emojione.shortnameToImage(":alien: is 👽 and 저 is not :alien: or :alien: also :randomy: is not emoji"), "<img class=\"emojione\" alt=\"👽\" title=\":alien:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f47d.png\"/> is 👽 and 저 is not <img class=\"emojione\" alt=\"👽\" title=\":alien:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f47d.png\"/> or <img class=\"emojione\" alt=\"👽\" title=\":alien:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f47d.png\"/> also :randomy: is not emoji");

});

QUnit.test( "multiline emoji string", function( assert ) {

assert.equal(emojione.shortnameToImage(":dancer:\n:dancer:"), "<img class=\"emojione\" alt=\"💃\" title=\":dancer:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f483.png\"/>\n<img class=\"emojione\" alt=\"💃\" title=\":dancer:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f483.png\"/>");

});

QUnit.test( "triple emoji string", function( assert ) {

assert.equal(emojione.shortnameToImage(":dancer::dancer::alien:"), "<img class=\"emojione\" alt=\"💃\" title=\":dancer:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f483.png\"/><img class=\"emojione\" alt=\"💃\" title=\":dancer:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f483.png\"/><img class=\"emojione\" alt=\"👽\" title=\":alien:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f47d.png\"/>");

});


QUnit.module("toShort");

QUnit.test( "single unicode character conversion", function( assert ) {

assert.equal(emojione.toShort("Hello world! 😄 :smile:"), "Hello world! :smile: :smile:");

});

QUnit.test( "mixed ascii, regular unicode and duplicate emoji", function( assert ) {

assert.equal(emojione.toShort("👽 is not :alien: and 저 is not 👽 or 👽"), ":alien: is not :alien: and 저 is not :alien: or :alien:");

});

QUnit.test( "multiline emoji string", function( assert ) {

assert.equal(emojione.toShort("💃\n💃"), ":dancer:\n:dancer:");

});

QUnit.test( "alias vs. canonical", function( assert ) {

assert.equal(emojione.toShort("🇯🇵 どうもありがとう"), ":flag_jp: どうもありがとう");

});

QUnit.test( "unicode character conversion within excluded tag", function( assert ) {

assert.equal(emojione.toShort("<div>😄</div>"), "<div>:smile:</div>");

});


QUnit.module("toImage");

QUnit.test( "single character shortname conversion", function( assert ) {

assert.equal(emojione.toImage("Hello world! 😄 :smile:"), "Hello world! <img class=\"emojione\" alt=\"😄\" title=\":smile:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f604.png\"/> <img class=\"emojione\" alt=\"😄\" title=\":smile:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f604.png\"/>");

});

QUnit.test( "shortname shares a colon", function( assert ) {

assert.equal(emojione.toImage(":invalid:snail:"), ":invalid<img class=\"emojione\" alt=\"🐌\" title=\":snail:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f40c.png\"/>");

});

QUnit.test( "single unicode character conversion", function( assert ) {

assert.equal(emojione.toImage("🐌"), "<img class=\"emojione\" alt=\"🐌\" title=\":snail:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f40c.png\"/>");

});


QUnit.module("toImage");

QUnit.test( "2 consecutive on new lines", function( assert ) {

assert.equal(emojione.toImage(":ro:\n:ro:"), "<img class=\"emojione\" alt=\"🇷🇴\" title=\":ro:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f1f7-1f1f4.png\"/>\n<img class=\"emojione\" alt=\"🇷🇴\" title=\":ro:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f1f7-1f1f4.png\"/>");

});

QUnit.test( "inside a word safe", function( assert ) {
emojione.riskyMatchShortNames = false;
assert.equal(emojione.toImage("a:ro:a"), "a:ro:a");
emojione.riskyMatchShortNames = true;
});

QUnit.test( "inside a word unsafe", function( assert ) {

assert.equal(emojione.toImage("a:ro:a"), "a<img class=\"emojione\" alt=\"🇷🇴\" title=\":ro:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f1f7-1f1f4.png\"/>a");

});

QUnit.test( "alias", function( assert ) {

assert.equal(emojione.toImage(":couplekiss_mm:"), "<img class=\"emojione\" alt=\"👨‍❤️‍💋‍👨\" title=\":couplekiss_mm:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f468-2764-1f48b-1f468.png\"/>");

});

QUnit.test( "alias with +", function( assert ) {

assert.equal(emojione.toImage(":+1_tone1:"), "<img class=\"emojione\" alt=\"👍🏻\" title=\":+1_tone1:\" src=\"https://cdn.jsdelivr.net/emojione/assets/3.1/png/64/1f44d-1f3fb.png\"/>");

});


QUnit.module("unifyUnicode");

QUnit.test( "alias", function( assert ) {

assert.equal(emojione.unifyUnicode(":couplekiss_mm:"), "👨‍❤️‍💋‍👨");

});


Expand Down
Loading