1
2
`; 28 | const variousContent = content => html`${content}`; 29 | 30 | render(body, html`this is a test`); 31 | render(body, html`this is a ${ 32 | [1, 2].map(n => html`${n}`) 33 | } test`); 34 | render(body, html`this is a ${ 35 | [1, 2].map(n => svg`${n}`) 36 | } test`); 37 | 38 | (function twice(i) { 39 | render(body, html`this is a ${ 40 | (i ? [1, 2, 3] : [1, 2]).map(n => svg`${n}`) 41 | } test`); 42 | if (i--) twice(i); 43 | }(1)); 44 | 45 | render(body, html`this is a ${'test'}`); 46 | render(body, html`this is a ${true}`); 47 | render(body, html`this is a ${1} ${2} ${3}`); 48 | render(body, html`this is a ${1}`); 49 | 50 | let div = document.createElement('div'); 51 | render(div, htmlNode`this is a test`); 52 | render(div, htmlFor(body)`this is a test`); 53 | render(div, htmlFor(body, 1)`this is a test`); 54 | render(div, () => htmlFor(body)`this is a test`); 55 | render(div, () => htmlFor(body, 1)`this is a test`); 56 | (function twice(i) { 57 | render(div, () => htmlFor(body)`this is a test`); 58 | render(div, () => htmlFor(body, 1)`this is a test`); 59 | if (i--) twice(i); 60 | }(1)); 61 | 62 | let clicked = false; 63 | render(div, html`${'hole'}
`); 173 | render(body, html`a
`, 56 | html`b
`, 57 | html`c
`, 58 | html`d
`, 59 | html`e
`, 60 | html`f
`, 61 | html`g
`, 62 | html`h
`, 63 | html`i
`, 64 | html`j
`, 65 | html`k
` 66 | ); 67 | 68 | testDiff( 69 | html`a
a
`, 70 | html`b
b
`, 71 | html`c
c
`, 72 | html`d
d
`, 73 | html`e
e
`, 74 | html`f
f
`, 75 | html`g
g
`, 76 | html`h
h
`, 77 | html`i
i
`, 78 | html`j
j
`, 79 | html`k
k
` 80 | ); 81 | -------------------------------------------------------------------------------- /test/dom/attribute.js: -------------------------------------------------------------------------------- 1 | import Attribute from '../../esm/dom/attribute.js'; 2 | import Document from '../../esm/dom/document.js'; 3 | 4 | const document = new Document; 5 | 6 | const a = new Attribute('a'); 7 | const b = new Attribute('b', 2); 8 | 9 | console.assert(a.name === 'a'); 10 | console.assert(a.localName === 'a'); 11 | console.assert(a.nodeName === 'a'); 12 | console.assert(a.value === ''); 13 | console.assert(a.nodeValue === ''); 14 | console.assert(a.toString() === 'a'); 15 | a.value = 1; 16 | console.assert(a.value === '1'); 17 | console.assert(a.nodeValue === '1'); 18 | console.assert(a.toString() === 'a="1"'); 19 | 20 | console.assert(b.value === '2'); 21 | 22 | const element = document.createElement('test'); 23 | element.setAttribute('c', 3); 24 | console.assert(element.getAttributeNode('c').ownerElement === element); 25 | 26 | 27 | console.assert(a.ownerElement == null); 28 | element.setAttributeNode(a); 29 | console.assert(a.ownerElement == element); 30 | -------------------------------------------------------------------------------- /test/dom/comment.js: -------------------------------------------------------------------------------- 1 | import Document from '../../esm/dom/document.js'; 2 | 3 | const document = new Document; 4 | 5 | const comment = document.createComment('test'); 6 | console.assert(!comment.childNodes.length); 7 | console.assert(comment.nodeName === '#comment'); 8 | console.assert(comment.toString() === ''); 9 | console.assert(comment.textContent === 'test'); 10 | comment.textContent = 'ok'; 11 | console.assert(comment.textContent === 'ok'); 12 | 13 | const clone = comment.cloneNode(); 14 | console.assert(clone.nodeName === '#comment'); 15 | console.assert(clone.toString() === ''); -------------------------------------------------------------------------------- /test/dom/document-fragment.js: -------------------------------------------------------------------------------- 1 | import Document from '../../esm/dom/document.js'; 2 | 3 | const document = new Document; 4 | 5 | const f1 = document.createDocumentFragment(); 6 | const f2 = document.createDocumentFragment(); 7 | 8 | console.assert(f1.nodeType === 11, 'nodeType'); 9 | console.assert(f1.nodeName === '#document-fragment', 'nodeName'); 10 | 11 | f1.append('b', 'c'); 12 | console.assert(f1.childNodes.length === 2, 'childNodes'); 13 | console.assert(f1.firstChild.parentNode === f1, 'parentNode'); 14 | 15 | f2.append(f1, 'd'); 16 | console.assert(f1.childNodes.length === 0, 'childNodes'); 17 | console.assert(f2.childNodes.length === 3, 'childNodes'); 18 | console.assert(f2.firstChild.parentNode === f2, 'parentNode'); 19 | 20 | f2.prepend('a'); 21 | 22 | document.body.append(f2); 23 | console.assert(f2.childNodes.length === 0, 'childNodes'); 24 | console.assert(document.body.firstChild.parentNode === document.body, 'parentNode'); 25 | 26 | console.assert(document.body.toString() === 'abcd'); 27 | 28 | f1.append(...document.body.childNodes); 29 | console.assert(f1.firstChild.parentNode === f1, 'parentNode'); 30 | console.assert(document.body.childNodes.length === 0, 'childNodes'); 31 | 32 | console.assert(f1.toString() === 'abcd'); 33 | 34 | const f3 = f1.cloneNode(); 35 | console.assert(f3.toString() === ''); 36 | const f4 = f1.cloneNode(true); 37 | console.assert(f4.firstChild !== f1.firstChild); 38 | console.assert(f4.toString() === f1.toString()); 39 | console.assert(f4.firstChild.parentNode === f4); 40 | console.assert(f1.firstChild.parentNode === f1); 41 | -------------------------------------------------------------------------------- /test/dom/document-type.js: -------------------------------------------------------------------------------- 1 | import Document from '../../esm/dom/document.js'; 2 | import DocumentType from '../../esm/dom/document-type.js'; 3 | 4 | const document = new Document; 5 | 6 | let { doctype } = document; 7 | console.assert(doctype.toString() === ''); 8 | console.assert(doctype.nodeName === 'html'); 9 | console.assert(doctype.name === 'html'); 10 | console.assert(doctype.ownerDocument === document); 11 | 12 | doctype = new DocumentType(''); 13 | console.assert(doctype.ownerDocument === null); 14 | console.assert(doctype.toString() === ''); -------------------------------------------------------------------------------- /test/dom/document.js: -------------------------------------------------------------------------------- 1 | import Document from '../../esm/dom/document.js'; 2 | 3 | const document = new Document; 4 | 5 | const { documentElement, body, head } = document; 6 | 7 | const attribute = document.createAttribute('lang'); 8 | attribute.value = 'en'; 9 | documentElement.setAttributeNode(attribute); 10 | 11 | const ce = document.createElement('a', { is: 'a-link' }); 12 | body.appendChild(ce); 13 | 14 | console.assert(document.toString() === ''); 15 | console.assert(head === documentElement.firstElementChild); 16 | console.assert(document.getElementsByTagName('html').length === 1); 17 | 18 | const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); 19 | console.assert('ownerSVGElement' in svg); 20 | console.assert('ownerSVGElement' in svg.cloneNode()); 21 | console.assert(svg.ownerSVGElement === null); 22 | console.assert(svg.toString() === ''); 23 | 24 | const rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect'); 25 | svg.append(rect); 26 | console.assert(rect.ownerSVGElement === svg); 27 | console.assert(svg.toString() === ''); 28 | rect.setAttribute('x', 1); 29 | console.assert(svg.toString() === ''); 30 | console.assert('ownerSVGElement' in svg.cloneNode(true)); 31 | 32 | const inner = rect.appendChild(document.createElementNS('http://www.w3.org/2000/svg', 'rect')); 33 | console.assert(inner.ownerSVGElement === svg); 34 | 35 | const tree = document.createElement('div'); 36 | let tree0, tree1, tree2; 37 | tree.append( 38 | tree0 = document.createElement('div'), 39 | tree2 = document.createComment('2'), 40 | document.createTextNode('') 41 | ); 42 | tree0.append( 43 | tree1 = document.createComment('1') 44 | ); 45 | 46 | const tw = document.createTreeWalker(tree, 1 | 128); 47 | 48 | console.assert(tw.nextNode() === tree0); 49 | console.assert(tw.nextNode() === tree1); 50 | console.assert(tw.nextNode() === tree2); 51 | console.assert(tw.nextNode() == null); 52 | -------------------------------------------------------------------------------- /test/dom/dom-parser.js: -------------------------------------------------------------------------------- 1 | import DOMParser from '../../esm/dom/dom-parser.js'; 2 | 3 | const dp = new DOMParser; 4 | 5 | let html = dp.parseFromString('...'); 6 | 7 | console.assert(html.toString() === ''); 8 | 9 | html = dp.parseFromString(''); 10 | 11 | console.assert(html.toString() === ''); 12 | 13 | let svg = dp.parseFromString('', 'svg'); 14 | 15 | console.log(svg.toString()); 16 | -------------------------------------------------------------------------------- /test/dom/element.js: -------------------------------------------------------------------------------- 1 | import Document from '../../esm/dom/document.js'; 2 | 3 | const document = new Document; 4 | 5 | const element = document.createElement('element'); 6 | const text = document.createTextNode('text'); 7 | 8 | console.assert(element.localName === 'element'); 9 | console.assert(element.nodeName === 'ELEMENT'); 10 | console.assert(element.tagName === 'ELEMENT'); 11 | console.assert(element.innerHTML === ''); 12 | console.assert(element.outerHTML === 'some node
164 | & ]]> 165 | 166 | `; 167 | console.assert(div.outerHTML === ` 168 |some node
172 | 173 | 174 |acde
'); 18 | console.assert(node.parentNode === null); 19 | 20 | range.setStartAfter(p.childNodes[0]); 21 | range.setEndAfter(p.childNodes[2]); 22 | range.deleteContents(); 23 | console.assert(p.toString() === 'ae
'); 24 | 25 | range.selectNodeContents(svg); 26 | 27 | const fragment = range.createContextualFragment( 28 | '${id} | 20 |21 | ${label} 22 | | 23 |24 | 25 | 26 | 27 | | 28 |29 | |
${id} | 26 |27 | ${label} 28 | | 29 |30 | 31 | 32 | 33 | | 34 |35 | |
${id} | 11 |12 | ${label} 13 | | 14 |15 | 16 | 17 | 18 | | 19 |20 | |
br
br