cartulary 0.3.0-alpha.1

The knowledge layer of your project — decisions, issues, docs, all in one place.
Documentation
/// The script body of a query, opaque to the domain. Adapters know
/// the surface format (Cozo, SQL, …) and decode anything the domain
/// needs out of it before constructing a [`Query`].
///
/// [`Query`]: super::value::Query
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct QueryScript(String);

impl QueryScript {
    pub fn new(body: impl Into<String>) -> Self {
        Self(body.into())
    }

    pub fn as_str(&self) -> &str {
        &self.0
    }
}

#[cfg(test)]
pub mod strategy {
    use super::QueryScript;
    use proptest::prelude::*;

    pub fn query_script() -> impl Strategy<Value = QueryScript> {
        ".{0,200}".prop_map(QueryScript::new)
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use proptest::prelude::*;

    proptest! {
        #[test]
        fn as_str_roundtrips(body in ".{0,200}") {
            let s = QueryScript::new(&body);
            prop_assert_eq!(s.as_str().to_string(), body);
        }
    }

    #[test]
    fn as_str_returns_the_full_body() {
        let body = "?[n] := n = 1\n";
        let s = QueryScript::new(body);
        assert_eq!(s.as_str(), body);
    }
}