Browse files

tested fix for node 0.6

  • Loading branch information...
1 parent c0b7ce1 commit 3e5e98e7e136007ea4271414f446d02cd34a786c @substack committed Feb 11, 2012
Showing with 26 additions and 7 deletions.
  1. +15 −0 index.js
  2. +11 −7 test/html.js
View
15 index.js
@@ -105,6 +105,21 @@ function difflet (opts, prev, next) {
if (inserted) unset('inserted');
});
}
+ else if (isRegExp(node)) {
+ this.block();
+
+ if (inserted) {
+ set('inserted');
+ write(node.toString());
+ unset('inserted');
+ }
+ else if (insertable && prevNode !== node) {
+ set('updated');
+ write(node.toString());
+ unset('updated');
+ }
+ else write(node.toString());
+ }
else if (typeof node === 'object'
&& node && typeof node.inspect === 'function') {
this.block();
View
18 test/html.js
@@ -1,5 +1,6 @@
var difflet = require('../');
var test = require('tap').test;
+var ent = require('ent');
test('html output', function (t) {
var tags = {
@@ -14,26 +15,29 @@ test('html output', function (t) {
stop : function (t, s) {
s.write('</' + tags[t] + '>');
},
+ write : function (buf) {
+ stream.write(ent.encode(buf));
+ }
});
function qqq () {}
- var s = diff(
+ var stream = diff(
{ yy : 6, zz : 5, a : [1,2,3], fn : qqq },
{
a : [ 1, 2, 3, [4], "z", /beep/, new Buffer([0,1,2]) ],
fn : 8,
b : [5,6,7]
}
);
- s.pipe(process.stdout, { end : false });
var data = ''
- s.on('data', function (buf) { data += buf });
- s.on('end', function () {
+ stream.on('data', function (buf) { data += buf });
+ stream.on('end', function () {
t.equal(data,
- '{"a":[1,2,3,<g>[4]</g>,<g>"z"</g>,<g>/beep/</g>,<g>'
- + '<Buffer 00 01 02></g>],"fn":<b>8</b>,'
- + '<g>"b":[5,6,7]</g>,<r>"yy":6,"zz":5</r>}'
+ '{&quot;a&quot;:[1,2,3,<g>[4]</g>,<g>&quot;z&quot;</g>,'
+ + '<g>/beep/</g>,<g>&lt;Buffer 00 01 02&gt;</g>],'
+ + '&quot;fn&quot;:<b>8</b>,<g>&quot;b&quot;:[5,6,7]</g>,'
+ + '<r>&quot;yy&quot;:6,&quot;zz&quot;:5</r>}'
);
t.end();
});

0 comments on commit 3e5e98e

Please sign in to comment.