wip: structure coming together and tests
This commit is contained in:
1 parent
16bfc6d248
commit
2d541eca64
13 files changed
+251
-141
No files matched your search
@@ -1,16 +1,11 @@
|
||||
//! tests to prove that the iterative implementation works
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use dioxus::{
|
||||
arena::SharedResources,
|
||||
diff::{CreateMeta, DiffMachine},
|
||||
prelude::*,
|
||||
scheduler::Mutations,
|
||||
DomEdit,
|
||||
};
|
||||
use dioxus::{arena::SharedResources, diff::DiffMachine, prelude::*, DomEdit, Mutations};
|
||||
mod test_logging;
|
||||
use dioxus_core as dioxus;
|
||||
use dioxus_html as dioxus_elements;
|
||||
use DomEdit::*;
|
||||
|
||||
#[test]
|
||||
fn test_original_diff() {
|
||||
@@ -26,11 +21,24 @@ fn test_original_diff() {
|
||||
|
||||
let mut dom = VirtualDom::new(App);
|
||||
let mutations = dom.rebuild().unwrap();
|
||||
dbg!(mutations);
|
||||
assert_eq!(
|
||||
mutations.edits,
|
||||
[
|
||||
CreateElement { id: 0, tag: "div" },
|
||||
CreateElement { id: 1, tag: "div" },
|
||||
CreateTextNode {
|
||||
id: 2,
|
||||
text: "Hello, world!"
|
||||
},
|
||||
AppendChildren { many: 1 },
|
||||
AppendChildren { many: 1 },
|
||||
AppendChildren { many: 1 },
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn test_iterative_create() {
|
||||
async fn create() {
|
||||
static App: FC<()> = |cx| {
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
@@ -50,14 +58,38 @@ async fn test_iterative_create() {
|
||||
};
|
||||
|
||||
test_logging::set_up_logging();
|
||||
|
||||
let mut dom = VirtualDom::new(App);
|
||||
let mutations = dom.rebuild_async().await.unwrap();
|
||||
dbg!(mutations);
|
||||
assert_eq!(
|
||||
mutations.edits,
|
||||
[
|
||||
CreateElement { id: 0, tag: "div" },
|
||||
CreateElement { id: 1, tag: "div" },
|
||||
CreateTextNode {
|
||||
id: 2,
|
||||
text: "Hello, world!"
|
||||
},
|
||||
CreateElement { id: 3, tag: "div" },
|
||||
CreateElement { id: 4, tag: "div" },
|
||||
CreateTextNode {
|
||||
id: 5,
|
||||
text: "hello"
|
||||
},
|
||||
CreateTextNode {
|
||||
id: 6,
|
||||
text: "world"
|
||||
},
|
||||
AppendChildren { many: 2 },
|
||||
AppendChildren { many: 1 },
|
||||
AppendChildren { many: 2 },
|
||||
AppendChildren { many: 1 },
|
||||
AppendChildren { many: 1 },
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn test_iterative_create_list() {
|
||||
async fn create_list() {
|
||||
static App: FC<()> = |cx| {
|
||||
cx.render(rsx! {
|
||||
{(0..3).map(|f| rsx!{ div {
|
||||
@@ -70,11 +102,36 @@ async fn test_iterative_create_list() {
|
||||
|
||||
let mut dom = VirtualDom::new(App);
|
||||
let mutations = dom.rebuild_async().await.unwrap();
|
||||
dbg!(mutations);
|
||||
|
||||
// copilot wrote this test :P
|
||||
assert_eq!(
|
||||
mutations.edits,
|
||||
[
|
||||
CreateElement { id: 0, tag: "div" },
|
||||
CreateTextNode {
|
||||
id: 1,
|
||||
text: "hello"
|
||||
},
|
||||
AppendChildren { many: 1 },
|
||||
CreateElement { id: 2, tag: "div" },
|
||||
CreateTextNode {
|
||||
id: 3,
|
||||
text: "hello"
|
||||
},
|
||||
AppendChildren { many: 1 },
|
||||
CreateElement { id: 4, tag: "div" },
|
||||
CreateTextNode {
|
||||
id: 5,
|
||||
text: "hello"
|
||||
},
|
||||
AppendChildren { many: 1 },
|
||||
AppendChildren { many: 3 },
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn test_iterative_create_simple() {
|
||||
async fn create_simple() {
|
||||
static App: FC<()> = |cx| {
|
||||
cx.render(rsx! {
|
||||
div {}
|
||||
@@ -88,11 +145,22 @@ async fn test_iterative_create_simple() {
|
||||
|
||||
let mut dom = VirtualDom::new(App);
|
||||
let mutations = dom.rebuild_async().await.unwrap();
|
||||
dbg!(mutations);
|
||||
|
||||
// copilot wrote this test :P
|
||||
assert_eq!(
|
||||
mutations.edits,
|
||||
[
|
||||
CreateElement { id: 0, tag: "div" },
|
||||
CreateElement { id: 1, tag: "div" },
|
||||
CreateElement { id: 2, tag: "div" },
|
||||
CreateElement { id: 3, tag: "div" },
|
||||
AppendChildren { many: 4 },
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn test_iterative_create_components() {
|
||||
async fn create_components() {
|
||||
static App: FC<()> = |cx| {
|
||||
cx.render(rsx! {
|
||||
Child { "abc1" }
|
||||
@@ -113,5 +181,81 @@ async fn test_iterative_create_components() {
|
||||
|
||||
let mut dom = VirtualDom::new(App);
|
||||
let mutations = dom.rebuild_async().await.unwrap();
|
||||
dbg!(mutations);
|
||||
|
||||
assert_eq!(
|
||||
mutations.edits,
|
||||
[
|
||||
CreateElement { id: 0, tag: "h1" },
|
||||
CreateElement { id: 1, tag: "div" },
|
||||
CreateTextNode {
|
||||
id: 2,
|
||||
text: "abc1"
|
||||
},
|
||||
AppendChildren { many: 1 },
|
||||
CreateElement { id: 3, tag: "p" },
|
||||
CreateElement { id: 4, tag: "h1" },
|
||||
CreateElement { id: 5, tag: "div" },
|
||||
CreateTextNode {
|
||||
id: 6,
|
||||
text: "abc2"
|
||||
},
|
||||
AppendChildren { many: 1 },
|
||||
CreateElement { id: 7, tag: "p" },
|
||||
CreateElement { id: 8, tag: "h1" },
|
||||
CreateElement { id: 9, tag: "div" },
|
||||
CreateTextNode {
|
||||
id: 10,
|
||||
text: "abc3"
|
||||
},
|
||||
AppendChildren { many: 1 },
|
||||
CreateElement { id: 11, tag: "p" },
|
||||
AppendChildren { many: 9 },
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn anchors() {
|
||||
static App: FC<()> = |cx| {
|
||||
cx.render(rsx! {
|
||||
{true.then(|| rsx!{ div { "hello" } })}
|
||||
{false.then(|| rsx!{ div { "goodbye" } })}
|
||||
})
|
||||
};
|
||||
|
||||
test_logging::set_up_logging();
|
||||
|
||||
let mut dom = VirtualDom::new(App);
|
||||
let mutations = dom.rebuild_async().await.unwrap();
|
||||
assert_eq!(
|
||||
mutations.edits,
|
||||
[
|
||||
CreateElement { id: 0, tag: "div" },
|
||||
CreateTextNode {
|
||||
id: 1,
|
||||
text: "hello"
|
||||
},
|
||||
AppendChildren { many: 1 },
|
||||
CreatePlaceholder { id: 2 },
|
||||
AppendChildren { many: 2 },
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn suspended() {
|
||||
static App: FC<()> = |cx| {
|
||||
let val = use_suspense(cx, || async {}, |cx, _| cx.render(rsx! { "hi "}));
|
||||
cx.render(rsx! { {val} })
|
||||
};
|
||||
|
||||
test_logging::set_up_logging();
|
||||
|
||||
let mut dom = VirtualDom::new(App);
|
||||
let mutations = dom.rebuild_async().await.unwrap();
|
||||
|
||||
assert_eq!(
|
||||
mutations.edits,
|
||||
[CreatePlaceholder { id: 0 }, AppendChildren { many: 1 },]
|
||||
);
|
||||
}
|
||||
@@ -8,10 +8,7 @@ use bumpalo::Bump;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use dioxus::{
|
||||
arena::SharedResources,
|
||||
diff::{DiffInstruction, DiffMachine},
|
||||
prelude::*,
|
||||
DomEdit,
|
||||
arena::SharedResources, diff::DiffMachine, prelude::*, DiffInstruction, DomEdit, MountType,
|
||||
};
|
||||
use dioxus_core as dioxus;
|
||||
use dioxus_html as dioxus_elements;
|
||||
@@ -43,9 +40,7 @@ impl TestDom {
|
||||
// let mut edits = Vec::new();
|
||||
let mut machine = DiffMachine::new_headless(&self.resources);
|
||||
|
||||
machine
|
||||
.stack
|
||||
.push(dioxus::diff::DiffInstruction::DiffNode { new, old });
|
||||
machine.stack.push(DiffInstruction::DiffNode { new, old });
|
||||
|
||||
machine.mutations
|
||||
}
|
||||
@@ -58,10 +53,8 @@ impl TestDom {
|
||||
|
||||
let mut machine = DiffMachine::new_headless(&self.resources);
|
||||
|
||||
machine.stack.push(dioxus::diff::DiffInstruction::Create {
|
||||
node: old,
|
||||
and: dioxus::diff::MountType::Append,
|
||||
});
|
||||
machine.stack.create_node(old, MountType::Append);
|
||||
|
||||
work_sync(&mut machine);
|
||||
|
||||
machine.mutations
|
||||
@@ -83,10 +76,9 @@ impl TestDom {
|
||||
// let mut create_edits = Vec::new();
|
||||
|
||||
let mut machine = DiffMachine::new_headless(&self.resources);
|
||||
machine.stack.push(dioxus::diff::DiffInstruction::Create {
|
||||
and: dioxus::diff::MountType::Append,
|
||||
node: old,
|
||||
});
|
||||
|
||||
machine.stack.create_node(old, MountType::Append);
|
||||
|
||||
work_sync(&mut machine);
|
||||
let create_edits = machine.mutations;
|
||||
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
use bumpalo::Bump;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use dioxus::{
|
||||
arena::SharedResources,
|
||||
diff::{CreateMeta, DiffMachine},
|
||||
prelude::*,
|
||||
DomEdit,
|
||||
};
|
||||
use dioxus::{arena::SharedResources, diff::DiffMachine, prelude::*, DomEdit};
|
||||
use dioxus_core as dioxus;
|
||||
use dioxus_html as dioxus_elements;
|
||||
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
use anyhow::{Context, Result};
|
||||
use dioxus::{
|
||||
arena::SharedResources,
|
||||
diff::{CreateMeta, DiffMachine},
|
||||
prelude::*,
|
||||
DomEdit,
|
||||
};
|
||||
use dioxus::{arena::SharedResources, diff::DiffMachine, prelude::*, DomEdit};
|
||||
use dioxus_core as dioxus;
|
||||
use dioxus_html as dioxus_elements;
|
||||
|
||||
|
||||
@@ -17,7 +17,9 @@ pub fn set_up_logging() {
|
||||
// just clone `colors_line` and overwrite our changes
|
||||
let colors_level = colors_line.clone().info(Color::Green);
|
||||
// here we set up our fern Dispatch
|
||||
fern::Dispatch::new()
|
||||
|
||||
// when running tests in batch, the logger is re-used, so ignore the logger error
|
||||
let _ = fern::Dispatch::new()
|
||||
.format(move |out, message, record| {
|
||||
out.finish(format_args!(
|
||||
"{color_line}[{level}{color_line}] {message}\x1B[0m",
|
||||
@@ -42,6 +44,5 @@ pub fn set_up_logging() {
|
||||
// .level_for("pretty_colored", log::LevelFilter::Trace)
|
||||
// output to stdout
|
||||
.chain(std::io::stdout())
|
||||
.apply()
|
||||
.unwrap();
|
||||
.apply();
|
||||
}
|
||||
@@ -3,12 +3,7 @@
|
||||
//! This means you can actually call it synchronously if you want.
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use dioxus::{
|
||||
arena::SharedResources,
|
||||
diff::{CreateMeta, DiffInstruction, DiffMachine},
|
||||
prelude::*,
|
||||
scope::Scope,
|
||||
};
|
||||
use dioxus::{arena::SharedResources, diff::DiffMachine, prelude::*, scope::Scope};
|
||||
use dioxus_core as dioxus;
|
||||
use dioxus_html as dioxus_elements;
|
||||
use futures_util::FutureExt;
|
||||
|
||||
Reference in new issue
Block a user