use cs::{run_search, SearchQuery};
use std::fs;
use tempfile::TempDir;
#[test]
fn test_reproduce_issue_0() {
let temp_dir = TempDir::new().unwrap();
let base_dir = temp_dir.path().to_path_buf();
let locales_dir = base_dir.join("locales");
fs::create_dir(&locales_dir).unwrap();
fs::write(
locales_dir.join("en.yml"),
r#"
en-US:
app:
production_and_service:
new_page:
labels:
add_new: "Add New"
"#,
)
.unwrap();
let src_dir = base_dir.join("src");
fs::create_dir(&src_dir).unwrap();
fs::write(
src_dir.join("index.js"),
"console.log(i18n.t('production_and_service.new_page.labels.add_new'));",
)
.unwrap();
let query = SearchQuery::new("Add New".to_string()).with_base_dir(base_dir.clone());
let result = run_search(query).unwrap();
println!(
"Found {} translation entries",
result.translation_entries.len()
);
for entry in &result.translation_entries {
println!("Entry: {} = {}", entry.key, entry.value);
}
println!("Found {} code references", result.code_references.len());
for reference in &result.code_references {
println!("Ref: {:?} -> {}", reference.file, reference.key_path);
}
assert_eq!(
result.translation_entries.len(),
1,
"Should find translation entry"
);
assert_eq!(
result.translation_entries[0].key,
"en-US.app.production_and_service.new_page.labels.add_new"
);
assert!(
!result.code_references.is_empty(),
"Should find code reference"
);
assert_eq!(
result.code_references[0].key_path,
"production_and_service.new_page.labels.add_new"
);
}