improve fuzzing test
This commit is contained in:
1 parent
990b0503e1
commit
112738c23d
1 file changed
+12
-13
@@ -163,14 +163,14 @@ fn create_random_dynamic_node<'a>(cx: &'a ScopeState, depth: usize) -> DynamicNo
|
|||||||
root_ids: Default::default(),
|
root_ids: Default::default(),
|
||||||
dynamic_nodes: cx.bump().alloc([cx.component(
|
dynamic_nodes: cx.bump().alloc([cx.component(
|
||||||
create_random_element,
|
create_random_element,
|
||||||
DepthProps { depth: depth },
|
DepthProps { depth, root: false },
|
||||||
"create_random_element",
|
"create_random_element",
|
||||||
)]),
|
)]),
|
||||||
dynamic_attrs: &[],
|
dynamic_attrs: &[],
|
||||||
})),
|
})),
|
||||||
3 => cx.component(
|
3 => cx.component(
|
||||||
create_random_element,
|
create_random_element,
|
||||||
DepthProps { depth: depth },
|
DepthProps { depth, root: false },
|
||||||
"create_random_element",
|
"create_random_element",
|
||||||
),
|
),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
@@ -199,22 +199,18 @@ fn create_random_dynamic_attr<'a>(cx: &'a ScopeState) -> Attribute<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn debugging() {
|
|
||||||
let template = create_random_template("test");
|
|
||||||
println!("{:#?}", template)
|
|
||||||
}
|
|
||||||
|
|
||||||
static mut TEMPLATE_COUNT: usize = 0;
|
static mut TEMPLATE_COUNT: usize = 0;
|
||||||
|
|
||||||
#[derive(PartialEq, Props)]
|
#[derive(PartialEq, Props)]
|
||||||
struct DepthProps {
|
struct DepthProps {
|
||||||
depth: usize,
|
depth: usize,
|
||||||
|
root: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_random_element<'a>(cx: Scope<'a, DepthProps>) -> Element<'a> {
|
fn create_random_element<'a>(cx: Scope<'a, DepthProps>) -> Element<'a> {
|
||||||
cx.needs_update();
|
cx.needs_update();
|
||||||
match rand::random::<usize>() % 3 {
|
let range = if cx.props.root { 2 } else { 3 };
|
||||||
|
let node = match rand::random::<usize>() % range {
|
||||||
0 | 1 => {
|
0 | 1 => {
|
||||||
let template = create_random_template(Box::leak(
|
let template = create_random_template(Box::leak(
|
||||||
format!(
|
format!(
|
||||||
@@ -248,18 +244,20 @@ fn create_random_element<'a>(cx: Scope<'a, DepthProps>) -> Element<'a> {
|
|||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
println!("{:#?}", node);
|
|
||||||
Some(node)
|
Some(node)
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
};
|
||||||
|
println!("{:#?}", node);
|
||||||
|
node
|
||||||
}
|
}
|
||||||
|
|
||||||
// test for panics when creating random nodes and templates
|
// test for panics when creating random nodes and templates
|
||||||
#[test]
|
#[test]
|
||||||
fn create() {
|
fn create() {
|
||||||
for _ in 0..1000 {
|
for _ in 0..1000 {
|
||||||
let mut vdom = VirtualDom::new_with_props(create_random_element, DepthProps { depth: 0 });
|
let mut vdom =
|
||||||
|
VirtualDom::new_with_props(create_random_element, DepthProps { depth: 0, root: true });
|
||||||
vdom.rebuild();
|
vdom.rebuild();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -269,7 +267,8 @@ fn create() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn diff() {
|
fn diff() {
|
||||||
for _ in 0..100 {
|
for _ in 0..100 {
|
||||||
let mut vdom = VirtualDom::new_with_props(create_random_element, DepthProps { depth: 0 });
|
let mut vdom =
|
||||||
|
VirtualDom::new_with_props(create_random_element, DepthProps { depth: 0, root: true });
|
||||||
vdom.rebuild();
|
vdom.rebuild();
|
||||||
for _ in 0..10 {
|
for _ in 0..10 {
|
||||||
vdom.render_immediate();
|
vdom.render_immediate();
|
||||||
|
|||||||
Reference in new issue
Block a user