aboutsummaryrefslogtreecommitdiffstats
path: root/crates/turtle/src/atuin_daemon
diff options
context:
space:
mode:
Diffstat (limited to 'crates/turtle/src/atuin_daemon')
-rw-r--r--crates/turtle/src/atuin_daemon/search/mod.rs129
1 files changed, 4 insertions, 125 deletions
diff --git a/crates/turtle/src/atuin_daemon/search/mod.rs b/crates/turtle/src/atuin_daemon/search/mod.rs
index 04beb459..02c79c9c 100644
--- a/crates/turtle/src/atuin_daemon/search/mod.rs
+++ b/crates/turtle/src/atuin_daemon/search/mod.rs
@@ -93,7 +93,9 @@ impl FrecencyData {
let frequency_score = (f64::from(self.count).ln() * 20.0).min(100.0);
// Apply multipliers and combine scores, then round to u32
- recency_score.mul_add(recency_mul, frequency_score * frequency_mul).round() as u32
+ recency_score
+ .mul_add(recency_mul, frequency_score * frequency_mul)
+ .round() as u32
}
}
@@ -481,8 +483,7 @@ impl Default for SearchIndex {
#[cfg(test)]
mod tests {
- use super::*;
- use time::macros::datetime;
+ use super::FrecencyData;
#[test]
fn frecency_data_compute() {
@@ -553,126 +554,4 @@ mod tests {
assert!(boost_recency > default_score);
assert!(boost_recency < double_recency);
}
-
- #[test]
- fn command_data_add_invocation() {
- let interner = ThreadedRodeo::new();
-
- let (dir1, dir2) = if cfg!(windows) {
- ("C:\\Users\\User\\project", "C:\\Users\\User\\other")
- } else {
- ("/home/user/project", "/home/user/other")
- };
-
- let history1 = make_history("git status", dir1, datetime!(2024-01-01 10:00 UTC));
- let history2 = make_history("git status", dir2, datetime!(2024-01-01 12:00 UTC));
-
- let mut data = CommandData::new(&history1, &interner).unwrap();
- assert_eq!(data.global_frecency.count, 1);
- let id1 = data.most_recent_id();
-
- data.add_invocation(&history2, &interner);
- assert_eq!(data.global_frecency.count, 2);
-
- // Most recent ID should update to history2 (newer timestamp)
- let id2 = data.most_recent_id();
- assert_ne!(id1, id2);
- }
-
- #[test]
- fn command_data_filters() {
- let interner = ThreadedRodeo::new();
-
- let (dir1, dir2) = if cfg!(windows) {
- ("C:\\Users\\User\\project", "C:\\Users\\User\\other")
- } else {
- ("/home/user/project", "/home/user/other")
- };
-
- let h1 = make_history("git status", dir1, datetime!(2024-01-01 10:00 UTC));
- let h2 = make_history("git status", dir2, datetime!(2024-01-01 12:00 UTC));
-
- let mut data = CommandData::new(&h1, &interner).unwrap();
- data.add_invocation(&h2, &interner);
-
- let (check1, check2, check3) = if cfg!(windows) {
- (
- with_trailing_slash("C:\\Users\\User\\project"),
- with_trailing_slash("C:\\Users\\User\\other"),
- with_trailing_slash("C:\\Users\\User\\missing"),
- )
- } else {
- (
- with_trailing_slash("/home/user/project"),
- with_trailing_slash("/home/user/other"),
- with_trailing_slash("/home/user/missing"),
- )
- };
-
- assert!(data.has_invocation_in_dir(&check1, &interner));
- assert!(data.has_invocation_in_dir(&check2, &interner));
- assert!(!data.has_invocation_in_dir(&check3, &interner));
-
- let (check1, check2, check3) = if cfg!(windows) {
- (
- with_trailing_slash("C:\\Users\\User"),
- with_trailing_slash("C:\\Users"),
- with_trailing_slash("C:\\Users\\User\\var"),
- )
- } else {
- (
- with_trailing_slash("/home/user"),
- with_trailing_slash("/home"),
- with_trailing_slash("/var"),
- )
- };
-
- assert!(data.has_invocation_in_workspace(&check1, &interner));
- assert!(data.has_invocation_in_workspace(&check2, &interner));
- assert!(!data.has_invocation_in_workspace(&check3, &interner));
- }
-
- #[tokio::test]
- async fn search_index_add_and_search() {
- let index = SearchIndex::new();
-
- let h1 = make_history(
- "git status",
- "/home/user/project",
- datetime!(2024-01-01 10:00 UTC),
- );
- let h2 = make_history(
- "git commit -m 'test'",
- "/home/user/project",
- datetime!(2024-01-01 10:05 UTC),
- );
- let h3 = make_history(
- "ls -la",
- "/home/user/other",
- datetime!(2024-01-01 10:10 UTC),
- );
-
- index.add_history(&h1);
- index.add_history(&h2);
- index.add_history(&h3);
-
- assert_eq!(index.command_count(), 3);
-
- // Search for "git" - should match 2 commands
- let results = index
- .search("git", IndexFilterMode::Global, &QueryContext::default(), 10)
- .await;
- assert_eq!(results.len(), 2);
-
- // Search with directory filter
- let results = index
- .search(
- "",
- IndexFilterMode::Directory(with_trailing_slash("/home/user/project")),
- &QueryContext::default(),
- 10,
- )
- .await;
- assert_eq!(results.len(), 2); // git status and git commit
- }
}