use rumdl_lib::vscode::{EXTENSION_ID, VsCodeExtension, handle_vscode_command};
mod mock_tests {
use super::*;
#[test]
fn test_install_with_fake_command() {
let result = VsCodeExtension::with_command("echo");
if let Ok(ext) = result {
let install_result = ext.install(false);
assert!(install_result.is_ok());
}
}
#[test]
fn test_install_force_flag() {
let result = VsCodeExtension::with_command("echo");
if let Ok(ext) = result {
let install_result = ext.install(true);
assert!(install_result.is_ok()); }
}
#[test]
fn test_is_installed_error_handling() {
let result = VsCodeExtension::with_command("echo");
if let Ok(ext) = result {
let is_installed_result = ext.is_installed();
if let Ok(installed) = is_installed_result {
assert!(!installed);
}
}
}
#[test]
fn test_show_status_behavior() {
let result = VsCodeExtension::with_command("echo");
if let Ok(ext) = result {
let status_result = ext.show_status();
let _ = status_result;
}
}
}
#[test]
fn test_vscode_extension_creation_error() {
let no_commands_checker = |_cmd: &str| false;
let result = VsCodeExtension::find_code_command_impl(no_commands_checker);
assert!(result.is_err());
if let Err(e) = result {
assert!(e.contains("not found"));
assert!(e.contains("code") || e.contains("cursor") || e.contains("windsurf"));
}
}
#[test]
fn test_find_all_editors_empty_path() {
let no_commands_checker = |_cmd: &str| false;
let editors = VsCodeExtension::find_all_editors_impl(no_commands_checker);
assert!(editors.is_empty());
}
#[test]
fn test_handle_vscode_command_status_flag() {
let result = handle_vscode_command(false, false, true);
let _ = result;
let result = handle_vscode_command(false, false, false);
let _ = result;
let result = handle_vscode_command(false, true, false);
let _ = result;
}
#[test]
fn test_install_output_parsing() {
let result = VsCodeExtension::with_command("false");
if let Ok(ext) = result {
match ext.install(false) {
Ok(_) => panic!("Expected error"),
Err(e) => {
assert!(!e.is_empty());
}
}
}
}
#[test]
fn test_version_parsing_logic() {
let test_cases = vec![
("rvben.rumdl@0.0.10", Some("0.0.10")),
("rvben.rumdl@1.2.3", Some("1.2.3")),
("rvben.rumdl", None), ("other.extension@1.0.0", None), ("", None), ];
for (line, expected) in test_cases {
if line.starts_with(EXTENSION_ID) {
let version = line.split('@').nth(1);
assert_eq!(version, expected);
}
}
}
#[test]
fn test_command_exists_edge_cases() {
let result = VsCodeExtension::with_command("/nonexistent/path/to/command");
assert!(result.is_err());
let result = VsCodeExtension::with_command("");
assert!(result.is_err());
let result = VsCodeExtension::with_command("command with spaces");
assert!(result.is_err());
}
#[test]
fn test_error_message_formats() {
let result = VsCodeExtension::with_command("false"); if let Ok(_ext) = result {
if let Err(e) = _ext.install(false) {
assert!(!e.is_empty());
}
if let Err(e) = _ext.is_installed() {
assert!(e.contains("Failed") || e.contains("extensions"));
}
let _ = _ext.show_status(); }
}