Skip to content

Commit

Permalink
Use insta for snapshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchalmers committed Dec 21, 2023
1 parent 39b2cfd commit df351ca
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions execution-plan-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ proc-macro = true

[dev-dependencies]
anyhow = "1.0.75"
insta = "1.34.0"
kittycad-execution-plan-traits = { path = "../execution-plan-traits" }
regex = "1.10.2"
rustfmt-wrapper = "0.2.1"
2 changes: 1 addition & 1 deletion execution-plan-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ mod tests {
let input: DeriveInput = syn::parse2(input).unwrap();
let out = impl_derive_value(input);
let formatted = get_text_fmt(&out).unwrap();
println!("{formatted}");
insta::assert_snapshot!(formatted);
}

fn clean_text(s: &str) -> String {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
source: execution-plan-macros/src/lib.rs
expression: formatted
---
impl kittycad_execution_plan_traits::Value for FooEnum {
fn into_parts(self) -> Vec<kittycad_execution_plan_traits::Primitive> {
match self {
FooEnum::A { x } => {
vec![
Primitive::from(stringify!(A).to_owned()),
Primitive::from(x),
]
}
FooEnum::B { y } => {
vec![
Primitive::from(stringify!(B).to_owned()),
Primitive::from(y),
]
}
FooEnum::C(field0, field1) => {
vec![
Primitive::from(stringify!(C).to_owned()),
Primitive::from(field0),
Primitive::from(field1),
]
}
}
}

fn from_parts<I>(values: &mut I) -> Result<Self, kittycad_execution_plan_traits::MemoryError>
where
I: Iterator<Item = Option<kittycad_execution_plan_traits::Primitive>>,
{
let variant_name = String::from_parts(values)?;
match variant_name.as_str() {
stringify!(A) => {
let x = usize::from_parts(values)?;
Ok(Self::A { x })
}
stringify!(B) => {
let y = usize::from_parts(values)?;
Ok(Self::B { y })
}
stringify!(C) => {
let field0 = usize::from_parts(values)?;
let field1 = String::from_parts(values)?;
Ok(Self::C(field0, field1))
}
other => Err(
kittycad_execution_plan_traits::MemoryError::InvalidEnumVariant {
expected_type: stringify!(FooEnum).to_owned(),
actual: other.to_owned(),
},
),
}
}
}

0 comments on commit df351ca

Please sign in to comment.