+ +
+And
+ +diff --git a/src/browser/dom/node.zig b/src/browser/dom/node.zig index 5dc171b4..35f91208 100644 --- a/src/browser/dom/node.zig +++ b/src/browser/dom/node.zig @@ -631,262 +631,7 @@ pub const Node = struct { }; const testing = @import("../../testing.zig"); -test "Browser.DOM.node" { - var runner = try testing.jsRunner(testing.tracking_allocator, .{}); - defer runner.deinit(); - - { - var err_out: ?[]const u8 = null; - try runner.exec( - \\ function trimAndReplace(str) { - \\ str = str.replace(/(\r\n|\n|\r)/gm,''); - \\ str = str.replace(/\s+/g, ' '); - \\ str = str.trim(); - \\ return str; - \\ } - , "trimAndReplace", &err_out); - } - - try runner.testCases(&.{ - .{ "document.body.compareDocumentPosition(document.firstChild); ", "10" }, - .{ "document.getElementById(\"para-empty\").compareDocumentPosition(document.getElementById(\"content\"));", "10" }, - .{ "document.getElementById(\"content\").compareDocumentPosition(document.getElementById(\"para-empty\"));", "20" }, - .{ "document.getElementById(\"link\").compareDocumentPosition(document.getElementById(\"link\"));", "0" }, - .{ "document.getElementById(\"para-empty\").compareDocumentPosition(document.getElementById(\"link\"));", "2" }, - .{ "document.getElementById(\"link\").compareDocumentPosition(document.getElementById(\"para-empty\"));", "4" }, - }, .{}); - - try runner.testCases(&.{ - .{ "document.getElementById('content').getRootNode().__proto__.constructor.name", "HTMLDocument" }, - }, .{}); - - try runner.testCases(&.{ - // for next test cases - .{ "let content = document.getElementById('content')", "undefined" }, - .{ "let link = document.getElementById('link')", "undefined" }, - .{ "let first_child = content.firstChild.nextSibling", "undefined" }, // nextSibling because of line return \n - - .{ "let body_first_child = document.body.firstChild", "undefined" }, - .{ "body_first_child.localName", "div" }, - .{ "body_first_child.__proto__.constructor.name", "HTMLDivElement" }, - .{ "document.getElementById('para-empty').firstChild.firstChild", "null" }, - }, .{}); - - try runner.testCases(&.{ - .{ "let last_child = content.lastChild.previousSibling", "undefined" }, // previousSibling because of line return \n - .{ "last_child.__proto__.constructor.name", "Comment" }, - }, .{}); - - try runner.testCases(&.{ - .{ "let next_sibling = link.nextSibling.nextSibling", "undefined" }, - .{ "next_sibling.localName", "p" }, - .{ "next_sibling.__proto__.constructor.name", "HTMLParagraphElement" }, - .{ "content.nextSibling.nextSibling", "null" }, - }, .{}); - - try runner.testCases(&.{ - .{ "let prev_sibling = document.getElementById('para-empty').previousSibling.previousSibling", "undefined" }, - .{ "prev_sibling.localName", "a" }, - .{ "prev_sibling.__proto__.constructor.name", "HTMLAnchorElement" }, - .{ "content.previousSibling", "null" }, - }, .{}); - - try runner.testCases(&.{ - .{ "let parent = document.getElementById('para').parentElement", "undefined" }, - .{ "parent.localName", "div" }, - .{ "parent.__proto__.constructor.name", "HTMLDivElement" }, - .{ "let h = content.parentElement.parentElement", "undefined" }, - .{ "h.parentElement", "null" }, - .{ "h.parentNode.__proto__.constructor.name", "HTMLDocument" }, - }, .{}); - - try runner.testCases(&.{ - .{ "first_child.nodeName === 'A'", "true" }, - .{ "link.firstChild.nodeName === '#text'", "true" }, - .{ "last_child.nodeName === '#comment'", "true" }, - .{ "document.nodeName === '#document'", "true" }, - }, .{}); - - try runner.testCases(&.{ - .{ "first_child.nodeType === 1", "true" }, - .{ "link.firstChild.nodeType === 3", "true" }, - .{ "last_child.nodeType === 8", "true" }, - .{ "document.nodeType === 9", "true" }, - }, .{}); - - try runner.testCases(&.{ - .{ "let owner = content.ownerDocument", "undefined" }, - .{ "owner.__proto__.constructor.name", "HTMLDocument" }, - .{ "document.ownerDocument", "null" }, - .{ "let owner2 = document.createElement('div').ownerDocument", "undefined" }, - .{ "owner2.__proto__.constructor.name", "HTMLDocument" }, - }, .{}); - - try runner.testCases(&.{ - .{ "content.isConnected", "true" }, - .{ "document.isConnected", "true" }, - .{ "const connDiv = document.createElement('div')", null }, - .{ "connDiv.isConnected", "false" }, - .{ "const connParentDiv = document.createElement('div')", null }, - .{ "connParentDiv.appendChild(connDiv)", null }, - .{ "connDiv.isConnected", "false" }, - .{ "content.appendChild(connParentDiv)", null }, - .{ "connDiv.isConnected", "true" }, - }, .{}); - - try runner.testCases(&.{ - .{ "last_child.nodeValue === 'comment'", "true" }, - .{ "link.nodeValue === null", "true" }, - .{ "let text = link.firstChild", "undefined" }, - .{ "text.nodeValue === 'OK'", "true" }, - .{ "text.nodeValue = 'OK modified'", "OK modified" }, - .{ "text.nodeValue === 'OK modified'", "true" }, - .{ "link.nodeValue = 'nothing'", "nothing" }, - }, .{}); - - try runner.testCases(&.{ - .{ "text.textContent === 'OK modified'", "true" }, - .{ "trimAndReplace(content.textContent) === 'OK modified And'", "true" }, - .{ "text.textContent = 'OK'", "OK" }, - .{ "text.textContent", "OK" }, - .{ "trimAndReplace(document.getElementById('para-empty').textContent)", "" }, - .{ "document.getElementById('para-empty').textContent = 'OK'", "OK" }, - .{ "document.getElementById('para-empty').firstChild.nodeName === '#text'", "true" }, - }, .{}); - - try runner.testCases(&.{ - .{ "let append = document.createElement('h1')", "undefined" }, - .{ "content.appendChild(append).toString()", "[object HTMLHeadingElement]" }, - .{ "content.lastChild.__proto__.constructor.name", "HTMLHeadingElement" }, - .{ "content.appendChild(link).toString()", "[object HTMLAnchorElement]" }, - }, .{}); - - try runner.testCases(&.{ - .{ "let clone = link.cloneNode()", "undefined" }, - .{ "clone.toString()", "[object HTMLAnchorElement]" }, - .{ "clone.parentNode === null", "true" }, - .{ "clone.firstChild === null", "true" }, - .{ "let clone_deep = link.cloneNode(true)", "undefined" }, - .{ "clone_deep.firstChild.nodeName === '#text'", "true" }, - }, .{}); - - try runner.testCases(&.{ - .{ "link.contains(text)", "true" }, - .{ "text.contains(link)", "false" }, - }, .{}); - - try runner.testCases(&.{ - .{ "link.hasChildNodes()", "true" }, - .{ "text.hasChildNodes()", "false" }, - }, .{}); - - try runner.testCases(&.{ - .{ "link.childNodes.length", "1" }, - .{ "text.childNodes.length", "0" }, - }, .{}); - - try runner.testCases(&.{ - .{ "let insertBefore = document.createElement('a')", "undefined" }, - .{ "link.insertBefore(insertBefore, text) !== undefined", "true" }, - .{ "link.firstChild.localName === 'a'", "true" }, - - .{ "let insertBefore2 = document.createElement('b')", null }, - .{ "link.insertBefore(insertBefore2, null).localName", "b" }, - .{ "link.childNodes[link.childNodes.length - 1].localName", "b" }, - }, .{}); - - try runner.testCases(&.{ - // TODO: does not seems to work - // .{ "link.isDefaultNamespace('')", "true" }, - .{ "link.isDefaultNamespace('false')", "false" }, - }, .{}); - - try runner.testCases(&.{ - .{ "let equal1 = document.createElement('a')", "undefined" }, - .{ "let equal2 = document.createElement('a')", "undefined" }, - .{ "equal1.textContent = 'is equal'", "is equal" }, - .{ "equal2.textContent = 'is equal'", "is equal" }, - // TODO: does not seems to work - // .{ "equal1.isEqualNode(equal2)", "true" }, - }, .{}); - - try runner.testCases(&.{ - .{ "document.body.isSameNode(document.body)", "true" }, - }, .{}); - - try runner.testCases(&.{ - // TODO: no test - .{ "link.normalize()", "undefined" }, - }, .{}); - - try runner.testCases(&.{ - .{ "link.baseURI", "https://lightpanda.io/opensource-browser/" }, - }, .{}); - - try runner.testCases(&.{ - .{ "content.removeChild(append) !== undefined", "true" }, - .{ "last_child.__proto__.constructor.name !== 'HTMLHeadingElement'", "true" }, - }, .{}); - - try runner.testCases(&.{ - .{ "let replace = document.createElement('div')", "undefined" }, - .{ "link.replaceChild(replace, insertBefore) !== undefined", "true" }, - }, .{}); - - try runner.testCases(&.{ - .{ "Node.ELEMENT_NODE", "1" }, - .{ "Node.ATTRIBUTE_NODE", "2" }, - .{ "Node.TEXT_NODE", "3" }, - .{ "Node.CDATA_SECTION_NODE", "4" }, - .{ "Node.PROCESSING_INSTRUCTION_NODE", "7" }, - .{ "Node.COMMENT_NODE", "8" }, - .{ "Node.DOCUMENT_NODE", "9" }, - .{ "Node.DOCUMENT_TYPE_NODE", "10" }, - .{ "Node.DOCUMENT_FRAGMENT_NODE", "11" }, - .{ "Node.ENTITY_REFERENCE_NODE", "5" }, - .{ "Node.ENTITY_NODE", "6" }, - .{ "Node.NOTATION_NODE", "12" }, - }, .{}); -} - -test "Browser.DOM.node.owner" { - var runner = try testing.jsRunner(testing.tracking_allocator, .{ .html = - \\
- \\ I am the original reference node. - \\
- \\Hey
Marked+ I am the original reference node. +
+