Skip to content

Commit

Permalink
add test for a venn db without keys
Browse files Browse the repository at this point in the history
to ensure it works as expected
  • Loading branch information
GlenDC committed Apr 7, 2024
1 parent 7a5eae7 commit ed92590
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions venndb-macros/src/generate_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ fn generate_db_struct_methods(
let method_append = generate_db_struct_method_append(name, name_db, vis, db_error, fields);

quote! {
#[allow(clippy::unused_unit)]
impl #name_db {
#method_new

Expand Down
45 changes: 45 additions & 0 deletions venndb-usage/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,49 @@ mod tests {
let result = query.execute().unwrap().any();
assert!(result.id == 1 || result.id == 2 || result.id == 3);
}

#[test]
fn test_db_without_keys() {
#[derive(Debug, VennDB)]
struct NoKeys {
name: String,
a: bool,
b: bool,
}

let mut db = NoKeysDB::from_rows(vec![
NoKeys {
name: "Alice".to_string(),
a: true,
b: false,
},
NoKeys {
name: "Bob".to_string(),
a: false,
b: true,
},
]);

assert_eq!(db.len(), 2);
assert_eq!(db.capacity(), 2);

let mut query = db.query();
query.a(true);
let results: Vec<_> = query.execute().unwrap().iter().collect();
assert_eq!(results.len(), 1);
assert_eq!(results[0].name, "Alice");

db.append(NoKeys {
name: "Charlie".to_string(),
a: true,
b: true,
});

let mut query = db.query();
query.b(true);
let results: Vec<_> = query.execute().unwrap().iter().collect();
assert_eq!(results.len(), 2);
assert_eq!(results[0].name, "Bob");
assert_eq!(results[1].name, "Charlie");
}
}

0 comments on commit ed92590

Please sign in to comment.