2024-07-31 16:59:51 +00:00
|
|
|
//! Tests that fields attributed with `#[default]` are initialized with `Default::default()`.
|
|
|
|
|
|
|
|
use salsa::Durability;
|
|
|
|
use test_log::test;
|
|
|
|
|
|
|
|
#[salsa::input]
|
|
|
|
struct MyInput {
|
|
|
|
required: bool,
|
|
|
|
#[default]
|
|
|
|
optional: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn new_constructor() {
|
|
|
|
let db = salsa::DatabaseImpl::new();
|
|
|
|
|
|
|
|
let input = MyInput::new(&db, true);
|
|
|
|
|
2024-08-06 06:56:06 +00:00
|
|
|
assert!(input.required(&db));
|
2024-07-31 16:59:51 +00:00
|
|
|
assert_eq!(input.optional(&db), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn builder_specify_optional() {
|
|
|
|
let db = salsa::DatabaseImpl::new();
|
|
|
|
|
|
|
|
let input = MyInput::builder(true).optional(20).new(&db);
|
|
|
|
|
2024-08-06 06:56:06 +00:00
|
|
|
assert!(input.required(&db));
|
2024-07-31 16:59:51 +00:00
|
|
|
assert_eq!(input.optional(&db), 20);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn builder_default_optional_value() {
|
|
|
|
let db = salsa::DatabaseImpl::new();
|
|
|
|
|
|
|
|
let input = MyInput::builder(true)
|
|
|
|
.required_durability(Durability::HIGH)
|
|
|
|
.new(&db);
|
|
|
|
|
2024-08-06 06:56:06 +00:00
|
|
|
assert!(input.required(&db));
|
2024-07-31 16:59:51 +00:00
|
|
|
assert_eq!(input.optional(&db), 0);
|
|
|
|
}
|