From a81aad61ab6e7c47f1460e20583cae7c469c68e5 Mon Sep 17 00:00:00 2001 From: Peter Jaszkowiak Date: Thu, 1 Dec 2016 17:23:06 -0700 Subject: [PATCH] Add tests for translator static methods --- public/src/modules/translator.js | 6 ++++-- test/translator.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/public/src/modules/translator.js b/public/src/modules/translator.js index e60385ed79..d975e16e1d 100644 --- a/public/src/modules/translator.js +++ b/public/src/modules/translator.js @@ -395,11 +395,13 @@ /** * Construct a translator pattern + * @param {string} name - Translation name + * @param {...string} arg - Optional argument for the pattern */ Translator.compile = function compile() { - var args = Array.prototype.slice.call(arguments, 0); + var args = Array.prototype.slice.call(arguments, 0); - return '[[' + args.join(', ') + ']]'; + return '[[' + args.join(', ') + ']]'; }; return Translator; diff --git a/test/translator.js b/test/translator.js index 60fb589e0d..a89681adef 100644 --- a/test/translator.js +++ b/test/translator.js @@ -223,4 +223,33 @@ describe('Translator static methods', function () { done(); }); }); + describe('.escape', function () { + it('should escape translation patterns within text', function (done) { + assert.strictEqual( + Translator.escape('some nice text [[global:home]] here'), + 'some nice text \\[\\[global:home\\]\\] here' + ); + done(); + }); + }); + + describe('.unescape', function () { + it('should unescape escaped translation patterns within text', function (done) { + assert.strictEqual( + Translator.unescape('some nice text \\[\\[global:home\\]\\] here'), + 'some nice text [[global:home]] here' + ); + done(); + }); + }); + + describe('.compile', function () { + it('should create a translator pattern from a key and list of arguments', function (done) { + assert.strictEqual( + Translator.compile('amazing:cool', 'awesome', 'great'), + '[[amazing:cool, awesome, great]]' + ); + done(); + }); + }); });