mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-23 05:07:27 +00:00
44 lines
943 B
Rust
44 lines
943 B
Rust
|
//! 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);
|
||
|
|
||
|
assert_eq!(input.required(&db), true);
|
||
|
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);
|
||
|
|
||
|
assert_eq!(input.required(&db), true);
|
||
|
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);
|
||
|
|
||
|
assert_eq!(input.required(&db), true);
|
||
|
assert_eq!(input.optional(&db), 0);
|
||
|
}
|