aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/main.rs
diff options
context:
space:
mode:
authorcopilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>2025-08-24 16:52:40 +0000
committercopilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>2025-08-24 16:52:40 +0000
commitdf985c9b639bab3edd687170fd279724b8f05d69 (patch)
treee563cb65f5b3b56ba2893297aaa6e92624ae5a2a /src/main.rs
parent5dabc731cfb0f90afd1fc69b2603070149da43be (diff)
downloadsoon-copilot/fix-3fe7bfbf-c7ce-4f76-a4e2-75649693787c.tar.gz
soon-copilot/fix-3fe7bfbf-c7ce-4f76-a4e2-75649693787c.zip
Add comprehensive unit tests and CI test scriptcopilot/fix-3fe7bfbf-c7ce-4f76-a4e2-75649693787c
Co-authored-by: HsiangNianian <44714368+HsiangNianian@users.noreply.github.com>
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
index 245810f..443a2ab 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -567,3 +567,71 @@ fn main() {
}
}
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_main_cmd_extraction() {
+ assert_eq!(main_cmd("git status"), "git");
+ assert_eq!(main_cmd("ls -la"), "ls");
+ assert_eq!(main_cmd(""), "");
+ assert_eq!(main_cmd("single"), "single");
+ assert_eq!(main_cmd(" spaced command "), "spaced");
+ }
+
+ #[test]
+ fn test_is_ignored_command() {
+ assert_eq!(is_ignored_command("soon"), true);
+ assert_eq!(is_ignored_command("cd"), true);
+ assert_eq!(is_ignored_command("ls"), true);
+ assert_eq!(is_ignored_command("pwd"), true);
+ assert_eq!(is_ignored_command("exit"), true);
+ assert_eq!(is_ignored_command("clear"), true);
+ assert_eq!(is_ignored_command("git"), false);
+ assert_eq!(is_ignored_command("cargo"), false);
+ }
+
+ #[test]
+ fn test_detect_shell() {
+ // This test will depend on the actual environment
+ let shell = detect_shell();
+ assert!(shell == "bash" || shell == "zsh" || shell == "fish" || shell == "unknown");
+ }
+
+ #[test]
+ fn test_history_path() {
+ let bash_path = history_path("bash");
+ assert!(bash_path.is_some());
+ assert!(bash_path.unwrap().ends_with(".bash_history"));
+
+ let zsh_path = history_path("zsh");
+ assert!(zsh_path.is_some());
+ assert!(zsh_path.unwrap().ends_with(".zsh_history"));
+
+ let fish_path = history_path("fish");
+ assert!(fish_path.is_some());
+ assert!(fish_path.unwrap().ends_with("fish_history"));
+
+ let unknown_path = history_path("unknown");
+ assert!(unknown_path.is_some());
+ // Unknown shell returns empty PathBuf
+ }
+
+ #[test]
+ fn test_get_cache_path() {
+ let cache_path = get_cache_path();
+ assert!(cache_path.ends_with(".soon_cache"));
+ }
+
+ #[test]
+ fn test_history_item_creation() {
+ let item = HistoryItem {
+ cmd: "test command".to_string(),
+ path: Some("/home/user".to_string()),
+ };
+ assert_eq!(item.cmd, "test command");
+ assert_eq!(item.path, Some("/home/user".to_string()));
+ }
+}
+