Ensure _.startCase only uppercases the first character of each word.

This commit is contained in:
John-David Dalton
2016-03-17 21:07:55 -07:00
parent 8d7058e6ad
commit 9735961090
2 changed files with 23 additions and 7 deletions

View File

@@ -13208,17 +13208,17 @@
* @returns {string} Returns the start cased string. * @returns {string} Returns the start cased string.
* @example * @example
* *
* _.startCase('--foo-bar'); * _.startCase('--foo-bar--');
* // => 'Foo Bar' * // => 'Foo Bar'
* *
* _.startCase('fooBar'); * _.startCase('fooBar');
* // => 'Foo Bar' * // => 'Foo Bar'
* *
* _.startCase('__foo_bar__'); * _.startCase('__FOO_BAR__');
* // => 'Foo Bar' * // => 'FOO BAR'
*/ */
var startCase = createCompounder(function(result, word, index) { var startCase = createCompounder(function(result, word, index) {
return result + (index ? ' ' : '') + capitalize(word); return result + (index ? ' ' : '') + upperFirst(word);
}); });
/** /**

View File

@@ -2090,7 +2090,7 @@
var strings = [ var strings = [
'foo bar', 'Foo bar', 'foo Bar', 'Foo Bar', 'foo bar', 'Foo bar', 'foo Bar', 'Foo Bar',
'FOO BAR', 'fooBar', '--foo-bar', '__foo_bar__' 'FOO BAR', 'fooBar', '--foo-bar--', '__foo_bar__'
]; ];
var converted = (function() { var converted = (function() {
@@ -2108,7 +2108,8 @@
assert.expect(1); assert.expect(1);
var actual = lodashStable.map(strings, function(string) { var actual = lodashStable.map(strings, function(string) {
return func(string) === converted; var expected = (caseName == 'start' && string == 'FOO BAR') ? string : converted;
return func(string) === expected;
}); });
assert.deepEqual(actual, lodashStable.map(strings, alwaysTrue)); assert.deepEqual(actual, lodashStable.map(strings, alwaysTrue));
@@ -2118,7 +2119,8 @@
assert.expect(1); assert.expect(1);
var actual = lodashStable.map(strings, function(string) { var actual = lodashStable.map(strings, function(string) {
return func(func(string)) === converted; var expected = (caseName == 'start' && string == 'FOO BAR') ? string : converted;
return func(func(string)) === expected;
}); });
assert.deepEqual(actual, lodashStable.map(strings, alwaysTrue)); assert.deepEqual(actual, lodashStable.map(strings, alwaysTrue));
@@ -19821,6 +19823,20 @@
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
QUnit.module('lodash.startCase');
(function() {
QUnit.test('should uppercase only the first character of each word', function(assert) {
assert.expect(3);
assert.strictEqual(_.startCase('--foo-bar--'), 'Foo Bar');
assert.strictEqual(_.startCase('fooBar'), 'Foo Bar');
assert.strictEqual(_.startCase('__FOO_BAR__'), 'FOO BAR');
});
}());
/*--------------------------------------------------------------------------*/
QUnit.module('lodash.startsWith'); QUnit.module('lodash.startsWith');
(function() { (function() {