當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript dloc.DLocRoot類代碼示例

本文整理匯總了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;未經允許,請勿轉載。