Improved readabilty. Improved accuracy of stripBraces() function.

This commit is contained in:
pschwartau%netscape.com 2001-09-05 00:49:31 +00:00
Родитель 629bcf86ac
Коммит ded8f34015
1 изменённых файлов: 29 добавлений и 22 удалений

Просмотреть файл

@ -23,6 +23,13 @@
* See http://bugzilla.mozilla.org/show_bug.cgi?id=90596 * See http://bugzilla.mozilla.org/show_bug.cgi?id=90596
* *
* NOTE: some inefficiencies in the test are made for the sake of readability. * NOTE: some inefficiencies in the test are made for the sake of readability.
* For example, we quote string values like "Hi" in lines like this:
*
* actual = enumerateThis(obj);
* expect = '{prop:"Hi"}';
*
* But enumerateThis(obj) gets literal value Hi for obj.prop, not literal "Hi".
* We take care of all these details in the compactThis(), sortThis() functions.
* Sorting properties alphabetically is necessary for the test to work in Rhino. * Sorting properties alphabetically is necessary for the test to work in Rhino.
*/ */
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -31,7 +38,6 @@ var bug = 90596;
var summary = '[DontEnum] props (if overridden) should appear in for-in loops'; var summary = '[DontEnum] props (if overridden) should appear in for-in loops';
var cnCOMMA = ','; var cnCOMMA = ',';
var cnCOLON = ':'; var cnCOLON = ':';
var cnEMPTY = '';
var cnLBRACE = '{'; var cnLBRACE = '{';
var cnRBRACE = '}'; var cnRBRACE = '}';
var status = ''; var status = '';
@ -42,6 +48,7 @@ var expect= '';
var expectedvalues = []; var expectedvalues = [];
var obj = {}; var obj = {};
status = inSection(1); status = inSection(1);
obj = {toString:9}; obj = {toString:9};
actual = enumerateThis(obj); actual = enumerateThis(obj);
@ -189,24 +196,24 @@ function addThis()
*/ */
function sortThis(sList) function sortThis(sList)
{ {
sList = formatThis(sList); sList = compactThis(sList);
sList = stripBraces(sList);
var arr = sList.split(cnCOMMA); var arr = sList.split(cnCOMMA);
arr = arr.sort(); arr = arr.sort();
var ret = String(arr); var ret = String(arr);
return addBraces(ret); ret = addBraces(ret);
return ret;
} }
/* /*
* Strips out braces at beginning/end of text, and any whitespace or quotes * Strips out any whitespace or quotes from the text -
*/ */
function formatThis(text) function compactThis(text)
{ {
var charCode = 0; var charCode = 0;
var ret = ''; var ret = '';
text = stripBraces(text);
for (var i=0; i<text.length; i++) for (var i=0; i<text.length; i++)
{ {
charCode = text.charCodeAt(i); charCode = text.charCodeAt(i);
@ -219,21 +226,6 @@ function formatThis(text)
} }
/*
* strips off braces at beginning and end of text -
*/
function stripBraces(text)
{
// remember to escape the braces...
var arr = text.match(/^\{(.*)\}$/);
// defend against a null match...
if (arr && arr[1])
return arr[1];
return cnEMPTY;
}
function isWhiteSpace(charCode) function isWhiteSpace(charCode)
{ {
switch (charCode) switch (charCode)
@ -268,6 +260,21 @@ function isQuote(charCode)
} }
/*
* strips off braces at beginning and end of text -
*/
function stripBraces(text)
{
// remember to escape the braces...
var arr = text.match(/^\{(.*)\}$/);
// defend against a null match...
if (arr != null && arr[1] != null)
return arr[1];
return text;
}
function test() function test()
{ {
enterFunc ('test'); enterFunc ('test');