Improve output: distinguish between failed assertions (failures) and unexpected exceptions (errors), and print a filtered stack trace for any exception.

This commit is contained in:
jeb228 2010-01-29 22:13:57 +00:00
commit 4f2e303079
1839 changed files with 235630 additions and 0 deletions

View file

@ -0,0 +1,105 @@
/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
http://dojotoolkit.org/community/licensing.shtml
*/
dojo.provide("dojo.string.Builder");
dojo.require("dojo.string");
// NOTE: testing shows that direct "+=" concatenation is *much* faster on
// Spidermoneky and Rhino, while arr.push()/arr.join() style concatenation is
// significantly quicker on IE (Jscript/wsh/etc.).
dojo.string.Builder = function(str){
this.arrConcat = (dojo.render.html.capable && dojo.render.html["ie"]);
var a = [];
var b = str || "";
var length = this.length = b.length;
if(this.arrConcat){
if(b.length > 0){
a.push(b);
}
b = "";
}
this.toString = this.valueOf = function(){
return (this.arrConcat) ? a.join("") : b;
};
this.append = function(s){
if(this.arrConcat){
a.push(s);
}else{
b+=s;
}
length += s.length;
this.length = length;
return this;
};
this.clear = function(){
a = [];
b = "";
length = this.length = 0;
return this;
};
this.remove = function(f,l){
var s = "";
if(this.arrConcat){
b = a.join("");
}
a=[];
if(f>0){
s = b.substring(0, (f-1));
}
b = s + b.substring(f + l);
length = this.length = b.length;
if(this.arrConcat){
a.push(b);
b="";
}
return this;
};
this.replace = function(o,n){
if(this.arrConcat){
b = a.join("");
}
a = [];
b = b.replace(o,n);
length = this.length = b.length;
if(this.arrConcat){
a.push(b);
b="";
}
return this;
};
this.insert = function(idx,s){
if(this.arrConcat){
b = a.join("");
}
a=[];
if(idx == 0){
b = s + b;
}else{
var t = b.split("");
t.splice(idx,0,s);
b = t.join("")
}
length = this.length = b.length;
if(this.arrConcat){
a.push(b);
b="";
}
return this;
};
};

View file

@ -0,0 +1,19 @@
/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
http://dojotoolkit.org/community/licensing.shtml
*/
dojo.kwCompoundRequire({
common: [
"dojo.string",
"dojo.string.common",
"dojo.string.extras",
"dojo.string.Builder"
]
});
dojo.provide("dojo.string.*");

View file

@ -0,0 +1,87 @@
/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
http://dojotoolkit.org/community/licensing.shtml
*/
dojo.provide("dojo.string.common");
dojo.require("dojo.string");
/**
* Trim whitespace from 'str'. If 'wh' > 0,
* only trim from start, if 'wh' < 0, only trim
* from end, otherwise trim both ends
*/
dojo.string.trim = function(str, wh){
if(!str.replace){ return str; }
if(!str.length){ return str; }
var re = (wh > 0) ? (/^\s+/) : (wh < 0) ? (/\s+$/) : (/^\s+|\s+$/g);
return str.replace(re, "");
}
/**
* Trim whitespace at the beginning of 'str'
*/
dojo.string.trimStart = function(str) {
return dojo.string.trim(str, 1);
}
/**
* Trim whitespace at the end of 'str'
*/
dojo.string.trimEnd = function(str) {
return dojo.string.trim(str, -1);
}
/**
* Return 'str' repeated 'count' times, optionally
* placing 'separator' between each rep
*/
dojo.string.repeat = function(str, count, separator) {
var out = "";
for(var i = 0; i < count; i++) {
out += str;
if(separator && i < count - 1) {
out += separator;
}
}
return out;
}
/**
* Pad 'str' to guarantee that it is at least 'len' length
* with the character 'c' at either the start (dir=1) or
* end (dir=-1) of the string
*/
dojo.string.pad = function(str, len/*=2*/, c/*='0'*/, dir/*=1*/) {
var out = String(str);
if(!c) {
c = '0';
}
if(!dir) {
dir = 1;
}
while(out.length < len) {
if(dir > 0) {
out = c + out;
} else {
out += c;
}
}
return out;
}
/** same as dojo.string.pad(str, len, c, 1) */
dojo.string.padLeft = function(str, len, c) {
return dojo.string.pad(str, len, c, 1);
}
/** same as dojo.string.pad(str, len, c, -1) */
dojo.string.padRight = function(str, len, c) {
return dojo.string.pad(str, len, c, -1);
}

