use assert_cmd::{cargo_bin, Command};
use predicates::prelude::*;
use std::fs;
use tempfile::TempDir;
#[test]
fn test_multiple_code_references_all_shown() {
let mut cmd = Command::new(cargo_bin!("cs"));
cmd.arg("add new")
.current_dir("tests/fixtures/rails-app")
.assert()
.success()
.stdout(predicate::str::contains("invoice_list.ts"))
.stdout(predicate::str::contains("invoices.ts")); }
#[test]
fn test_multiple_usages_show_line_numbers() {
let mut cmd = Command::new(cargo_bin!("cs"));
cmd.arg("add new")
.current_dir("tests/fixtures/rails-app")
.assert()
.success()
.stdout(predicate::str::contains(":12)"))
.stdout(predicate::str::contains(":14)"))
.stdout(predicate::str::contains(":22)"));
}
#[test]
fn test_multiple_translation_files() {
let mut cmd = Command::new(cargo_bin!("cs"));
cmd.arg("ajouter nouveau") .current_dir("tests/fixtures/rails-app")
.assert()
.success()
.stdout(predicate::str::contains("fr.yml"));
}
#[test]
fn test_partial_key_matching() {
let mut cmd = Command::new(cargo_bin!("cs"));
cmd.arg("add new")
.current_dir("tests/fixtures/rails-app")
.assert()
.success()
.stdout(predicate::str::contains("invoice.labels.add_new"))
.stdout(predicate::str::contains("labels.add_new"))
.stdout(predicate::str::contains("invoice.labels"));
}
#[test]
fn test_multiple_patterns_detected() {
let mut cmd = Command::new(cargo_bin!("cs"));
cmd.arg("add new")
.current_dir("tests/fixtures/rails-app")
.assert()
.success()
.stdout(predicate::str::contains("I18n.t("));
}
#[test]
fn test_related_usages_grouped() {
let mut cmd = Command::new(cargo_bin!("cs"));
cmd.arg("add new")
.current_dir("tests/fixtures/rails-app")
.assert()
.success()
.stdout(predicate::str::contains("├─>").or(predicate::str::contains("└─>")));
}
#[test]
fn test_multiple_keys_with_same_value() {
let temp_dir = TempDir::new().unwrap();
let yaml_path = temp_dir.path().join("config/locales");
fs::create_dir_all(&yaml_path).unwrap();
let yaml_file = yaml_path.join("en.yml");
fs::write(
&yaml_file,
"en:\n key1: \"submit\"\n key2: \"submit\"\n nested:\n key3: \"submit\"",
)
.unwrap();
let mut cmd = Command::new(cargo_bin!("cs"));
cmd.arg("submit")
.current_dir(temp_dir.path())
.assert()
.success()
.stdout(predicate::str::contains("key1"))
.stdout(predicate::str::contains("key2"))
.stdout(predicate::str::contains("nested.key3"));
}
#[test]
fn test_deeply_nested_keys() {
let temp_dir = TempDir::new().unwrap();
let yaml_path = temp_dir.path().join("config/locales");
fs::create_dir_all(&yaml_path).unwrap();
let yaml_file = yaml_path.join("en.yml");
fs::write(&yaml_file,
"en:\n app:\n views:\n invoice:\n form:\n labels:\n add_new: \"Add New\"").unwrap();
let mut cmd = Command::new(cargo_bin!("cs"));
cmd.arg("Add New")
.current_dir(temp_dir.path())
.assert()
.success()
.stdout(predicate::str::contains(
"app.views.invoice.form.labels.add_new",
));
}
#[test]
fn test_cross_file_references() {
let mut cmd = Command::new(cargo_bin!("cs"));
cmd.arg("add new")
.current_dir("tests/fixtures/rails-app")
.assert()
.success()
.stdout(predicate::str::contains("invoice_list.ts"))
.stdout(predicate::str::contains("invoices.ts"));
}
#[test]
fn test_no_duplicate_results() {
let mut cmd = Command::new(cargo_bin!("cs"));
let output = cmd
.arg("add new")
.current_dir("tests/fixtures/rails-app")
.output()
.unwrap();
let stdout = String::from_utf8_lossy(&output.stdout);
let lines: Vec<&str> = stdout.lines().collect();
let mut seen = std::collections::HashSet::new();
for line in lines {
if line.contains(".ts:") {
if seen.contains(line) {
panic!("Duplicate line found: {}", line);
}
seen.insert(line);
}
}
}
#[test]
fn test_multiple_frameworks_in_one_project() {
let temp_dir = TempDir::new().unwrap();
let yaml_path = temp_dir.path().join("locales");
fs::create_dir_all(&yaml_path).unwrap();
fs::write(yaml_path.join("en.yml"), "en:\n greeting: \"Hello\"").unwrap();
fs::write(temp_dir.path().join("ruby.rb"), "I18n.t('greeting')").unwrap();
fs::write(temp_dir.path().join("react.tsx"), "t('greeting')").unwrap();
fs::write(temp_dir.path().join("vue.vue"), "$t('greeting')").unwrap();
let mut cmd = Command::new(cargo_bin!("cs"));
cmd.arg("Hello")
.current_dir(temp_dir.path())
.assert()
.success()
.stdout(predicate::str::contains("ruby.rb"))
.stdout(predicate::str::contains("react.tsx"))
.stdout(predicate::str::contains("vue.vue"));
}