Skip to content

Commit

Permalink
remove useless ngettext
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba committed Apr 2, 2020
1 parent c04abcb commit acf8687
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 61 deletions.
32 changes: 0 additions & 32 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -753,38 +753,6 @@ exports.dQuote = function(str) {
return '"' + str + '"';
};

/**
* Provides simplistic message translation for dealing with plurality.
*
* @description
* Use this to create messages which need to be singular or plural.
* Some languages have several plural forms, so _complete_ message clauses
* are preferable to generating the message on the fly.
*
* @private
* @param {number} n - Non-negative integer
* @param {string} msg1 - Message to be used in English for `n = 1`
* @param {string} msg2 - Message to be used in English for `n = 0, 2, 3, ...`
* @returns {string} message corresponding to value of `n`
* @example
* var sprintf = require('util').format;
* var pkgs = ['one', 'two'];
* var msg = sprintf(
* ngettext(
* pkgs.length,
* 'cannot load package: %s',
* 'cannot load packages: %s'
* ),
* pkgs.map(sQuote).join(', ')
* );
* console.log(msg); // => cannot load packages: 'one', 'two'
*/
exports.ngettext = function(n, msg1, msg2) {
if (typeof n === 'number' && n >= 0) {
return n === 1 ? msg1 : msg2;
}
};

/**
* It's a noop.
* @public
Expand Down
8 changes: 4 additions & 4 deletions test/unit/runner.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('Runner', function() {
global.foo = 'bar';
runner.on(EVENT_TEST_FAIL, function(_test, _err) {
expect(_test, 'to be', test);
expect(_err, 'to have message', "global leak detected: 'foo'");
expect(_err, 'to have message', "global leak(s) detected: 'foo'");
delete global.foo;
done();
});
Expand Down Expand Up @@ -183,7 +183,7 @@ describe('Runner', function() {
global.bar = 'baz';
runner.on(EVENT_TEST_FAIL, function(_test, _err) {
expect(_test, 'to be', test);
expect(_err, 'to have message', "global leaks detected: 'foo', 'bar'");
expect(_err.message, 'to be', "global leak(s) detected: 'foo', 'bar'");
delete global.foo;
delete global.bar;
done();
Expand Down Expand Up @@ -217,7 +217,7 @@ describe('Runner', function() {
global.bar = 'detect-me';
runner.on(EVENT_TEST_FAIL, function(_test, _err) {
expect(_test.title, 'to be', 'im a test about lions');
expect(_err, 'to have message', "global leak detected: 'bar'");
expect(_err, 'to have message', "global leak(s) detected: 'bar'");
delete global.foo;
delete global.bar;
done();
Expand All @@ -229,7 +229,7 @@ describe('Runner', function() {
global.derp = 'bar';
runner.on(EVENT_TEST_FAIL, function(_test, _err) {
expect(_test.title, 'to be', 'herp');
expect(_err, 'to have message', "global leak detected: 'derp'");
expect(_err, 'to have message', "global leak(s) detected: 'derp'");
delete global.derp;
done();
});
Expand Down
25 changes: 0 additions & 25 deletions test/unit/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -724,31 +724,6 @@ describe('lib/utils', function() {
});
});

describe('ngettext', function() {
var singular = 'singular';
var plural = 'plural';

it("should return plural string if 'n' is 0", function() {
expect(utils.ngettext(0, singular, plural), 'to be', plural);
});

it("should return singular string if 'n' is 1", function() {
expect(utils.ngettext(1, singular, plural), 'to be', singular);
});

it("should return plural string if 'n' is greater than 1", function() {
var arr = ['aaa', 'bbb'];
expect(utils.ngettext(arr.length, singular, plural), 'to be', plural);
});

it("should return undefined if 'n' is not a non-negative integer", function() {
expect(utils.ngettext('', singular, plural), 'to be undefined');
expect(utils.ngettext(-1, singular, plural), 'to be undefined');
expect(utils.ngettext(true, singular, plural), 'to be undefined');
expect(utils.ngettext({}, singular, plural), 'to be undefined');
});
});

describe('createMap', function() {
it('should return an object with a null prototype', function() {
expect(Object.getPrototypeOf(utils.createMap()), 'to be', null);
Expand Down

0 comments on commit acf8687

Please sign in to comment.