Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move tests into source files #897

Merged
merged 1 commit into from
Jan 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/format/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,27 @@ pub struct Json<T>(pub T);
text_format!(Json based on serde_json);

binary_format!(Json based on serde_json);

#[cfg(test)]
mod tests {
use super::*;
use crate::format::{Binary, Text};
use serde::{Deserialize, Serialize};
#[cfg(feature = "wasm_test")]
use wasm_bindgen_test::wasm_bindgen_test as test;

#[test]
fn json_format() {
#[derive(Serialize, Deserialize)]
struct Data {
value: u8,
}

let Json(data): Json<Result<Data, _>> = Json::from(Ok(r#"{"value": 123}"#.to_string()));
let data = data.unwrap();
assert_eq!(data.value, 123);

let _stored: Text = Json(&data).into();
let _stored: Binary = Json(&data).into();
}
}
64 changes: 64 additions & 0 deletions src/virtual_dom/vcomp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,67 @@ impl<COMP: Component> fmt::Debug for VChild<COMP> {
f.write_str("VChild<_>")
}
}

#[cfg(test)]
mod tests {
use crate::macros::Properties;
use crate::{html, Component, ComponentLink, Html, ShouldRender};
#[cfg(feature = "wasm_test")]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

#[cfg(feature = "wasm_test")]
wasm_bindgen_test_configure!(run_in_browser);

struct Comp;

#[derive(Clone, PartialEq, Properties)]
struct Props {
field_1: u32,
field_2: u32,
}

impl Component for Comp {
type Message = ();
type Properties = Props;

fn create(_: Self::Properties, _: ComponentLink<Self>) -> Self {
Comp
}

fn update(&mut self, _: Self::Message) -> ShouldRender {
unimplemented!();
}

fn view(&self) -> Html {
unimplemented!();
}
}

#[test]
fn set_properties_to_component() {
html! {
<Comp />
};

html! {
<Comp field_1=1 />
};

html! {
<Comp field_2=2 />
};

html! {
<Comp field_1=1 field_2=2 />
};

let props = Props {
field_1: 1,
field_2: 1,
};

html! {
<Comp with props />
};
}
}
42 changes: 42 additions & 0 deletions src/virtual_dom/vlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,45 @@ impl VDiff for VList {
previous_sibling
}
}

#[cfg(test)]
mod tests {
use crate::{html, Component, ComponentLink, Html, ShouldRender};
#[cfg(feature = "wasm_test")]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

#[cfg(feature = "wasm_test")]
wasm_bindgen_test_configure!(run_in_browser);

struct Comp;

impl Component for Comp {
type Message = ();
type Properties = ();

fn create(_: Self::Properties, _: ComponentLink<Self>) -> Self {
Comp
}

fn update(&mut self, _: Self::Message) -> ShouldRender {
unimplemented!();
}

fn view(&self) -> Html {
unimplemented!();
}
}

#[test]
fn check_fragments() {
let fragment = html! {
<>
</>
};
html! {
<div>
{ fragment }
</div>
};
}
}
Loading