Collapsed StringPrettyPrinter into PrettyPrinter
We never really took advantage of the potential extensibility that the split provided, and the boundary between the two was getting muddied over time.
This commit is contained in:
@@ -3961,6 +3961,8 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
function PrettyPrinter() {
|
function PrettyPrinter() {
|
||||||
this.ppNestLevel_ = 0;
|
this.ppNestLevel_ = 0;
|
||||||
this.seen = [];
|
this.seen = [];
|
||||||
|
this.length = 0;
|
||||||
|
this.stringParts = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasCustomToString(value) {
|
function hasCustomToString(value) {
|
||||||
@@ -4044,31 +4046,15 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
return objKeys.length > length;
|
return objKeys.length > length;
|
||||||
};
|
};
|
||||||
|
|
||||||
PrettyPrinter.prototype.emitArray = j$.unimplementedMethod_;
|
PrettyPrinter.prototype.emitScalar = function(value) {
|
||||||
PrettyPrinter.prototype.emitSet = j$.unimplementedMethod_;
|
|
||||||
PrettyPrinter.prototype.emitMap = j$.unimplementedMethod_;
|
|
||||||
PrettyPrinter.prototype.emitObject = j$.unimplementedMethod_;
|
|
||||||
PrettyPrinter.prototype.emitScalar = j$.unimplementedMethod_;
|
|
||||||
PrettyPrinter.prototype.emitString = j$.unimplementedMethod_;
|
|
||||||
|
|
||||||
function StringPrettyPrinter() {
|
|
||||||
PrettyPrinter.call(this);
|
|
||||||
|
|
||||||
this.length = 0;
|
|
||||||
this.stringParts = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
j$.util.inherit(StringPrettyPrinter, PrettyPrinter);
|
|
||||||
|
|
||||||
StringPrettyPrinter.prototype.emitScalar = function(value) {
|
|
||||||
this.append(value);
|
this.append(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
StringPrettyPrinter.prototype.emitString = function(value) {
|
PrettyPrinter.prototype.emitString = function(value) {
|
||||||
this.append('\'' + value + '\'');
|
this.append('\'' + value + '\'');
|
||||||
};
|
};
|
||||||
|
|
||||||
StringPrettyPrinter.prototype.emitArray = function(array) {
|
PrettyPrinter.prototype.emitArray = function(array) {
|
||||||
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
||||||
this.append('Array');
|
this.append('Array');
|
||||||
return;
|
return;
|
||||||
@@ -4102,7 +4088,7 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
this.append(' ]');
|
this.append(' ]');
|
||||||
};
|
};
|
||||||
|
|
||||||
StringPrettyPrinter.prototype.emitSet = function(set) {
|
PrettyPrinter.prototype.emitSet = function(set) {
|
||||||
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
||||||
this.append('Set');
|
this.append('Set');
|
||||||
return;
|
return;
|
||||||
@@ -4122,7 +4108,7 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
this.append(' )');
|
this.append(' )');
|
||||||
};
|
};
|
||||||
|
|
||||||
StringPrettyPrinter.prototype.emitMap = function(map) {
|
PrettyPrinter.prototype.emitMap = function(map) {
|
||||||
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
||||||
this.append('Map');
|
this.append('Map');
|
||||||
return;
|
return;
|
||||||
@@ -4142,7 +4128,7 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
this.append(' )');
|
this.append(' )');
|
||||||
};
|
};
|
||||||
|
|
||||||
StringPrettyPrinter.prototype.emitObject = function(obj) {
|
PrettyPrinter.prototype.emitObject = function(obj) {
|
||||||
var ctor = obj.constructor,
|
var ctor = obj.constructor,
|
||||||
constructorName;
|
constructorName;
|
||||||
|
|
||||||
@@ -4175,7 +4161,7 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
this.append(' })');
|
this.append(' })');
|
||||||
};
|
};
|
||||||
|
|
||||||
StringPrettyPrinter.prototype.emitTypedArray = function(arr) {
|
PrettyPrinter.prototype.emitTypedArray = function(arr) {
|
||||||
var constructorName = j$.fnNameFor(arr.constructor),
|
var constructorName = j$.fnNameFor(arr.constructor),
|
||||||
limitedArray = Array.prototype.slice.call(arr, 0, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH),
|
limitedArray = Array.prototype.slice.call(arr, 0, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH),
|
||||||
itemsString = Array.prototype.join.call(limitedArray, ', ');
|
itemsString = Array.prototype.join.call(limitedArray, ', ');
|
||||||
@@ -4187,7 +4173,7 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
this.append(constructorName + ' [ ' + itemsString + ' ]');
|
this.append(constructorName + ' [ ' + itemsString + ' ]');
|
||||||
};
|
};
|
||||||
|
|
||||||
StringPrettyPrinter.prototype.formatProperty = function(obj, property, isGetter) {
|
PrettyPrinter.prototype.formatProperty = function(obj, property, isGetter) {
|
||||||
this.append(property);
|
this.append(property);
|
||||||
this.append(': ');
|
this.append(': ');
|
||||||
if (isGetter) {
|
if (isGetter) {
|
||||||
@@ -4197,7 +4183,7 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
StringPrettyPrinter.prototype.append = function(value) {
|
PrettyPrinter.prototype.append = function(value) {
|
||||||
var result = truncate(value, j$.MAX_PRETTY_PRINT_CHARS - this.length);
|
var result = truncate(value, j$.MAX_PRETTY_PRINT_CHARS - this.length);
|
||||||
this.length += result.value.length;
|
this.length += result.value.length;
|
||||||
this.stringParts.push(result.value);
|
this.stringParts.push(result.value);
|
||||||
@@ -4207,6 +4193,7 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
function truncate(s, maxlen) {
|
function truncate(s, maxlen) {
|
||||||
if (s.length <= maxlen) {
|
if (s.length <= maxlen) {
|
||||||
return { value: s, truncated: false };
|
return { value: s, truncated: false };
|
||||||
@@ -4253,9 +4240,9 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
return extraKeys;
|
return extraKeys;
|
||||||
}
|
}
|
||||||
return function(value) {
|
return function(value) {
|
||||||
var stringPrettyPrinter = new StringPrettyPrinter();
|
var prettyPrinter = new PrettyPrinter();
|
||||||
stringPrettyPrinter.format(value);
|
prettyPrinter.format(value);
|
||||||
return stringPrettyPrinter.stringParts.join('');
|
return prettyPrinter.stringParts.join('');
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
function PrettyPrinter() {
|
function PrettyPrinter() {
|
||||||
this.ppNestLevel_ = 0;
|
this.ppNestLevel_ = 0;
|
||||||
this.seen = [];
|
this.seen = [];
|
||||||
|
this.length = 0;
|
||||||
|
this.stringParts = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasCustomToString(value) {
|
function hasCustomToString(value) {
|
||||||
@@ -86,31 +88,15 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
return objKeys.length > length;
|
return objKeys.length > length;
|
||||||
};
|
};
|
||||||
|
|
||||||
PrettyPrinter.prototype.emitArray = j$.unimplementedMethod_;
|
PrettyPrinter.prototype.emitScalar = function(value) {
|
||||||
PrettyPrinter.prototype.emitSet = j$.unimplementedMethod_;
|
|
||||||
PrettyPrinter.prototype.emitMap = j$.unimplementedMethod_;
|
|
||||||
PrettyPrinter.prototype.emitObject = j$.unimplementedMethod_;
|
|
||||||
PrettyPrinter.prototype.emitScalar = j$.unimplementedMethod_;
|
|
||||||
PrettyPrinter.prototype.emitString = j$.unimplementedMethod_;
|
|
||||||
|
|
||||||
function StringPrettyPrinter() {
|
|
||||||
PrettyPrinter.call(this);
|
|
||||||
|
|
||||||
this.length = 0;
|
|
||||||
this.stringParts = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
j$.util.inherit(StringPrettyPrinter, PrettyPrinter);
|
|
||||||
|
|
||||||
StringPrettyPrinter.prototype.emitScalar = function(value) {
|
|
||||||
this.append(value);
|
this.append(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
StringPrettyPrinter.prototype.emitString = function(value) {
|
PrettyPrinter.prototype.emitString = function(value) {
|
||||||
this.append('\'' + value + '\'');
|
this.append('\'' + value + '\'');
|
||||||
};
|
};
|
||||||
|
|
||||||
StringPrettyPrinter.prototype.emitArray = function(array) {
|
PrettyPrinter.prototype.emitArray = function(array) {
|
||||||
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
||||||
this.append('Array');
|
this.append('Array');
|
||||||
return;
|
return;
|
||||||
@@ -144,7 +130,7 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
this.append(' ]');
|
this.append(' ]');
|
||||||
};
|
};
|
||||||
|
|
||||||
StringPrettyPrinter.prototype.emitSet = function(set) {
|
PrettyPrinter.prototype.emitSet = function(set) {
|
||||||
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
||||||
this.append('Set');
|
this.append('Set');
|
||||||
return;
|
return;
|
||||||
@@ -164,7 +150,7 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
this.append(' )');
|
this.append(' )');
|
||||||
};
|
};
|
||||||
|
|
||||||
StringPrettyPrinter.prototype.emitMap = function(map) {
|
PrettyPrinter.prototype.emitMap = function(map) {
|
||||||
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
|
||||||
this.append('Map');
|
this.append('Map');
|
||||||
return;
|
return;
|
||||||
@@ -184,7 +170,7 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
this.append(' )');
|
this.append(' )');
|
||||||
};
|
};
|
||||||
|
|
||||||
StringPrettyPrinter.prototype.emitObject = function(obj) {
|
PrettyPrinter.prototype.emitObject = function(obj) {
|
||||||
var ctor = obj.constructor,
|
var ctor = obj.constructor,
|
||||||
constructorName;
|
constructorName;
|
||||||
|
|
||||||
@@ -217,7 +203,7 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
this.append(' })');
|
this.append(' })');
|
||||||
};
|
};
|
||||||
|
|
||||||
StringPrettyPrinter.prototype.emitTypedArray = function(arr) {
|
PrettyPrinter.prototype.emitTypedArray = function(arr) {
|
||||||
var constructorName = j$.fnNameFor(arr.constructor),
|
var constructorName = j$.fnNameFor(arr.constructor),
|
||||||
limitedArray = Array.prototype.slice.call(arr, 0, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH),
|
limitedArray = Array.prototype.slice.call(arr, 0, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH),
|
||||||
itemsString = Array.prototype.join.call(limitedArray, ', ');
|
itemsString = Array.prototype.join.call(limitedArray, ', ');
|
||||||
@@ -229,7 +215,7 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
this.append(constructorName + ' [ ' + itemsString + ' ]');
|
this.append(constructorName + ' [ ' + itemsString + ' ]');
|
||||||
};
|
};
|
||||||
|
|
||||||
StringPrettyPrinter.prototype.formatProperty = function(obj, property, isGetter) {
|
PrettyPrinter.prototype.formatProperty = function(obj, property, isGetter) {
|
||||||
this.append(property);
|
this.append(property);
|
||||||
this.append(': ');
|
this.append(': ');
|
||||||
if (isGetter) {
|
if (isGetter) {
|
||||||
@@ -239,7 +225,7 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
StringPrettyPrinter.prototype.append = function(value) {
|
PrettyPrinter.prototype.append = function(value) {
|
||||||
var result = truncate(value, j$.MAX_PRETTY_PRINT_CHARS - this.length);
|
var result = truncate(value, j$.MAX_PRETTY_PRINT_CHARS - this.length);
|
||||||
this.length += result.value.length;
|
this.length += result.value.length;
|
||||||
this.stringParts.push(result.value);
|
this.stringParts.push(result.value);
|
||||||
@@ -249,6 +235,7 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
function truncate(s, maxlen) {
|
function truncate(s, maxlen) {
|
||||||
if (s.length <= maxlen) {
|
if (s.length <= maxlen) {
|
||||||
return { value: s, truncated: false };
|
return { value: s, truncated: false };
|
||||||
@@ -295,8 +282,8 @@ getJasmineRequireObj().pp = function(j$) {
|
|||||||
return extraKeys;
|
return extraKeys;
|
||||||
}
|
}
|
||||||
return function(value) {
|
return function(value) {
|
||||||
var stringPrettyPrinter = new StringPrettyPrinter();
|
var prettyPrinter = new PrettyPrinter();
|
||||||
stringPrettyPrinter.format(value);
|
prettyPrinter.format(value);
|
||||||
return stringPrettyPrinter.stringParts.join('');
|
return prettyPrinter.stringParts.join('');
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user