Update tests a little, add constructor for QueryClause struct

This commit is contained in:
Timothy Warren 2019-04-03 16:41:51 -04:00
parent 7fd51aa76c
commit 0d648952cd

View File

@ -61,6 +61,16 @@ struct QueryClause {
string: String,
}
impl QueryClause {
pub fn new(clause_type: QueryClauseType, conjunction: String, string: String) -> Self {
QueryClause {
clause_type,
conjunction,
string,
}
}
}
#[derive(Debug)]
struct QueryState {
select_string: String,
@ -386,13 +396,14 @@ mod tests {
#[test]
fn set_key_value() {
let builder = QueryBuilder::new()
let qb = QueryBuilder::new()
.set("foo", Box::new("bar"));
assert!(builder.state.values[0].is::<&str>());
assert_eq!(qb.state.set_array_keys[0], "foo");
assert!(qb.state.values[0].is::<&str>());
// @TODO find a way to make this kind of operation much more ergonomic
assert_eq!(*builder.state.values[0].downcast_ref::<&str>().unwrap(), "bar");
assert_eq!(*qb.state.values[0].downcast_ref::<&str>().unwrap(), "bar");
}
#[test]
@ -412,6 +423,8 @@ mod tests {
let qb = qb.set_map(authors);
// assert_eq!(qb.state.set_array_keys[0], "Chinua Achebe");
assert_eq!(qb.state.set_array_keys.len(), 3);
assert_eq!(qb.state.values.len(), 3);
}
}