mirror of
https://github.com/salsa-rs/salsa.git
synced 2025-01-22 21:05:11 +00:00
Add a test
This commit is contained in:
parent
8fc6dc82ac
commit
fbb219a527
1 changed files with 57 additions and 0 deletions
57
salsa-2022-tests/tests/debug.rs
Normal file
57
salsa-2022-tests/tests/debug.rs
Normal file
|
@ -0,0 +1,57 @@
|
|||
//! Test that a `tracked` fn on a `salsa::input`
|
||||
//! compiles and executes successfully.
|
||||
|
||||
use expect_test::expect;
|
||||
use test_log::test;
|
||||
use salsa::DebugWithDb;
|
||||
|
||||
#[salsa::jar(db = Db)]
|
||||
struct Jar(MyInput, ComplexStruct);
|
||||
|
||||
trait Db: salsa::DbWithJar<Jar> {}
|
||||
|
||||
#[salsa::input]
|
||||
struct MyInput {
|
||||
field: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||
struct NotSalsa {
|
||||
field: String,
|
||||
}
|
||||
|
||||
#[salsa::input]
|
||||
struct ComplexStruct {
|
||||
my_input: MyInput,
|
||||
not_salsa: NotSalsa,
|
||||
}
|
||||
|
||||
#[salsa::db(Jar)]
|
||||
#[derive(Default)]
|
||||
struct Database {
|
||||
storage: salsa::Storage<Self>,
|
||||
}
|
||||
|
||||
impl salsa::Database for Database {
|
||||
fn salsa_runtime(&self) -> &salsa::Runtime {
|
||||
self.storage.runtime()
|
||||
}
|
||||
}
|
||||
|
||||
impl Db for Database {}
|
||||
|
||||
|
||||
#[test]
|
||||
fn execute() {
|
||||
let mut db = Database::default();
|
||||
|
||||
let input = MyInput::new(&mut db, 22);
|
||||
let not_salsa = NotSalsa {
|
||||
field: "it's salsa time".to_string(),
|
||||
};
|
||||
let complex_struct = ComplexStruct::new(&mut db, input, not_salsa);
|
||||
|
||||
let actual = format!("{:?}", complex_struct.debug(&db));
|
||||
let expected = expect![[r#"ComplexStruct { [salsa id]: 0, my_input: MyInput { [salsa id]: 0, field: 22 }, not_salsa: NotSalsa { field: "it's salsa time" } }"#]];
|
||||
expected.assert_eq(&actual);
|
||||
}
|
Loading…
Reference in a new issue