mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
feat: optimize hotkey behavior and window management logic
This commit is contained in:
@@ -394,85 +394,4 @@ impl CoreManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
async fn create_test_script() -> Result<String> {
|
||||
let temp_dir = std::env::temp_dir();
|
||||
let script_path = temp_dir.join("test_script.js");
|
||||
let script_content = r#"
|
||||
// This is a test script
|
||||
function main(config) {
|
||||
console.log("Testing script");
|
||||
return config;
|
||||
}
|
||||
"#;
|
||||
|
||||
fs::write(&script_path, script_content)?;
|
||||
Ok(script_path.to_string_lossy().to_string())
|
||||
}
|
||||
|
||||
async fn create_invalid_script() -> Result<String> {
|
||||
let temp_dir = std::env::temp_dir();
|
||||
let script_path = temp_dir.join("invalid_script.js");
|
||||
let script_content = r#"
|
||||
// This is an invalid script
|
||||
function main(config { // Missing closing parenthesis
|
||||
console.log("Testing script");
|
||||
return config;
|
||||
}
|
||||
"#;
|
||||
|
||||
fs::write(&script_path, script_content)?;
|
||||
Ok(script_path.to_string_lossy().to_string())
|
||||
}
|
||||
|
||||
async fn create_no_main_script() -> Result<String> {
|
||||
let temp_dir = std::env::temp_dir();
|
||||
let script_path = temp_dir.join("no_main_script.js");
|
||||
let script_content = r#"
|
||||
// This script has no main function
|
||||
function helper(config) {
|
||||
console.log("Testing script");
|
||||
return config;
|
||||
}
|
||||
"#;
|
||||
|
||||
fs::write(&script_path, script_content)?;
|
||||
Ok(script_path.to_string_lossy().to_string())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_validate_script_file() -> Result<()> {
|
||||
let core_manager = CoreManager::global();
|
||||
|
||||
// 测试有效脚本
|
||||
let script_path = create_test_script().await?;
|
||||
let result = core_manager.validate_config_file(&script_path).await?;
|
||||
assert!(result.0, "有效脚本应该通过验证");
|
||||
|
||||
// 测试无效脚本
|
||||
let invalid_script_path = create_invalid_script().await?;
|
||||
let result = core_manager.validate_config_file(&invalid_script_path).await?;
|
||||
assert!(!result.0, "无效脚本不应该通过验证");
|
||||
assert!(result.1.contains("脚本语法错误"), "无效脚本应该返回语法错误");
|
||||
|
||||
// 测试缺少main函数的脚本
|
||||
let no_main_script_path = create_no_main_script().await?;
|
||||
let result = core_manager.validate_config_file(&no_main_script_path).await?;
|
||||
assert!(!result.0, "缺少main函数的脚本不应该通过验证");
|
||||
assert!(result.1.contains("缺少main函数"), "应该提示缺少main函数");
|
||||
|
||||
// 清理测试文件
|
||||
let _ = fs::remove_file(script_path);
|
||||
let _ = fs::remove_file(invalid_script_path);
|
||||
let _ = fs::remove_file(no_main_script_path);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user