1use crate::{protocol::*, Result};
6
7pub struct ReplClient {
9 }
12
13impl ReplClient {
14 pub fn new() -> Self {
15 Self {}
16 }
17
18 pub fn send(&mut self, request: ReplRequest) -> Result<ReplResponse> {
20 match request {
22 ReplRequest::Eval { .. } => Ok(ReplResponse::Value { value: "result".to_string() }),
23 ReplRequest::Status => {
24 Ok(ReplResponse::Status { tier1_count: 0, tier2_count: 0, tier3_count: 0 })
25 }
26 _ => Ok(ReplResponse::Ok),
27 }
28 }
29
30 pub fn run(&mut self) -> Result<()> {
32 println!("Oxur REPL v0.1.0");
33 println!("Type (exit) to quit");
34
35 Ok(())
37 }
38}
39
40impl Default for ReplClient {
41 fn default() -> Self {
42 Self::new()
43 }
44}
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn test_client_creation() {
52 let _client = ReplClient::new();
53 }
54
55 #[test]
56 fn test_client_default() {
57 let _client = ReplClient::default();
58 }
59
60 #[test]
61 fn test_send_eval() {
62 let mut client = ReplClient::new();
63 let req = ReplRequest::Eval { source: "(+ 1 2)".to_string() };
64 let resp = client.send(req);
65 assert!(resp.is_ok());
66 match resp.unwrap() {
67 ReplResponse::Value { value } => assert_eq!(value, "result"),
68 _ => panic!("Expected Value response"),
69 }
70 }
71
72 #[test]
73 fn test_send_status() {
74 let mut client = ReplClient::new();
75 let req = ReplRequest::Status;
76 let resp = client.send(req);
77 assert!(resp.is_ok());
78 match resp.unwrap() {
79 ReplResponse::Status { tier1_count, tier2_count, tier3_count } => {
80 assert_eq!(tier1_count, 0);
81 assert_eq!(tier2_count, 0);
82 assert_eq!(tier3_count, 0);
83 }
84 _ => panic!("Expected Status response"),
85 }
86 }
87
88 #[test]
89 fn test_send_reset() {
90 let mut client = ReplClient::new();
91 let req = ReplRequest::Reset;
92 let resp = client.send(req);
93 assert!(resp.is_ok());
94 }
95
96 #[test]
97 fn test_send_load() {
98 let mut client = ReplClient::new();
99 let req = ReplRequest::Load { path: "test.ox".to_string() };
100 let resp = client.send(req);
101 assert!(resp.is_ok());
102 }
103
104 #[test]
105 fn test_send_shutdown() {
106 let mut client = ReplClient::new();
107 let req = ReplRequest::Shutdown;
108 let resp = client.send(req);
109 assert!(resp.is_ok());
110 }
111
112 #[test]
113 fn test_run_does_not_panic() {
114 let mut client = ReplClient::new();
115 let result = client.run();
116 assert!(result.is_ok());
117 }
118}