use serde_json::json;
use std::collections::HashMap;
#[test]
fn test_json_rpc_format() {
let request = json!({
"jsonrpc": "2.0",
"method": "test_method",
"params": {"key": "value"},
"id": 1
});
assert_eq!(request["jsonrpc"], "2.0");
assert_eq!(request["method"], "test_method");
assert_eq!(request["id"], 1);
}
#[test]
fn test_http_request_format() {
let mut headers = HashMap::new();
headers.insert("content-type".to_string(), "application/json".to_string());
headers.insert("accept".to_string(), "application/json".to_string());
assert_eq!(
headers.get("content-type"),
Some(&"application/json".to_string())
);
assert_eq!(headers.get("accept"), Some(&"application/json".to_string()));
}
#[test]
fn test_cli_argument_parsing() {
let args = ["analyze", "complexity", ".", "--json"];
assert_eq!(args[0], "analyze");
assert_eq!(args[1], "complexity");
assert_eq!(args[2], ".");
assert!(args.contains(&"--json"));
}
#[test]
fn test_protocol_response_formats() {
let jsonrpc_response = json!({
"jsonrpc": "2.0",
"result": {"status": "success"},
"id": 1
});
let http_response = json!({
"status": 200,
"body": {"status": "success"}
});
let cli_response = json!({
"status": "success"
});
assert_eq!(jsonrpc_response["result"]["status"], "success");
assert_eq!(http_response["body"]["status"], "success");
assert_eq!(cli_response["status"], "success");
}
#[test]
fn test_error_response_formats() {
let jsonrpc_error = json!({
"jsonrpc": "2.0",
"error": {
"code": -32601,
"message": "Method not found"
},
"id": 1
});
let http_error = json!({
"status": 404,
"error": "Not Found"
});
let cli_error = json!({
"error": "Command not found"
});
assert_eq!(jsonrpc_error["error"]["code"], -32601);
assert_eq!(http_error["status"], 404);
assert!(cli_error["error"].is_string());
}
#[test]
fn test_parameter_normalization() {
let mcp_params = json!({
"path": ".",
"threshold": 10,
"format": "json"
});
let http_params = json!({
"path": ".",
"options": {
"threshold": 10,
"format": "json"
}
});
let cli_params = [".", "--threshold", "10", "--format", "json"];
assert_eq!(mcp_params["path"], ".");
assert_eq!(mcp_params["threshold"], 10);
assert_eq!(http_params["path"], ".");
assert_eq!(http_params["options"]["threshold"], 10);
assert_eq!(cli_params[0], ".");
assert!(cli_params.contains(&"--threshold"));
assert!(cli_params.contains(&"10"));
}