var difflet = require('../');
var test = require('tap').test;
var ent = require('ent');
var tags = {
inserted : 'g',
updated : 'b',
deleted : 'r',
};
test('html output', function (t) {
t.plan(1);
var diff = difflet({
start : function (t, s) {
s.write('<' + tags[t] + '>');
},
stop : function (t, s) {
s.write('' + tags[t] + '>');
},
write : function (buf, s) {
s.write(ent.encode(buf));
}
});
var stream = diff(
{ yy : 6, zz : 5, a : [1,2,3], fn : function qqq () {} },
{
a : [ 1, 2, 3, [4], "z", /beep/, new Buffer([0,1,2]) ],
fn : function rrr () {},
b : [5,6,7]
}
);
var data = ''
stream.on('data', function (buf) { data += buf });
stream.on('end', function () {
t.equal(data,
'{"a":[1,2,3,[4],"z",'
+ '/beep/,<Buffer 00 01 02>],'
+ '"fn":[Function: rrr],'
+ '"b":[5,6,7],"yy":6,'
+ '"zz":5}'
);
t.end();
});
});
test('compare html output', function (t) {
t.plan(1);
var diff = difflet({
start : function (t, s) {
s.write('<' + tags[t] + '>');
},
stop : function (t, s) {
s.write('' + tags[t] + '>');
},
write : function (buf, s) {
s.write(ent.encode(buf));
}
});
var data = diff.compare(
{ yy : 6, zz : 5, a : [1,2,3], fn : function qqq () {} },
{
a : [ 1, 2, 3, [4], "z", /beep/, new Buffer([0,1,2]) ],
fn : function rrr () {},
b : [5,6,7]
}
);
t.equal(data,
'{"a":[1,2,3,[4],"z",'
+ '/beep/,<Buffer 00 01 02>],'
+ '"fn":[Function: rrr],'
+ '"b":[5,6,7],"yy":6,'
+ '"zz":5}'
);
t.end();
});