2024-05-16 09:18:56 +00:00
|
|
|
//! Test that a `tracked` fn on a `salsa::input`
|
|
|
|
//! compiles and executes successfully.
|
2024-06-18 07:40:21 +00:00
|
|
|
mod common;
|
|
|
|
use common::{HasLogger, Logger};
|
2024-05-16 09:18:56 +00:00
|
|
|
|
|
|
|
use expect_test::expect;
|
|
|
|
use test_log::test;
|
|
|
|
|
2024-07-17 09:33:51 +00:00
|
|
|
#[salsa::db]
|
|
|
|
trait Db: salsa::Database + HasLogger {}
|
2024-05-16 09:18:56 +00:00
|
|
|
|
|
|
|
#[salsa::interned]
|
|
|
|
struct InternedString<'db> {
|
|
|
|
data: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[salsa::interned]
|
|
|
|
struct InternedPair<'db> {
|
|
|
|
data: (InternedString<'db>, InternedString<'db>),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[salsa::tracked]
|
|
|
|
fn intern_stuff(db: &dyn Db) -> String {
|
2024-05-30 12:23:42 +00:00
|
|
|
let s1 = InternedString::new(db, "Hello, ".to_string());
|
|
|
|
let s2 = InternedString::new(db, "World, ".to_string());
|
2024-05-16 09:18:56 +00:00
|
|
|
let s3 = InternedPair::new(db, (s1, s2));
|
2024-07-17 09:47:56 +00:00
|
|
|
format!("{s3:?}")
|
2024-05-16 09:18:56 +00:00
|
|
|
}
|
|
|
|
|
2024-07-17 09:33:51 +00:00
|
|
|
#[salsa::db]
|
2024-05-16 09:18:56 +00:00
|
|
|
#[derive(Default)]
|
|
|
|
struct Database {
|
|
|
|
storage: salsa::Storage<Self>,
|
|
|
|
logger: Logger,
|
|
|
|
}
|
|
|
|
|
2024-07-17 09:33:51 +00:00
|
|
|
#[salsa::db]
|
2024-05-16 09:18:56 +00:00
|
|
|
impl salsa::Database for Database {}
|
|
|
|
|
2024-07-17 09:33:51 +00:00
|
|
|
#[salsa::db]
|
2024-05-16 09:18:56 +00:00
|
|
|
impl Db for Database {}
|
|
|
|
|
|
|
|
impl HasLogger for Database {
|
|
|
|
fn logger(&self) -> &Logger {
|
|
|
|
&self.logger
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn execute() {
|
|
|
|
let mut db = Database::default();
|
|
|
|
|
|
|
|
expect![[r#"
|
2024-07-17 09:47:56 +00:00
|
|
|
"InternedPair { data: (InternedString { data: \"Hello, \" }, InternedString { data: \"World, \" }) }"
|
2024-05-16 09:18:56 +00:00
|
|
|
"#]].assert_debug_eq(&intern_stuff(&db));
|
|
|
|
db.assert_logs(expect!["[]"]);
|
|
|
|
}
|