prototype: Make sure $w always returns an array.

This commit is contained in:
Tobie Langel 2007-10-15 17:19:16 +00:00
parent 0632778884
commit 865ac01937
3 changed files with 8 additions and 0 deletions

View File

@ -1,5 +1,7 @@
*SVN*
* Make sure $w always returns an array. [Andrew Dupont, Tobie Langel]
* Add more tests to Hash. [Mislav Marohnić]
* Performance enhancements to $A. Closes #9464. [Samuel Lebeau]

View File

@ -128,6 +128,7 @@ if (!Array.prototype.lastIndexOf) Array.prototype.lastIndexOf = function(item, i
Array.prototype.toArray = Array.prototype.clone;
function $w(string) {
if (!Object.isString(string)) return [];
string = string.strip();
return string ? string.split(/\s+/) : [];
}

View File

@ -204,6 +204,11 @@
test$w: function(){ with(this) {
assertEnumEqual(['a', 'b', 'c', 'd'], $w('a b c d'));
assertEnumEqual([], $w(' '));
assertEnumEqual([], $w(''));
assertEnumEqual([], $w(null));
assertEnumEqual([], $w(undefined));
assertEnumEqual([], $w());
assertEnumEqual([], $w(10));
assertEnumEqual(['a'], $w('a'));
assertEnumEqual(['a'], $w('a '));
assertEnumEqual(['a'], $w(' a'));