View file

@ -0,0 +1,237 @@
/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
http://dojotoolkit.org/community/licensing.shtml
*/
dojo.provide("dojo.string.extras");
dojo.require("dojo.string.common");
dojo.require("dojo.lang");
/**
* Performs parameterized substitutions on a string. For example,
* dojo.string.substituteParams("File '%{0}' is not found in directory '%{1}'.","foo.html","/temp");
* returns
* "File 'foo.html' is not found in directory '/temp'."
*
* @param template the original string template with %{values} to be replaced
* @param hash name/value pairs (type object) to provide substitutions. Alternatively, substitutions may be
* included as arguments 1..n to this function, corresponding to template parameters 0..n-1
* @return the completed string. Throws an exception if any parameter is unmatched
*/
//TODO: use ${} substitution syntax instead, like widgets do?
dojo.string.substituteParams = function(template /*string */, hash /* object - optional or ... */) {
var map = (typeof hash == 'object') ? hash : dojo.lang.toArray(arguments, 1);
return template.replace(/\%\{(\w+)\}/g, function(match, key){
return map[key] || dojo.raise("Substitution not found: " + key);
});
};
/**
* Parameterized string function
* str - formatted string with %{values} to be replaces
* pairs - object of name: "value" value pairs
* killExtra - remove all remaining %{values} after pairs are inserted
*/
dojo.string.paramString = function(str, pairs, killExtra) {
dojo.deprecated("dojo.string.paramString",
"use dojo.string.substituteParams instead", "0.4");
for(var name in pairs) {
var re = new RegExp("\\%\\{" + name + "\\}", "g");
str = str.replace(re, pairs[name]);
}
if(killExtra) { str = str.replace(/%\{([^\}\s]+)\}/g, ""); }
return str;
}
/** Uppercases the first letter of each word */
dojo.string.capitalize = function (str) {
if (!dojo.lang.isString(str)) { return ""; }
if (arguments.length == 0) { str = this; }
var words = str.split(' ');
for(var i=0; i<words.length; i++){
words[i] = words[i].charAt(0).toUpperCase() + words[i].substring(1);
}
return words.join(" ");
}
/**
* Return true if the entire string is whitespace characters
*/
dojo.string.isBlank = function (str) {
if(!dojo.lang.isString(str)) { return true; }
return (dojo.string.trim(str).length == 0);
}
dojo.string.encodeAscii = function(str) {
if(!dojo.lang.isString(str)) { return str; }
var ret = "";
var value = escape(str);
var match, re = /%u([0-9A-F]{4})/i;
while((match = value.match(re))) {
var num = Number("0x"+match[1]);
var newVal = escape("&#" + num + ";");
ret += value.substring(0, match.index) + newVal;
value = value.substring(match.index+match[0].length);
}
ret += value.replace(/\+/g, "%2B");
return ret;
}
dojo.string.escape = function(type, str) {
var args = dojo.lang.toArray(arguments, 1);
switch(type.toLowerCase()) {
case "xml":
case "html":
case "xhtml":
return dojo.string.escapeXml.apply(this, args);
case "sql":
return dojo.string.escapeSql.apply(this, args);
case "regexp":
case "regex":
return dojo.string.escapeRegExp.apply(this, args);
case "javascript":
case "jscript":
case "js":
return dojo.string.escapeJavaScript.apply(this, args);
case "ascii":
// so it's encode, but it seems useful
return dojo.string.encodeAscii.apply(this, args);
default:
return str;
}
}
dojo.string.escapeXml = function(str, noSingleQuotes) {
str = str.replace(/&/gm, "&amp;").replace(/</gm, "&lt;")
.replace(/>/gm, "&gt;").replace(/"/gm, "&quot;");
if(!noSingleQuotes) { str = str.replace(/'/gm, "&#39;"); }
return str;
}
dojo.string.escapeSql = function(str) {
return str.replace(/'/gm, "''");
}
dojo.string.escapeRegExp = function(str) {
return str.replace(/\\/gm, "\\\\").replace(/([\f\b\n\t\r[\^$|?*+(){}])/gm, "\\$1");
}
dojo.string.escapeJavaScript = function(str) {
return str.replace(/(["'\f\b\n\t\r])/gm, "\\$1");
}
dojo.string.escapeString = function(str){
return ('"' + str.replace(/(["\\])/g, '\\$1') + '"'
).replace(/[\f]/g, "\\f"
).replace(/[\b]/g, "\\b"
).replace(/[\n]/g, "\\n"
).replace(/[\t]/g, "\\t"
).replace(/[\r]/g, "\\r");
}
// TODO: make an HTML version
dojo.string.summary = function(str, len) {
if(!len || str.length <= len) {
return str;
} else {
return str.substring(0, len).replace(/\.+$/, "") + "...";
}
}
/**
* Returns true if 'str' ends with 'end'
*/
dojo.string.endsWith = function(str, end, ignoreCase) {
if(ignoreCase) {
str = str.toLowerCase();
end = end.toLowerCase();
}
if((str.length - end.length) < 0){
return false;
}
return str.lastIndexOf(end) == str.length - end.length;
}
/**
* Returns true if 'str' ends with any of the arguments[2 -> n]
*/
dojo.string.endsWithAny = function(str /* , ... */) {
for(var i = 1; i < arguments.length; i++) {
if(dojo.string.endsWith(str, arguments[i])) {
return true;
}
}
return false;
}
/**
* Returns true if 'str' starts with 'start'
*/
dojo.string.startsWith = function(str, start, ignoreCase) {
if(ignoreCase) {
str = str.toLowerCase();
start = start.toLowerCase();
}
return str.indexOf(start) == 0;
}
/**
* Returns true if 'str' starts with any of the arguments[2 -> n]
*/
dojo.string.startsWithAny = function(str /* , ... */) {
for(var i = 1; i < arguments.length; i++) {
if(dojo.string.startsWith(str, arguments[i])) {
return true;
}
}
return false;
}
/**
* Returns true if 'str' contains any of the arguments 2 -> n
*/
dojo.string.has = function(str /* , ... */) {
for(var i = 1; i < arguments.length; i++) {
if(str.indexOf(arguments[i]) > -1){
return true;
}
}
return false;
}
dojo.string.normalizeNewlines = function (text,newlineChar) {
if (newlineChar == "\n") {
text = text.replace(/\r\n/g, "\n");
text = text.replace(/\r/g, "\n");
} else if (newlineChar == "\r") {
text = text.replace(/\r\n/g, "\r");
text = text.replace(/\n/g, "\r");
} else {
text = text.replace(/([^\r])\n/g, "$1\r\n");
text = text.replace(/\r([^\n])/g, "\r\n$1");
}
return text;
}
dojo.string.splitEscaped = function (str,charac) {
var components = [];
for (var i = 0, prevcomma = 0; i < str.length; i++) {
if (str.charAt(i) == '\\') { i++; continue; }
if (str.charAt(i) == charac) {
components.push(str.substring(prevcomma, i));
prevcomma = i + 1;
}
}
components.push(str.substr(prevcomma));
return components;
}