Skip to content

Commit d47fc61

Browse files
twilcoalexcrichton
authored andcommitted
Add unit tests for more 'web-sys' HTML bindings (#617)
That list includes: * HtmlOptionElement * HtmlOptGroupElement * HtmlOListElement * HtmlModElement
1 parent 4a78769 commit d47fc61

File tree

7 files changed

+154
-6
lines changed

7 files changed

+154
-6
lines changed

crates/web-sys/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,11 +221,11 @@ bindings are fully working and have full test coverage.
221221
- [ ] HTMLMenuItemElement.webidl
222222
- [ ] HTMLMetaElement.webidl
223223
- [ ] HTMLMeterElement.webidl
224-
- [ ] HTMLModElement.webidl
224+
- [x] HTMLModElement.webidl
225225
- [ ] HTMLObjectElement.webidl
226-
- [ ] HTMLOListElement.webidl
227-
- [ ] HTMLOptGroupElement.webidl
228-
- [ ] HTMLOptionElement.webidl
226+
- [x] HTMLOListElement.webidl
227+
- [x] HTMLOptGroupElement.webidl
228+
- [x] HTMLOptionElement.webidl
229229
- [x] HTMLOptionsCollection.webidl
230230
- [x] HTMLOutputElement.webidl
231231
- [x] HTMLParagraphElement.webidl

crates/web-sys/tests/wasm/element.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ export function new_button() {
1414
return document.createElement("button");
1515
}
1616

17+
export function new_del() {
18+
return document.createElement("del");
19+
}
20+
1721
export function new_div() {
1822
return document.createElement("div");
1923
}
@@ -22,6 +26,10 @@ export function new_form() {
2226
return document.createElement("form");
2327
}
2428

29+
export function new_food_options_collection() {
30+
return new_select_with_food_opts().options;
31+
}
32+
2533
export function new_head() {
2634
return document.createElement("head");
2735
}
@@ -42,8 +50,16 @@ export function new_input() {
4250
return document.createElement("input");
4351
}
4452

45-
export function new_food_options_collection() {
46-
return new_select_with_food_opts().options;
53+
export function new_ins() {
54+
return document.createElement("ins");
55+
}
56+
57+
export function new_olist() {
58+
return document.createElement("ol");
59+
}
60+
61+
export function new_optgroup() {
62+
return document.createElement("optgroup");
4763
}
4864

4965
export function new_output() {

crates/web-sys/tests/wasm/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ pub mod hr_element;
2525
pub mod html_element;
2626
pub mod html_html_element;
2727
pub mod input_element;
28+
pub mod mod_elements;
29+
pub mod olist_element;
30+
pub mod optgroup_element;
31+
pub mod option_element;
2832
pub mod options_collection;
2933
pub mod output_element;
3034
pub mod paragraph_element;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use wasm_bindgen_test::*;
2+
use wasm_bindgen::prelude::*;
3+
use web_sys::HtmlModElement;
4+
5+
#[wasm_bindgen(module = "./tests/wasm/element.js")]
6+
extern {
7+
fn new_del() -> HtmlModElement;
8+
fn new_ins() -> HtmlModElement;
9+
}
10+
11+
#[wasm_bindgen_test]
12+
fn test_mod_elements() {
13+
let del = new_del();
14+
15+
del.set_cite("https://www.rust-lang.org/en-US/");
16+
assert_eq!(del.cite(), "https://www.rust-lang.org/en-US/", "Option should have the cite URI we gave it.");
17+
18+
del.set_date_time("Thu Aug 02 2018 18:02:56 GMT-0500 (Central Daylight Time)");
19+
assert_eq!(del.date_time(), "Thu Aug 02 2018 18:02:56 GMT-0500 (Central Daylight Time)", "Option should have the date_time we gave it.");
20+
21+
let ins = new_ins();
22+
23+
ins.set_cite("https://www.rust-lang.org/en-US/");
24+
assert_eq!(ins.cite(), "https://www.rust-lang.org/en-US/", "Option should have the cite URI we gave it.");
25+
26+
ins.set_date_time("Thu Aug 02 2018 18:02:56 GMT-0500 (Central Daylight Time)");
27+
assert_eq!(ins.date_time(), "Thu Aug 02 2018 18:02:56 GMT-0500 (Central Daylight Time)", "Option should have the date_time we gave it.");
28+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use wasm_bindgen_test::*;
2+
use wasm_bindgen::prelude::*;
3+
use web_sys::HtmlOListElement;
4+
5+
#[wasm_bindgen(module = "./tests/wasm/element.js")]
6+
extern {
7+
fn new_olist() -> HtmlOListElement;
8+
}
9+
10+
#[wasm_bindgen_test]
11+
fn test_olist_element() {
12+
let olist = new_olist();
13+
14+
olist.set_reversed(true);
15+
assert_eq!(olist.reversed(), true, "Olist should be reversed after we set it to be reversed.");
16+
17+
olist.set_reversed(false);
18+
assert_eq!(olist.reversed(), false, "Olist should not be reversed after we set it to be not reversed.");
19+
20+
olist.set_start(23);
21+
assert_eq!(olist.start(), 23, "Olist should have the start value we gave it.");
22+
23+
olist.set_type("A");
24+
assert_eq!(olist.type_(), "A", "Olist should be type 'A' after we set it to be type 'A'.");
25+
26+
olist.set_type("I");
27+
assert_eq!(olist.type_(), "I", "Olist should be type 'I' after we set it to be type 'I'.");
28+
29+
olist.set_compact(true);
30+
assert_eq!(olist.compact(), true, "Olist should be compact after we set it to be compact.");
31+
32+
olist.set_compact(false);
33+
assert_eq!(olist.compact(), false, "Olist should not be compact after we set it to be not compact.");
34+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use wasm_bindgen_test::*;
2+
use wasm_bindgen::prelude::*;
3+
use web_sys::HtmlOptGroupElement;
4+
5+
#[wasm_bindgen(module = "./tests/wasm/element.js")]
6+
extern {
7+
fn new_optgroup() -> HtmlOptGroupElement;
8+
}
9+
10+
#[wasm_bindgen_test]
11+
fn test_optgroup_element() {
12+
let optgroup = new_optgroup();
13+
14+
optgroup.set_disabled(true);
15+
assert_eq!(optgroup.disabled(), true, "Optgroup should be disabled after we set it to be disabled.");
16+
17+
optgroup.set_disabled(false);
18+
assert_eq!(optgroup.disabled(), false, "Optgroup should not be disabled after we set it to be not-disabled.");
19+
20+
optgroup.set_label("Group of options below");
21+
assert_eq!(optgroup.label(), "Group of options below", "Optgroup should have the label we gave it.");
22+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use wasm_bindgen_test::*;
2+
use wasm_bindgen::prelude::*;
3+
use web_sys::HtmlOptionElement;
4+
5+
#[wasm_bindgen_test]
6+
fn test_option_element() {
7+
let option = HtmlOptionElement::new(
8+
"option_text",
9+
"option_value",
10+
false,
11+
true
12+
).unwrap();
13+
14+
option.set_disabled(true);
15+
assert_eq!(option.disabled(), true, "Option should be disabled after we set it to be disabled.");
16+
17+
option.set_disabled(false);
18+
assert_eq!(option.disabled(), false, "Option should not be disabled after we set it to be not-disabled.");
19+
20+
assert!(option.form().is_none(), "Our option should not be associated with a form.");
21+
22+
option.set_label("Well this truly is a neat option");
23+
assert_eq!(option.label(), "Well this truly is a neat option", "Option should have the label we gave it.");
24+
25+
option.set_default_selected(true);
26+
assert_eq!(option.default_selected(), true, "Option should be default_selected after we set it to be default_selected.");
27+
28+
option.set_default_selected(false);
29+
assert_eq!(option.default_selected(), false, "Option should not be default_selected after we set it to be not default_selected.");
30+
31+
option.set_selected(true);
32+
assert_eq!(option.selected(), true, "Option should be selected after we set it to be selected.");
33+
34+
option.set_selected(false);
35+
assert_eq!(option.selected(), false, "Option should not be selected after we set it to be not selected.");
36+
37+
option.set_value("tomato");
38+
assert_eq!(option.value(), "tomato", "Option should have the value we gave it.");
39+
40+
option.set_text("potato");
41+
assert_eq!(option.text(), "potato", "Option should have the text we gave it.");
42+
43+
assert_eq!(option.index(), 0, "This should be the first option, since there are no other known options.");
44+
}

0 commit comments

Comments
 (0)