compare flat-dom output against hyperjson

pull/1/head
ansuz 7 years ago
parent e2052b4510
commit fb91f5df76

@ -132,6 +132,40 @@ define([
strungJSON(orig);
});
HTML_list.forEach(function (sel) {
var el = $(sel)[0];
var pred = function (el) {
if (el.nodeName === 'DIV') {
return true;
}
};
var filter = function (x) {
console.log(x);
if (x[1]['class']) {
x[1]['class'] = x[1]['class'].replace(/cke/g, '');
}
return x;
};
assert(function (cb) {
// FlatDOM output
var map = Flat.fromDOM(el, pred, filter);
// Hyperjson output
var hj = Hyperjson.fromDOM(el, pred, filter);
var x = Flat.toDOM(map);
var y = Hyperjson.toDOM(hj);
console.error(x.outerHTML);
console.error(y.outerHTML);
cb(x.outerHTML === y.outerHTML);
}, "Test equality of FlatDOM and HyperJSON");
});
// check that old hashes parse correctly
assert(function (cb) {
//if (1) { return cb(true); } // TODO(cjd): This is a test failure which is a known bug

@ -17,8 +17,7 @@ define([], function () {
return data;
};
var identity = function (x) { return x; };
Flat.fromDOM = function (dom) {
Flat.fromDOM = function (dom, predicate, filter) {
var data = {
map: {},
};
@ -34,14 +33,21 @@ define([], function () {
return id;
}
if (!el || !el.attributes) { return; }
if (predicate) {
if (!predicate(el)) { return; } // shortcircuit
}
id = uid();
data.map[id] = [
var temp = [
el.tagName,
getAttrs(el),
slice(el.childNodes).map(function (e) {
return process(e);
}).filter(identity)
}).filter(Boolean)
];
data.map[id] = filter? filter(temp): temp;
return id;
};

Loading…
Cancel
Save