plabayo / venndb

in memory Rust database to query your data like a Venn diagram
https://venndb.rs
Apache License 2.0
91 stars 1 forks source link

using an any filter doesn't get results when no non-any prop row has that value #5

Closed GlenDC closed 7 months ago

GlenDC commented 7 months ago

This testcase breaks on v0.2.1, despite it expected to not to break:

#[derive(Debug, VennDB)]
pub struct Worker {
    #[venndb(key)]
    id: u32,
    is_admin: bool,
    is_active: Option<bool>,
    #[venndb(filter, any)]
    department: Option<Department>,
}

#[test]
fn test_any_row_optional_filter_map_white_rabbit() {
    let db = WorkerDB::from_rows(vec![
        Worker {
            id: 1,
            is_admin: false,
            is_active: Some(true),
            department: Some(Department::Engineering),
        },
        Worker {
            id: 2,
            is_admin: false,
            is_active: None,
            department: None,
        },
        Worker {
            id: 3,
            is_admin: false,
            is_active: Some(true),
            department: Some(Department::Any),
        },
        Worker {
            id: 4,
            is_admin: false,
            is_active: Some(true),
            department: Some(Department::HR),
        },
    ])
    .unwrap();

    let mut query = db.query();
    query.department(Department::Marketing);
    let results = query.execute().unwrap().iter().collect::<Vec<_>>();
    assert_eq!(results.len(), 1);
    assert_eq!(results[1].id, 3);
}