Simplify _.unescape to match the behavior of _.escape.

Former-commit-id: ec7f4cf9a6f44b1ba99f467c47d7e04d5596d76e
This commit is contained in:
John-David Dalton
2012-08-27 07:54:03 -07:00
parent 7de69a21c5
commit b63f25a1ae
4 changed files with 130 additions and 134 deletions

View File

@@ -1539,17 +1539,19 @@
QUnit.module('lodash.unescape');
(function() {
test('should perform a case-insensitive replacement of numeric character references', function() {
equal(_.unescape(''x''), "'x'");
});
var escaped = '<h1>Moe's famous "death by chocolate" brownies & cake<\/h1>',
unescaped = '<h1>Moe\'s famous "death by chocolate" brownies & cake<\/h1>';
test('should unescape entities in the correct order', function() {
equal(_.unescape('&amp;lt;'), '&lt;');
});
test('should unescape the proper entities', function() {
var escaped = '&lt;h1&gt;Moe&#x27;s famous &quot;death by chocolate&quot; brownies &amp; cake&lt;\/h1&gt;';
equal(_.unescape(escaped), '<h1>Moe\'s famous "death by chocolate" brownies & cake<\/h1>');
equal(_.unescape(escaped), unescaped);
});
test('should unescape the same characters escaped by `_.escape`', function() {
equal(_.unescape(_.escape(unescaped)), unescaped);
});
test('should return an empty string when passed `null` or `undefined`', function() {