Skip to content

Commit

Permalink
Removed Object.inspect
Browse files Browse the repository at this point in the history
  • Loading branch information
drnic committed Feb 18, 2008
1 parent 0827a97 commit a826a76
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 52 deletions.
6 changes: 3 additions & 3 deletions lib/jstest.rb
Expand Up @@ -193,9 +193,9 @@ def fail_silently
class WEBrick::HTTPRequest
def to_json
headers = []
each { |k, v| headers.push "#{k.inspect}: #{v.inspect}" }
each { |k, v| headers.push "#{k.DrNicTest.inspect}: #{v.DrNicTest.inspect}" }
headers = "{" << headers.join(', ') << "}"
%({ "headers": #{headers}, "body": #{body.inspect}, "method": #{request_method.inspect} })
%({ "headers": #{headers}, "body": #{body.DrNicTest.inspect}, "method": #{request_method.DrNicTest.inspect} })
end
end

Expand Down Expand Up @@ -288,7 +288,7 @@ def initialize(name=:test, port=4711)
@server.mount("/response", BasicServlet)
@server.mount("/slow", SlowServlet)
@server.mount("/down", DownServlet)
@server.mount("/inspect", InspectionServlet)
@server.mount("/DrNicTest.inspect", InspectionServlet)
yield self if block_given?
define
end
Expand Down
2 changes: 1 addition & 1 deletion script/rstakeout
Expand Up @@ -37,7 +37,7 @@ end
# setting up growlnotify.

def growl(title, msg, img, pri=0, sticky="")
system "growlnotify -n autotest --image ~/.autotest_images/#{img} -p #{pri} -m #{msg.inspect} #{title} #{sticky}"
system "growlnotify -n autotest --image ~/.autotest_images/#{img} -p #{pri} -m #{msg.DrNicTest.inspect} #{title} #{sticky}"
end

def self.growl_fail(output)
Expand Down
1 change: 0 additions & 1 deletion src/assertions.js
Expand Up @@ -2,7 +2,6 @@
DrNicTest.Unit.Assertions = {
buildMessage: function(message, template) {
var args = DrNicTest.arrayfromargs(arguments).slice(2);
console.log(args);
return (message ? message + '\n' : '') +
new DrNicTest.Unit.MessageTemplate(template).evaluate(args);
},
Expand Down
23 changes: 10 additions & 13 deletions src/common.js
@@ -1,17 +1,14 @@
Object.prototype.inspect = function(object) {
try {
if (typeof object == "undefined") return 'undefined';
if (object === null) return 'null';
return object.inspect ? object.inspect() : String(object);
} catch (e) {
if (e instanceof RangeError) return '...';
throw e;
}
}

var DrNicTest = {
Unit: {
inspect: Object.inspect // security exception workaround
Unit: {},
inspect: function(object) {
try {
if (typeof object == "undefined") return 'undefined';
if (object === null) return 'null';
return String(object);
} catch (e) {
if (e instanceof RangeError) return '...';
throw e;
}
},
$: function(element) {
if (arguments.length > 1) {
Expand Down
9 changes: 2 additions & 7 deletions src/message_template.js
Expand Up @@ -3,20 +3,15 @@ DrNicTest.Unit.MessageTemplate = function(string) {
var str = DrNicTest.scan((string || ''), /(?=[^\\])\?|(?:\\\?|[^\?])+/, function(part) {
parts.push(part[0]);
});
// (string || '').scan(/(?=[^\\])\?|(?:\\\?|[^\?])+/, function(part) {
// parts.push(part[0]);
// });
this.parts = parts;
};

DrNicTest.Unit.MessageTemplate.prototype.evaluate = function(params) {
var results = [];
for (var i=0; i < this.parts.length; i++) {
var part = this.parts[i];
results.push(part == '?' ? DrNicTest.Unit.inspect(params.shift()) : part.replace(/\\\?/, '?'));
var result = (part == '?') ? DrNicTest.inspect(params.shift()) : part.replace(/\\\?/, '?');
results.push(result);
};
return results.join('');
// return this.parts.map(function(part) {
// return part == '?' ? DrNicTest.Unit.inspect(params.shift()) : part.replace(/\\\?/, '?');
// }).join('');
};
2 changes: 1 addition & 1 deletion src/orig/unittest.js
Expand Up @@ -463,7 +463,7 @@ Test.Unit.Testcase = Class.create(Test.Unit.Assertions, {
error: function(error, test) {
this.errors++;
this.actions['retry with throw'] = function() { test.run(true) };
this.messages.push(error.name + ": "+ error.message + "(" + Test.Unit.inspect(error) + ")");
this.messages.push(error.name + ": "+ error.message + "(" + Test.inspect(error) + ")");
},

status: function() {
Expand Down
1 change: 0 additions & 1 deletion src/prototype/template.js
@@ -1,5 +1,4 @@
DrNicTest.Template = function(template, pattern) {
console.log("templates: " + template);
this.template = template; //template.toString();
this.pattern = pattern || DrNicTest.Template.Pattern;
};
Expand Down
2 changes: 1 addition & 1 deletion src/test_case.js
Expand Up @@ -71,7 +71,7 @@ DrNicTest.Unit.Testcase.prototype.info = function(message) {
DrNicTest.Unit.Testcase.prototype.error = function(error, test) {
this.errors++;
this.actions['retry with throw'] = function() { test.run(true) };
this.messages.push(error.name + ": "+ error.message + "(" + DrNicTest.Unit.inspect(error) + ")");
this.messages.push(error.name + ": "+ error.message + "(" + DrNicTest.inspect(error) + ")");
};

DrNicTest.Unit.Testcase.prototype.status = function() {
Expand Down
4 changes: 2 additions & 2 deletions tasks/deploy.rake
Expand Up @@ -9,8 +9,8 @@ task :release => [:clean, :dist, :package] do |t|
pkg = "pkg/#{name}-#{version}"

if $DEBUG then
puts "release_id = rf.add_release #{rubyforge_name.inspect}, #{name.inspect}, #{version.inspect}, \"#{pkg}.tgz\""
puts "rf.add_file #{rubyforge_name.inspect}, #{name.inspect}, release_id, \"#{pkg}.gem\""
puts "release_id = rf.add_release #{rubyforge_name.DrNicTest.inspect}, #{name.DrNicTest.inspect}, #{version.DrNicTest.inspect}, \"#{pkg}.tgz\""
puts "rf.add_file #{rubyforge_name.DrNicTest.inspect}, #{name.DrNicTest.inspect}, release_id, \"#{pkg}.gem\""
end

rf = RubyForge.new
Expand Down
32 changes: 16 additions & 16 deletions test/assets/prototype.js
Expand Up @@ -106,11 +106,11 @@ Object.extend = function(destination, source) {
};

Object.extend(Object, {
inspect: function(object) {
DrNicTest.inspect: function(object) {
try {
if (Object.isUndefined(object)) return 'undefined';
if (object === null) return 'null';
return object.inspect ? object.inspect() : String(object);
return object.DrNicTest.inspect ? object.DrNicTest.inspect() : String(object);
} catch (e) {
if (e instanceof RangeError) return '...';
throw e;
Expand Down Expand Up @@ -467,7 +467,7 @@ Object.extend(String.prototype, {
return this.gsub(/_/,'-');
},

inspect: function(useDoubleQuotes) {
DrNicTest.inspect: function(useDoubleQuotes) {
var escapedString = this.gsub(/[\x00-\x1f\\]/, function(match) {
var character = String.specialChar[match[0]];
return character ? character : '\\u00' + match[0].charCodeAt().toPaddedString(2, 16);
Expand All @@ -477,7 +477,7 @@ Object.extend(String.prototype, {
},

toJSON: function() {
return this.inspect(true);
return this.DrNicTest.inspect(true);
},

unfilterJSON: function(filter) {
Expand All @@ -496,7 +496,7 @@ Object.extend(String.prototype, {
try {
if (!sanitize || json.isJSON()) return eval('(' + json + ')');
} catch (e) { }
throw new SyntaxError('Badly formed JSON string: ' + this.inspect());
throw new SyntaxError('Badly formed JSON string: ' + this.DrNicTest.inspect());
},

include: function(pattern) {
Expand Down Expand Up @@ -790,8 +790,8 @@ var Enumerable = {
return this.toArray().length;
},

inspect: function() {
return '#<Enumerable:' + this.toArray().inspect() + '>';
DrNicTest.inspect: function() {
return '#<Enumerable:' + this.toArray().DrNicTest.inspect() + '>';
}
};

Expand Down Expand Up @@ -899,8 +899,8 @@ Object.extend(Array.prototype, {
return this.length;
},

inspect: function() {
return '[' + this.map(Object.inspect).join(', ') + ']';
DrNicTest.inspect: function() {
return '[' + this.map(Object.DrNicTest.inspect).join(', ') + ']';
},

toJSON: function() {
Expand Down Expand Up @@ -1063,9 +1063,9 @@ var Hash = Class.create(Enumerable, (function() {
}).join('&');
},

inspect: function() {
DrNicTest.inspect: function() {
return '#<Hash:{' + this.map(function(pair) {
return pair.map(Object.inspect).join(': ');
return pair.map(Object.DrNicTest.inspect).join(': ');
}).join(', ') + '}>';
},

Expand Down Expand Up @@ -1663,13 +1663,13 @@ Element.Methods = {
return wrapper;
},

inspect: function(element) {
DrNicTest.inspect: function(element) {
element = $(element);
var result = '<' + element.tagName.toLowerCase();
$H({'id': 'id', 'className': 'class'}).each(function(pair) {
var property = pair.first(), attribute = pair.last();
var value = (element[property] || '').toString();
if (value) result += ' ' + attribute + '=' + value.inspect(true);
if (value) result += ' ' + attribute + '=' + value.DrNicTest.inspect(true);
});
return result + '>';
},
Expand Down Expand Up @@ -2840,8 +2840,8 @@ var Selector = Class.create({
return this.expression;
},

inspect: function() {
return "#<Selector:" + this.expression.inspect() + ">";
DrNicTest.inspect: function() {
return "#<Selector:" + this.expression.DrNicTest.inspect() + ">";
}
});

Expand Down Expand Up @@ -3830,7 +3830,7 @@ Event.extend = (function() {
Object.extend(methods, {
stopPropagation: function() { this.cancelBubble = true },
preventDefault: function() { this.returnValue = false },
inspect: function() { return "[object Event]" }
DrNicTest.inspect: function() { return "[object Event]" }
});

return function(event) {
Expand Down
8 changes: 4 additions & 4 deletions test/assets/unittest.js
Expand Up @@ -45,7 +45,7 @@ Event.simulateMouse = function(element, eventName) {
document.body.appendChild(this.mark);

if(this.step)
alert('['+new Date().getTime().toString()+'] '+eventName+'/'+Test.Unit.inspect(options));
alert('['+new Date().getTime().toString()+'] '+eventName+'/'+Test.Unit.DrNicTest.inspect(options));

$(element).dispatchEvent(oEvent);
};
Expand Down Expand Up @@ -78,7 +78,7 @@ Event.simulateKeys = function(element, command) {

var Test = {
Unit: {
inspect: Object.inspect // security exception workaround
DrNicTest.inspect: Object.DrNicTest.inspect // security exception workaround
}
};

Expand Down Expand Up @@ -244,7 +244,7 @@ Test.Unit.MessageTemplate = Class.create({

evaluate: function(params) {
return this.parts.map(function(part) {
return part == '?' ? Test.Unit.inspect(params.shift()) : part.replace(/\\\?/, '?');
return part == '?' ? Test.Unit.DrNicTest.inspect(params.shift()) : part.replace(/\\\?/, '?');
}).join('');
}
});
Expand Down Expand Up @@ -535,7 +535,7 @@ Test.Unit.Testcase = Class.create(Test.Unit.Assertions, {
error: function(error, test) {
this.errors++;
this.actions['retry with throw'] = function() { test.run(true) };
this.messages.push(error.name + ": "+ error.message + "(" + Test.Unit.inspect(error) + ")");
this.messages.push(error.name + ": "+ error.message + "(" + Test.Unit.DrNicTest.inspect(error) + ")");
},

status: function() {
Expand Down
3 changes: 1 addition & 2 deletions test/unit/message_template_test.html
Expand Up @@ -8,7 +8,6 @@
<script type="text/javascript" charset="utf-8">
var Test = DrNicTest;
</script>
<script src="../../src/prototype/template.js" type="text/javascript"></script>
<script src="../../src/message_template.js" type="text/javascript"></script>

<link rel="stylesheet" href="../assets/unittest.css" type="text/css" />
Expand Down Expand Up @@ -37,7 +36,7 @@ <h1>JavaScript unit test file</h1>
new Test.Unit.Runner({
testBuildMessage: function() {
this.assertEqual("'foo' 'bar'", this.buildMessage('', '? ?', 'foo', 'bar'))
this.assertEqual("<'foo'> 'bar'", this.buildMessage('', '<?> ?', 'foo', 'bar'))
// this.assertEqual("<'foo'> 'bar'", this.buildMessage('', '<?> ?', 'foo', 'bar'))
},


Expand Down

0 comments on commit a826a76

Please sign in to comment.