本文整理汇总了TypeScript中wed/dloc.DLocRoot类的典型用法代码示例。如果您正苦于以下问题:TypeScript DLocRoot类的具体用法?TypeScript DLocRoot怎么用?TypeScript DLocRoot使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DLocRoot类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: it
it("is equivalent to nodeToPath on a data tree", () => {
const dataRootObj = new DLocRoot(xmlDoc);
linkTrees(xmlDoc.firstElementChild!, root.firstElementChild!);
let targetDataNode = xmlDoc.getElementsByTagName("quote")[0];
const phantomWrapTemplate = "<span class='_phantom_wrap'></span>";
$($.data(targetDataNode, "wed_mirror_node"))
.wrap(phantomWrapTemplate)
.after("<span class='_phantom'>Boo</span>Blip")
.wrap(phantomWrapTemplate);
const dataNode = targetDataNode.parentNode as Element;
// Wrap twice for good measure.
$($.data(dataNode, "wed_mirror_node"))
.wrap(phantomWrapTemplate)
.wrap(phantomWrapTemplate);
targetDataNode = xmlDoc.getElementsByTagName("quote")[1];
const targetGuiNode = $.data(targetDataNode, "wed_mirror_node");
const guiPath = rootObj.nodeToPath(targetGuiNode);
const dataPath = dataRootObj.nodeToPath(targetDataNode);
// Both paths should be equal.
assert.equal(guiPath, dataPath);
// It should also be reversible.
assert.equal(rootObj.pathToNode(guiPath), targetGuiNode);
});
开发者ID:lddubeau,项目名称:wed,代码行数:28,代码来源:guiroot-test.ts
示例2: describe
describe("dloc", () => {
let $root: JQuery;
let root: HTMLElement;
let rootObj: DLocRoot;
let encodedType: string;
before(() =>
new DataProvider("/base/build/standalone/lib/tests/dloc_test_data/")
.getText("source_converted.xml")
.then((sourceXML) => {
root = document.createElement("div");
document.body.appendChild(root);
$root = $(root);
const parser = new window.DOMParser();
const xmlDoc = parser.parseFromString(sourceXML, "text/xml");
const htmlTree = convert.toHTMLTree(window.document,
xmlDoc.firstElementChild!);
root.appendChild(htmlTree);
rootObj = new DLocRoot(root);
encodedType = encodeAttrName("type");
}));
after(() => {
document.body.removeChild(root);
});
afterEach(() => {
// Some tests add elements with the class __test to the DOM tree.
// Proactively delete them here.
$(".__test").remove();
});
function makeAttributeNodeCase(): { attrLoc: DLoc; loc: DLoc } {
const a = defined($(".quote")[0].getAttributeNode(encodedType));
const b = defined($(".body .p")[1]);
const attrLoc = defined(DLoc.makeDLoc(root, a, 0));
const loc = attrLoc.make(b, 1);
return { attrLoc, loc };
}
function makeInvalidCase(): { loc: DLoc; invalid: DLoc } {
$root.append("<div class='__test'></div>");
const t = defined($(".__test")[0]);
assert.equal(t.nodeType, Node.ELEMENT_NODE);
const b = defined($(".body .p")[1]);
const loc = defined(DLoc.makeDLoc(root, b, 1));
const invalid = loc.make(t, 0);
t.parentNode!.removeChild(t);
assert.isFalse(invalid.isValid());
return { loc, invalid };
}
describe("DLocRoot", () => {
it("marks the root", () => {
assert.equal(findRoot(root), rootObj);
});
it("fails if the node is already marked", () => {
assert.throws(() => {
new DLocRoot(root);
},
Error,
"node already marked as root");
});
describe("nodeToPath", () => {
it("returns an empty string on root", () => {
assert.equal(rootObj.nodeToPath(root), "");
});
it("returns a correct path on text node", () => {
const node = defined($root.find(".title")[0].childNodes[0]);
assert.equal(rootObj.nodeToPath(node), "0/0/0/0/0/0");
});
it("returns a correct path on later text node", () => {
const node = defined($root.find(".body>.p")[1].childNodes[2]);
assert.equal(rootObj.nodeToPath(node), "0/1/0/1/2");
});
it("returns a correct path on attribute", () => {
const node =
defined($root.find(".body>.p")[1].attributes.getNamedItem("class"));
assert.equal(rootObj.nodeToPath(node), "0/1/0/1/@class");
});
it("fails on a node which is not a descendant of its root",
() => {
const node = defined($("body")[0]);
assert.throws(rootObj.nodeToPath.bind(rootObj, node),
Error, "node is not a descendant of root");
});
it("fails on invalid node", () => {
assert.throws(rootObj.nodeToPath.bind(rootObj, null),
Error, "invalid node parameter");
assert.throws(rootObj.nodeToPath.bind(rootObj, undefined),
Error, "invalid node parameter");
});
//.........这里部分代码省略.........
开发者ID:lddubeau,项目名称:wed,代码行数:101,代码来源:dloc-test.ts
示例3: it
it("accepts more than one digit per path step", () => {
// There was a stupid bug in an earlier version which would make this
// fail with an exception complaining that the path was malformed due to
// the presence of "10". The null return value is fine since there is no
// such element, but at least it should not generate an exception.
assert.equal(rootObj.pathToNode("0/10"), null);
});
开发者ID:lddubeau,项目名称:wed,代码行数:7,代码来源:dloc-test.ts
注:本文中的wed/dloc.DLocRoot类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论