on master help sign in
Add some initial sanity tests!
commit2baf10cb37a7c7cfcd50711a059dc20f93c7dcc7 authorNick Fitzgerald <fitzgen@gmail.com> dateTue 15 Jan 2019, 16:19 (8 years ago) parent55618b1
5 files changed+257−99
Cargo.lock+50−64 Cargo.toml+16 js/change-list.js+32−32 src/node.rs+24 tests/web.rs+135−3
Cargo.lock+50−64
@@ -40,7 +40,6 @@ dependencies = [
4040[[package]]
4141name = "bumpalo"
4242version = "1.1.0"
43−source = "registry+https://github.com/rust-lang/crates.io-index"
4443
4544[[package]]
4645name = "cc"
@@ -55,57 +54,67 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
5554[[package]]
5655name = "console_error_panic_hook"
5756version = "0.1.5"
58−source = "registry+https://github.com/rust-lang/crates.io-index"
5957dependencies = [
6058 "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
61− "wasm-bindgen 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
59+ "wasm-bindgen 0.2.31",
60+]
61+
62+[[package]]
63+name = "console_log"
64+version = "0.1.2"
65+source = "registry+https://github.com/rust-lang/crates.io-index"
66+dependencies = [
67+ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
68+ "web-sys 0.3.8",
6269]
6370
6471[[package]]
6572name = "dodrio"
6673version = "0.1.0"
6774dependencies = [
68− "bumpalo 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
69− "js-sys 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
70− "wasm-bindgen 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
71− "wasm-bindgen-test 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
72− "web-sys 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
75+ "bumpalo 1.1.0",
76+ "console_log 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
77+ "js-sys 0.3.8",
78+ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
79+ "wasm-bindgen 0.2.31",
80+ "wasm-bindgen-test 0.2.31",
81+ "web-sys 0.3.8",
7382]
7483
7584[[package]]
7685name = "dodrio-counter"
7786version = "0.1.0"
7887dependencies = [
79− "bumpalo 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
80− "console_error_panic_hook 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
88+ "bumpalo 1.1.0",
89+ "console_error_panic_hook 0.1.5",
8190 "dodrio 0.1.0",
82− "wasm-bindgen 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
83− "wasm-bindgen-test 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
84− "web-sys 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
91+ "wasm-bindgen 0.2.31",
92+ "wasm-bindgen-test 0.2.31",
93+ "web-sys 0.3.8",
8594]
8695
8796[[package]]
8897name = "dodrio-hello-world"
8998version = "0.1.0"
9099dependencies = [
91− "bumpalo 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
92− "console_error_panic_hook 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
100+ "bumpalo 1.1.0",
101+ "console_error_panic_hook 0.1.5",
93102 "dodrio 0.1.0",
94− "wasm-bindgen 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
95− "wasm-bindgen-test 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
96− "web-sys 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
103+ "wasm-bindgen 0.2.31",
104+ "wasm-bindgen-test 0.2.31",
105+ "web-sys 0.3.8",
97106]
98107
99108[[package]]
100109name = "dodrio-input-form"
101110version = "0.1.0"
102111dependencies = [
103− "bumpalo 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
104− "console_error_panic_hook 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
112+ "bumpalo 1.1.0",
113+ "console_error_panic_hook 0.1.5",
105114 "dodrio 0.1.0",
106− "wasm-bindgen 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
107− "wasm-bindgen-test 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
108− "web-sys 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
115+ "wasm-bindgen 0.2.31",
116+ "wasm-bindgen-test 0.2.31",
117+ "web-sys 0.3.8",
109118]
110119
111120[[package]]
@@ -164,9 +173,8 @@ dependencies = [
164173[[package]]
165174name = "js-sys"
166175version = "0.3.8"
167−source = "registry+https://github.com/rust-lang/crates.io-index"
168176dependencies = [
169− "wasm-bindgen 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
177+ "wasm-bindgen 0.2.31",
170178]
171179
172180[[package]]
@@ -349,78 +357,70 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
349357[[package]]
350358name = "wasm-bindgen"
351359version = "0.2.31"
352−source = "registry+https://github.com/rust-lang/crates.io-index"
353360dependencies = [
354− "wasm-bindgen-macro 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
361+ "wasm-bindgen-macro 0.2.31",
355362]
356363
357364[[package]]
358365name = "wasm-bindgen-backend"
359366version = "0.2.31"
360−source = "registry+https://github.com/rust-lang/crates.io-index"
361367dependencies = [
362368 "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
363369 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
364370 "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
365371 "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
366372 "syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)",
367− "wasm-bindgen-shared 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
373+ "wasm-bindgen-shared 0.2.31",
368374]
369375
370376[[package]]
371377name = "wasm-bindgen-futures"
372378version = "0.3.8"
373−source = "registry+https://github.com/rust-lang/crates.io-index"
374379dependencies = [
375380 "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
376− "js-sys 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
377− "wasm-bindgen 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
381+ "js-sys 0.3.8",
382+ "wasm-bindgen 0.2.31",
378383]
379384
380385[[package]]
381386name = "wasm-bindgen-macro"
382387version = "0.2.31"
383−source = "registry+https://github.com/rust-lang/crates.io-index"
384388dependencies = [
385389 "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
386− "wasm-bindgen-macro-support 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
390+ "wasm-bindgen-macro-support 0.2.31",
387391]
388392
389393[[package]]
390394name = "wasm-bindgen-macro-support"
391395version = "0.2.31"
392−source = "registry+https://github.com/rust-lang/crates.io-index"
393396dependencies = [
394397 "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
395398 "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
396399 "syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)",
397− "wasm-bindgen-backend 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
398− "wasm-bindgen-shared 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
400+ "wasm-bindgen-backend 0.2.31",
401+ "wasm-bindgen-shared 0.2.31",
399402]
400403
401404[[package]]
402405name = "wasm-bindgen-shared"
403406version = "0.2.31"
404−source = "registry+https://github.com/rust-lang/crates.io-index"
405407
406408[[package]]
407409name = "wasm-bindgen-test"
408410version = "0.2.31"
409−source = "registry+https://github.com/rust-lang/crates.io-index"
410411dependencies = [
411− "console_error_panic_hook 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
412+ "console_error_panic_hook 0.1.5",
412413 "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
413− "js-sys 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
414+ "js-sys 0.3.8",
414415 "scoped-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
415− "wasm-bindgen 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
416− "wasm-bindgen-futures 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
417− "wasm-bindgen-test-macro 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
416+ "wasm-bindgen 0.2.31",
417+ "wasm-bindgen-futures 0.3.8",
418+ "wasm-bindgen-test-macro 0.2.31",
418419]
419420
420421[[package]]
421422name = "wasm-bindgen-test-macro"
422423version = "0.2.31"
423−source = "registry+https://github.com/rust-lang/crates.io-index"
424424dependencies = [
425425 "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
426426 "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -429,7 +429,6 @@ dependencies = [
429429[[package]]
430430name = "wasm-bindgen-webidl"
431431version = "0.2.25"
432−source = "registry+https://github.com/rust-lang/crates.io-index"
433432dependencies = [
434433 "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
435434 "heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -437,21 +436,20 @@ dependencies = [
437436 "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
438437 "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
439438 "syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)",
440− "wasm-bindgen-backend 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
439+ "wasm-bindgen-backend 0.2.31",
441440 "weedle 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
442441]
443442
444443[[package]]
445444name = "web-sys"
446445version = "0.3.8"
447−source = "registry+https://github.com/rust-lang/crates.io-index"
448446dependencies = [
449447 "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
450448 "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
451− "js-sys 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
449+ "js-sys 0.3.8",
452450 "sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
453− "wasm-bindgen 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)",
454− "wasm-bindgen-webidl 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)",
451+ "wasm-bindgen 0.2.31",
452+ "wasm-bindgen-webidl 0.2.25",
455453]
456454
457455[[package]]
@@ -503,17 +501,15 @@ dependencies = [
503501"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
504502"checksum backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "89a47830402e9981c5c41223151efcced65a0510c13097c769cede7efb34782a"
505503"checksum backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)" = "c66d56ac8dabd07f6aacdaf633f4b8262f5b3601a810a0dcddffd5c22c69daa0"
506−"checksum bumpalo 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc4fcb5e70b6c60b241977e660f32831396c2a8e2208fdb40277ad22f69e9644"
507504"checksum cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f159dfd43363c4d08055a07703eb7a3406b0dac4d0584d96965a3262db3c9d16"
508505"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4"
509−"checksum console_error_panic_hook 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6c5dd2c094474ec60a6acaf31780af270275e3153bafff2db5995b715295762e"
506+"checksum console_log 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1e7871d2947441b0fdd8e2bd1ce2a2f75304f896582c0d572162d48290683c48"
510507"checksum env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "afb070faf94c85d17d50ca44f6ad076bce18ae92f0037d350947240a36e9d42e"
511508"checksum failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6dd377bcc1b1b7ce911967e3ec24fa19c3224394ec05b54aa7b083d498341ac7"
512509"checksum failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "64c2d913fe8ed3b6c6518eedf4538255b989945c14c2a7d5cbff62a5e2120596"
513510"checksum futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)" = "49e7653e374fe0d0c12de4250f0bdb60680b8c80eed558c5c7538eec9c89e21b"
514511"checksum heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea04fa3ead4e05e51a7c806fc07271fdbde4e246a6c6d1efd52e72230b771b82"
515512"checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114"
516−"checksum js-sys 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "27968ddad7df6b0895bf223d475fb71077bbc1de063777ae27cb442163591d36"
517513"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1"
518514"checksum libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)" = "10923947f84a519a45c8fefb7dd1b3e8c08747993381adee176d7a82b4195311"
519515"checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6"
@@ -539,16 +535,6 @@ dependencies = [
539535"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
540536"checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737"
541537"checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd"
542−"checksum wasm-bindgen 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)" = "f45ea87af0efdd3b142836cf2ea233c938fbd0ead3a9da0fd240abd5303d1f5c"
543−"checksum wasm-bindgen-backend 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)" = "65aafeecd4dcb2385505cbd33479c08c961902eae2d19f8cdc09a27c3cd50e09"
544−"checksum wasm-bindgen-futures 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "5b36999d57b7cc8b5463adcef55e9847efce0cb54dc3239a1f8082aae986d841"
545−"checksum wasm-bindgen-macro 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)" = "e3723ce26569facc66e1b53982a1035224d5c0d89a766eb3a45e56153e59b5e1"
546−"checksum wasm-bindgen-macro-support 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)" = "51ff31a6a49abf9743b2cac233bf83a33f24b154878ffdce5a41c8d11f91b3d9"
547−"checksum wasm-bindgen-shared 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)" = "98c697f76b3ab6a0e8abd4489ba81c1ad2eded87f8a871ea5593bb45323400c8"
548−"checksum wasm-bindgen-test 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)" = "371bcf73e0105dd6475ce979641adce782c45685c66502b69014ea3ed33e1c4c"
549−"checksum wasm-bindgen-test-macro 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)" = "14e80d7f52743df9276c7c8a37b793332d746309b0e63696d33d1de3d464c674"
550−"checksum wasm-bindgen-webidl 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "bb97b10781b6df5a71d9c3aa9c8b65023816fdba1b4b13a00eb5591eeeb7f6ea"
551−"checksum web-sys 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "4e4abda3e6221ccb9b9a1853d75c33a37a385e533e784bd8ea121f6ff279ec1c"
552538"checksum weedle 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "26a4c67f132386d965390b8a734d5d10adbcd30eb5cc74bd9229af8b83f10044"
553539"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0"
554540"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
Cargo.toml+16
@@ -27,6 +27,14 @@ features = [
2727wasm-bindgen-test = "0.2"
2828console_log = "0.1.2"
2929
30+[dev-dependencies.web-sys]
31+version = "0.3.8"
32+features = [
33+ "Attr",
34+ "NamedNodeMap",
35+ "NodeList",
36+]
37+
3038[profile.release]
3139# Tell `rustc` to optimize for small code size.
3240opt-level = "s"
@@ -37,3 +45,11 @@ members = [
3745 "./examples/hello-world/crate",
3846 "./examples/input-form/crate",
3947]
48+
49+[patch.crates-io]
50+bumpalo = { path = "../bumpalo" }
51+console_error_panic_hook = { path = "../console_error_panic_hook" }
52+wasm-bindgen = { path = "../wasm-bindgen" }
53+wasm-bindgen-test = { path = "../wasm-bindgen/crates/test" }
54+js-sys = { path = "../wasm-bindgen/crates/js-sys" }
55+web-sys = { path = "../wasm-bindgen/crates/web-sys" }
js/change-list.js+32−32
@@ -12,21 +12,21 @@ function string(mem, pointer, length) {
1212const OP_TABLE = [
1313 // 0
1414 function setText(stack, mem8, mem32, i) {
15− console.log("setText");
15+ // console.log("setText");
1616 const pointer = mem32[i++];
1717 const length = mem32[i++];
1818 const str = string(mem8, pointer, length);
19− console.log(" str =", str);
20− console.log(" top(stack) =", top(stack));
19+ // console.log(" str =", str);
20+ // console.log(" top(stack) =", top(stack));
2121 top(stack).textContent = str;
2222 return i;
2323 },
2424
2525 // 1
2626 function removeSelfAndNextSiblings(stack, mem8, mem32, i) {
27− console.log("removeSelfAndNextSiblings");
27+ // console.log("removeSelfAndNextSiblings");
2828 const node = stack.pop();
29− console.log(" top(stack) =", node);
29+ // console.log(" top(stack) =", node);
3030 let sibling = node.nextSibling;
3131 while (sibling) {
3232 const temp = sibling.nextSibling;
@@ -39,11 +39,11 @@ const OP_TABLE = [
3939
4040 // 2
4141 function replaceWith(stack, mem8, mem32, i) {
42− console.log("replaceWith");
42+ // console.log("replaceWith");
4343 const newNode = stack.pop();
44− console.log(" newNode =", newNode);
44+ // console.log(" newNode =", newNode);
4545 const oldNode = stack.pop();
46− console.log(" oldNode =", oldNode);
46+ // console.log(" oldNode =", oldNode);
4747 oldNode.replaceWith(newNode);
4848 stack.push(newNode);
4949 return i;
@@ -51,43 +51,43 @@ const OP_TABLE = [
5151
5252 // 3
5353 function setAttribute(stack, mem8, mem32, i) {
54− console.log("setAttribute");
54+ // console.log("setAttribute");
5555 const pointer1 = mem32[i++];
5656 const length1 = mem32[i++];
5757 const name = string(mem8, pointer1, length1);
58− console.log(" name =", name);
58+ // console.log(" name =", name);
5959 const pointer2 = mem32[i++];
6060 const length2 = mem32[i++];
6161 const value = string(mem8, pointer2, length2);
62− console.log(" value =", value);
63− console.log(" top(stack) =", top(stack));
62+ // console.log(" value =", value);
63+ // console.log(" top(stack) =", top(stack));
6464 top(stack).setAttribute(name, value);
6565 return i;
6666 },
6767
6868 // 4
6969 function removeAttribute(stack, mem8, mem32, i) {
70− console.log("removeAttribute");
70+ // console.log("removeAttribute");
7171 const pointer = mem32[i++];
7272 const length = mem32[i++];
7373 const name = string(mem8, pointer, length);
74− console.log(" name =", name);
74+ // console.log(" name =", name);
7575 top(stack).removeAttribute(name);
7676 return i;
7777 },
7878
7979 // 5
8080 function pushFirstChild(stack, mem8, mem32, i) {
81− console.log("pushFirstChild");
82− console.log(" top(stack) =", top(stack));
81+ // console.log("pushFirstChild");
82+ // console.log(" top(stack) =", top(stack));
8383 stack.push(top(stack).firstChild);
8484 return i;
8585 },
8686
8787 // 6
8888 function popPushNextSibling(stack, mem8, mem32, i) {
89− console.log("popPushNextSibling");
90− console.log(" top(stack) =", top(stack));
89+ // console.log("popPushNextSibling");
90+ // console.log(" top(stack) =", top(stack));
9191 const node = stack.pop();
9292 stack.push(node.nextSibling);
9393 return i;
@@ -95,16 +95,16 @@ const OP_TABLE = [
9595
9696 // 7
9797 function pop(stack, mem8, mem32, i) {
98− console.log("pop");
99− console.log(" top(stack) =", top(stack));
98+ // console.log("pop");
99+ // console.log(" top(stack) =", top(stack));
100100 stack.pop();
101101 return i;
102102 },
103103
104104 // 8
105105 function appendChild(stack, mem8, mem32, i) {
106− console.log("appendChild");
107− console.log(" top(stack) =", top(stack));
106+ // console.log("appendChild");
107+ // console.log(" top(stack) =", top(stack));
108108 const child = stack.pop();
109109 top(stack).appendChild(child);
110110 return i;
@@ -112,24 +112,24 @@ const OP_TABLE = [
112112
113113 // 9
114114 function createTextNode(stack, mem8, mem32, i) {
115− console.log("appendChild");
115+ // console.log("appendChild");
116116 const pointer = mem32[i++];
117117 const length = mem32[i++];
118118 const text = string(mem8, pointer, length);
119− console.log(" text =", text);
120− console.log(" top(stack) =", top(stack));
119+ // console.log(" text =", text);
120+ // console.log(" top(stack) =", top(stack));
121121 stack.push(document.createTextNode(text));
122122 return i;
123123 },
124124
125125 // 10
126126 function createElement(stack, mem8, mem32, i) {
127− console.log("createElement");
127+ // console.log("createElement");
128128 const pointer = mem32[i++];
129129 const length = mem32[i++];
130130 const tagName = string(mem8, pointer, length);
131− console.log(" tagName =", tagName);
132− console.log(" top(stack) =", top(stack));
131+ // console.log(" tagName =", tagName);
132+ // console.log(" top(stack) =", top(stack));
133133 stack.push(document.createElement(tagName));
134134 return i;
135135 }
@@ -149,7 +149,7 @@ class ChangeList {
149149 }
150150
151151 applyChanges(memory) {
152− console.log("======== ChangeList.prototype.applyChanges ==============================");
152+ // console.log("======== ChangeList.prototype.applyChanges ==============================");
153153 if (this.ranges.length == 0) {
154154 return;
155155 }
@@ -172,9 +172,9 @@ class ChangeList {
172172 const end = (start + len) / 4;
173173 for (let i = start / 4; i < end; ) {
174174 const op = mem32[i++];
175− console.log();
176− console.log(OP_TABLE[op].name);
177− console.log(this.stack);
175+ // console.log();
176+ // console.log(OP_TABLE[op].name);
177+ // console.log(this.stack);
178178 i = OP_TABLE[op](this.stack, mem8, mem32, i);
179179 }
180180 }
src/node.rs+24
@@ -50,6 +50,30 @@ impl<'a> Node<'a> {
5050 }
5151}
5252
53+impl<'a> TextNode<'a> {
54+ /// Get this text node's text content.
55+ pub fn text(&self) -> &'a str {
56+ self.text
57+ }
58+}
59+
60+impl<'a> ElementNode<'a> {
61+ /// Get this element's tag name.
62+ pub fn tag_name(&self) -> &'a str {
63+ self.tag_name
64+ }
65+
66+ /// Get this element's attributes.
67+ pub fn attributes(&self) -> &'a [Attribute<'a>] {
68+ self.attributes
69+ }
70+
71+ /// Get this element's attributes.
72+ pub fn children(&self) -> &'a [Node<'a>] {
73+ self.children
74+ }
75+}
76+
5377impl<'a> BumpAllocSafe for Node<'a> {}
5478impl<'a> BumpAllocSafe for Attribute<'a> {}
5579
tests/web.rs+135−3
@@ -2,12 +2,144 @@
22
33#![cfg(target_arch = "wasm32")]
44
5−extern crate wasm_bindgen_test;
5+use bumpalo::Bump;
6+use dodrio::{
7+ node::{Attribute, Node},
8+ vdom::Vdom,
9+ Render,
10+};
11+use log::*;
12+use wasm_bindgen::JsCast;
613use wasm_bindgen_test::*;
714
815wasm_bindgen_test_configure!(run_in_browser);
916
17+fn window() -> web_sys::Window {
18+ web_sys::window().expect("no global `window` exists")
19+}
20+
21+fn document() -> web_sys::Document {
22+ window()
23+ .document()
24+ .expect("should have a document on window")
25+}
26+
27+fn create_element(tag: &str) -> web_sys::Element {
28+ document()
29+ .create_element(tag)
30+ .expect("should create element OK")
31+}
32+
33+fn init_logging() {
34+ use std::sync::Once;
35+ static START: Once = Once::new();
36+ START.call_once(|| {
37+ console_log::init_with_level(Level::Trace).expect("could not initialize console_log");
38+ });
39+}
40+
41+fn assert_rendered<R: Render>(container: &web_sys::Element, r: &R) {
42+ init_logging();
43+ let bump = &Bump::new();
44+ let node = r.render(bump);
45+ let child = container
46+ .first_child()
47+ .expect("container does not have anything rendered into it?");
48+ check_node(&child, &node);
49+
50+ fn stringify_actual_node(n: &web_sys::Node) -> String {
51+ if let Some(el) = n.dyn_ref::<web_sys::Element>() {
52+ el.outer_html()
53+ } else {
54+ format!("#text({:?})", n.text_content())
55+ }
56+ }
57+
58+ fn check_node(actual: &web_sys::Node, expected: &Node) {
59+ info!("check_render:");
60+ info!(" actual = {}", stringify_actual_node(&actual));
61+ info!(" expected = {:?}", expected);
62+ match expected {
63+ Node::Text(text_node) => {
64+ assert_eq!(actual.node_name().to_uppercase(), "#TEXT");
65+ assert_eq!(actual.text_content().unwrap_or_default(), text_node.text());
66+ }
67+ Node::Element(elem) => {
68+ assert_eq!(
69+ actual.node_name().to_uppercase(),
70+ elem.tag_name().to_uppercase()
71+ );
72+ let actual = actual
73+ .dyn_ref::<web_sys::Element>()
74+ .expect("`actual` should be an `Element`");
75+ check_attributes(actual.attributes(), elem.attributes());
76+ check_children(actual.child_nodes(), elem.children());
77+ }
78+ }
79+ }
80+
81+ fn check_attributes(actual: web_sys::NamedNodeMap, expected: &[Attribute]) {
82+ assert_eq!(actual.length(), expected.len() as u32);
83+ for attr in expected {
84+ let actual_attr = actual
85+ .get_named_item(attr.name)
86+ .expect(&format!("should have attribute \"{}\"", attr.name));
87+ assert_eq!(actual_attr.value(), attr.value);
88+ }
89+ }
90+
91+ fn check_children(actual: web_sys::NodeList, expected: &[Node]) {
92+ assert_eq!(actual.length(), expected.len() as u32);
93+ for (i, child) in expected.iter().enumerate() {
94+ let actual_child = actual.item(i as u32).unwrap();
95+ check_node(&actual_child, child);
96+ }
97+ }
98+}
99+
100+#[wasm_bindgen_test]
101+fn render_initial_text() {
102+ struct Hello;
103+
104+ impl Render for Hello {
105+ fn render<'a, 'bump>(&'a self, _bump: &'bump Bump) -> Node<'bump>
106+ where
107+ 'a: 'bump,
108+ {
109+ Node::text("Hello")
110+ }
111+ }
112+
113+ let container = create_element("div");
114+ Vdom::new(&container, &Hello);
115+ assert_rendered(&container, &Hello);
116+}
117+
10118#[wasm_bindgen_test]
11−fn pass() {
12− assert_eq!(1 + 1, 2);
119+fn render_initial_node() {
120+ struct Hello;
121+
122+ impl Render for Hello {
123+ fn render<'a, 'bump>(&'a self, bump: &'bump Bump) -> Node<'bump>
124+ where
125+ 'a: 'bump,
126+ {
127+ Node::element(
128+ bump,
129+ "div",
130+ [Attribute {
131+ name: "id",
132+ value: "hello-world",
133+ }],
134+ [
135+ Node::text("Hello "),
136+ Node::element(bump, "span", [], [Node::text("World!")]),
137+ ],
138+ )
139+ }
140+ }
141+
142+ let container = create_element("div");
143+ Vdom::new(&container, &Hello);
144+ assert_rendered(&container, &Hello);
13145}