compare flat-dom output against hyperjson
This commit is contained in:
parent
e2052b4510
commit
fb91f5df76
@ -132,6 +132,40 @@ define([
|
|||||||
strungJSON(orig);
|
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
|
// check that old hashes parse correctly
|
||||||
assert(function (cb) {
|
assert(function (cb) {
|
||||||
//if (1) { return cb(true); } // TODO(cjd): This is a test failure which is a known bug
|
//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;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
var identity = function (x) { return x; };
|
Flat.fromDOM = function (dom, predicate, filter) {
|
||||||
Flat.fromDOM = function (dom) {
|
|
||||||
var data = {
|
var data = {
|
||||||
map: {},
|
map: {},
|
||||||
};
|
};
|
||||||
@ -34,14 +33,21 @@ define([], function () {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
if (!el || !el.attributes) { return; }
|
if (!el || !el.attributes) { return; }
|
||||||
|
if (predicate) {
|
||||||
|
if (!predicate(el)) { return; } // shortcircuit
|
||||||
|
}
|
||||||
|
|
||||||
id = uid();
|
id = uid();
|
||||||
data.map[id] = [
|
var temp = [
|
||||||
el.tagName,
|
el.tagName,
|
||||||
getAttrs(el),
|
getAttrs(el),
|
||||||
slice(el.childNodes).map(function (e) {
|
slice(el.childNodes).map(function (e) {
|
||||||
return process(e);
|
return process(e);
|
||||||
}).filter(identity)
|
}).filter(Boolean)
|
||||||
];
|
];
|
||||||
|
|
||||||
|
data.map[id] = filter? filter(temp): temp;
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user