use clouseau::parse_query; use clouseau::{query::Context, Queryable}; use std::marker::PhantomData; #[derive(Debug, Queryable)] struct Foo { a: i64, b: &'static str, v: Vec>, } #[derive(Debug, Queryable)] struct Bar(bool, AnEnum, Foo); #[derive(Debug, Queryable)] #[clouseau(transparent)] struct NewType(Foo); #[derive(Debug, Queryable)] enum AnEnum { Zero, One(i64), Named { a: u32, b: Vec }, } #[derive(Debug, Queryable)] struct HasGenerics { x: X, _marker: PhantomData, } fn has_generics(x: X) -> HasGenerics { HasGenerics { x, _marker: PhantomData, } } #[test] fn query_custom_struct() { let f = NewType(Foo { a: 1, b: "hello", v: vec![ has_generics(Bar( false, AnEnum::Zero, Foo { a: 10, b: "bye", v: vec![], }, )), has_generics(Bar( false, AnEnum::One(20), Foo { a: 11, b: "bonjour", v: vec![has_generics(Bar( false, AnEnum::One(1), Foo { a: 30, b: "aaaaa", v: vec![], }, ))], }, )), has_generics(Bar( false, AnEnum::Named { a: 1, b: vec![3, 4, 5], }, Foo { a: 12, b: "ciao", v: vec![], }, )), ], }); let ctx = Context::default(); let q = parse_query("./v/*/x[./1/a = 1]/2/b").unwrap(); let res: Vec<_> = ctx.exec(&q, &f).map(|v| v.to_string()).collect(); assert_eq!(res, vec![String::from("ciao")]); }