Core CI / core (macos-latest) (push) Canceled after 0s
Core CI / core (windows-latest) (push) Canceled after 0s
Core CI / desktop (macos-latest) (push) Canceled after 0s
Core CI / desktop (ubuntu-latest) (push) Canceled after 0s
Core CI / desktop (windows-latest) (push) Canceled after 0s
Core CI / core (ubuntu-latest) (push) Canceled after 2m23s
93 lines
3.1 KiB
Rust
93 lines
3.1 KiB
Rust
use anyhow::Result;
|
|
use searchi_core::{SearchIndex, SearchOptions, SourceLocation};
|
|
use std::fs;
|
|
|
|
#[test]
|
|
fn code_scope_filters_before_limit_and_extracts_build_files() -> Result<()> {
|
|
let root = tempfile::tempdir()?;
|
|
for number in 0..100 {
|
|
fs::write(
|
|
root.path().join(format!("early{number}.txt")),
|
|
"refreshAccessToken",
|
|
)?;
|
|
}
|
|
fs::write(
|
|
root.path().join("last.go"),
|
|
"func refreshAccessToken() {}\n",
|
|
)?;
|
|
fs::write(
|
|
root.path().join("Makefile"),
|
|
"refreshAccessToken:\n\techo ready\n",
|
|
)?;
|
|
fs::write(root.path().join("large.rs"), "\n".repeat(1_000_000))?;
|
|
let mut index = SearchIndex::open(":memory:")?;
|
|
index.index_folder(root.path())?;
|
|
assert_eq!(index.search("large.rs", 1)?[0].filename, "large.rs");
|
|
let options = SearchOptions {
|
|
code_only: true,
|
|
..Default::default()
|
|
};
|
|
let results = index.search_with_options("refreshAccessToken", 2, &options)?;
|
|
assert_eq!(results.len(), 2);
|
|
assert!(results
|
|
.iter()
|
|
.all(|r| r.filename == "last.go" || r.filename == "Makefile"));
|
|
assert!(results
|
|
.iter()
|
|
.all(|r| r.source.is_some() && r.snippet.contains("refreshAccessToken")));
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn overlapping_source_passages_preserve_routine_and_actual_lines() -> Result<()> {
|
|
let root = tempfile::tempdir()?;
|
|
let file = root.path().join("module.swift");
|
|
let mut lines = vec!["// filler\n"; 166];
|
|
lines[116] = "func importantRoutine() {\n";
|
|
lines[136] = " return finalValue\n";
|
|
lines[137] = "}\n";
|
|
fs::write(&file, lines.concat())?;
|
|
let mut index = SearchIndex::open(":memory:")?;
|
|
index.index_folder(root.path())?;
|
|
let path = fs::canonicalize(file)?.to_string_lossy().into_owned();
|
|
let passage = index
|
|
.source_passage(
|
|
&path,
|
|
&SourceLocation {
|
|
kind: "line".into(),
|
|
number: 97,
|
|
},
|
|
8192,
|
|
)?
|
|
.unwrap();
|
|
assert_eq!(passage.text, lines[96..].concat());
|
|
assert!(passage.text.contains("importantRoutine") && passage.text.contains("finalValue"));
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn old_code_index_reextracts_unchanged_source_on_upgrade() -> Result<()> {
|
|
let root = tempfile::tempdir()?;
|
|
let files = root.path().join("files");
|
|
fs::create_dir(&files)?;
|
|
fs::write(files.join("module.java"), "class Evidence {}")?;
|
|
fs::write(files.join("notes.txt"), "ordinary evidence")?;
|
|
let db = root.path().join("index.db");
|
|
let mut index = SearchIndex::open(&db)?;
|
|
index.index_folder(&files)?;
|
|
drop(index);
|
|
let connection = rusqlite::Connection::open(&db)?;
|
|
connection.execute_batch("PRAGMA user_version=10;")?;
|
|
drop(connection);
|
|
let mut index = SearchIndex::open(&db)?;
|
|
assert_eq!(index.search("module.java", 1)?[0].filename, "module.java");
|
|
let report = index.index_folder(&files)?;
|
|
assert_eq!(report.indexed, 1);
|
|
assert_eq!(report.unchanged, 1);
|
|
assert!(index
|
|
.search("Evidence", 10)?
|
|
.iter()
|
|
.any(|r| r.filename == "module.java" && r.source.is_some()));
|
|
Ok(())
|
|
}
|