node tests: Clean up emoji tests.

A few things here:

    * Use _.each to follow our convention.
    * Just use new locals to avoid overwriting template and
      avoid strange Object.assign hack.
    * Just use simple string concatenation.
    * Use better var names: full_name, shortcut
    * Use chaining syntax.
This commit is contained in:
Steve Howell
2018-04-12 20:23:50 +00:00
committed by Tim Abbott
parent 07591f03e2
commit c1a3c85a33

View File

@@ -99,15 +99,16 @@ zrequire('util');
{name: 'between symbols', original: 'Hello.<original>! World.', expected: 'Hello.<original>! World.'}, {name: 'between symbols', original: 'Hello.<original>! World.', expected: 'Hello.<original>! World.'},
{name: 'before end of sentence', original: 'Hello <original>!', expected: 'Hello <converted>!'}, {name: 'before end of sentence', original: 'Hello <original>!', expected: 'Hello <converted>!'},
]; ];
Object.keys(emoji.EMOTICON_CONVERSIONS).forEach(key => { _.each(emoji.EMOTICON_CONVERSIONS, (full_name, shortcut) => {
testcases.forEach(t => { _.each(testcases, (t) => {
var converted_value = `:${emoji.EMOTICON_CONVERSIONS[key]}:`; var converted_value = ':' + full_name + ':';
t = Object.assign({}, t); // circumvent copy by reference. var original = t.original;
t.original = t.original.replace(/(<original>)/g, key); var expected = t.expected;
t.expected = t.expected.replace(/(<original>)/g, key); original = original.replace(/(<original>)/g, shortcut);
t.expected = t.expected.replace(/(<converted>)/g, converted_value); expected = expected.replace(/(<original>)/g, shortcut)
var result = emoji.translate_emoticons_to_names(t.original); .replace(/(<converted>)/g, converted_value);
assert.equal(result, t.expected); var result = emoji.translate_emoticons_to_names(original);
assert.equal(result, expected);
}); });
}); });
}()); }());