salsa/tests/interned-struct-with-lifetime.rs

32 lines
812 B
Rust
Raw Normal View History

2024-05-16 09:18:56 +00:00
//! Test that a `tracked` fn on a `salsa::input`
//! compiles and executes successfully.
use expect_test::expect;
use test_log::test;
#[salsa::interned]
struct InternedString<'db> {
data: String,
}
#[salsa::interned]
struct InternedPair<'db> {
data: (InternedString<'db>, InternedString<'db>),
}
#[salsa::tracked]
fn intern_stuff(db: &dyn salsa::Database) -> 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
}
#[test]
fn execute() {
let db = salsa::DatabaseImpl::new();
2024-05-16 09:18:56 +00:00
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));
}