Skip to main content

trustformers_debug/ide_integration/
functions.rs

1//! Auto-generated module
2//!
3//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
4
5#[cfg(test)]
6mod tests {
7    use super::super::*;
8    use crate::DebugConfig;
9    use std::path::PathBuf;
10    use uuid::Uuid;
11    #[test]
12    fn test_supported_ide_variants() {
13        let ides = [
14            SupportedIDE::VSCode,
15            SupportedIDE::IntelliJ,
16            SupportedIDE::Vim,
17            SupportedIDE::Emacs,
18            SupportedIDE::Sublime,
19            SupportedIDE::Atom,
20            SupportedIDE::Jupyter,
21            SupportedIDE::JupyterLab,
22            SupportedIDE::Custom("custom_ide".to_string()),
23        ];
24        assert_eq!(ides.len(), 9);
25    }
26    #[test]
27    fn test_ide_capabilities_creation() {
28        let caps = IDECapabilities {
29            syntax_highlighting: true,
30            code_completion: true,
31            inline_debugging: true,
32            tensor_visualization: true,
33            real_time_metrics: true,
34            breakpoint_management: true,
35            call_stack_navigation: true,
36            variable_inspection: true,
37            performance_profiling: true,
38            error_annotations: true,
39            jupyter_widgets: false,
40            interactive_plots: false,
41            notebook_integration: false,
42            kernel_communication: false,
43        };
44        assert!(caps.syntax_highlighting);
45        assert!(!caps.jupyter_widgets);
46    }
47    #[test]
48    fn test_ide_message_set_breakpoint() {
49        let msg = IDEMessage::SetBreakpoint {
50            file: PathBuf::from("/src/main.rs"),
51            line: 42,
52            condition: Some("x > 10".to_string()),
53        };
54        match msg {
55            IDEMessage::SetBreakpoint {
56                file,
57                line,
58                condition,
59            } => {
60                assert_eq!(file, PathBuf::from("/src/main.rs"));
61                assert_eq!(line, 42);
62                assert!(condition.is_some());
63            },
64            _ => panic!("Expected SetBreakpoint"),
65        }
66    }
67    #[test]
68    fn test_ide_message_remove_breakpoint() {
69        let msg = IDEMessage::RemoveBreakpoint {
70            file: PathBuf::from("/src/lib.rs"),
71            line: 10,
72        };
73        match msg {
74            IDEMessage::RemoveBreakpoint { file, line } => {
75                assert_eq!(file, PathBuf::from("/src/lib.rs"));
76                assert_eq!(line, 10);
77            },
78            _ => panic!("Expected RemoveBreakpoint"),
79        }
80    }
81    #[test]
82    fn test_ide_message_control_variants() {
83        let messages = [
84            IDEMessage::StepInto,
85            IDEMessage::StepOver,
86            IDEMessage::StepOut,
87            IDEMessage::Continue,
88            IDEMessage::Pause,
89        ];
90        assert_eq!(messages.len(), 5);
91    }
92    #[test]
93    fn test_ide_message_debug_session() {
94        let session_id = Uuid::new_v4();
95        let start_msg = IDEMessage::StartDebugSession { session_id };
96        let stop_msg = IDEMessage::StopDebugSession { session_id };
97        match start_msg {
98            IDEMessage::StartDebugSession { session_id: s } => assert_eq!(s, session_id),
99            _ => panic!("Expected StartDebugSession"),
100        }
101        match stop_msg {
102            IDEMessage::StopDebugSession { session_id: s } => assert_eq!(s, session_id),
103            _ => panic!("Expected StopDebugSession"),
104        }
105    }
106    #[test]
107    fn test_ide_message_inspect_variable() {
108        let msg = IDEMessage::InspectVariable {
109            variable_name: "tensor_weights".to_string(),
110        };
111        match msg {
112            IDEMessage::InspectVariable { variable_name } => {
113                assert_eq!(variable_name, "tensor_weights");
114            },
115            _ => panic!("Expected InspectVariable"),
116        }
117    }
118    #[test]
119    fn test_ide_message_evaluate_expression() {
120        let msg = IDEMessage::EvaluateExpression {
121            expression: "model.parameters().count()".to_string(),
122        };
123        match msg {
124            IDEMessage::EvaluateExpression { expression } => {
125                assert!(expression.contains("parameters"));
126            },
127            _ => panic!("Expected EvaluateExpression"),
128        }
129    }
130    #[test]
131    fn test_jupyter_widget_manager_new() {
132        let manager = JupyterWidgetManager::new();
133        assert!(manager.get_active_widgets().is_empty());
134        assert!(!manager.is_kernel_connected());
135    }
136    #[test]
137    fn test_jupyter_widget_manager_default() {
138        let manager = JupyterWidgetManager::default();
139        assert!(!manager.is_kernel_connected());
140    }
141    #[test]
142    fn test_jupyter_widget_manager_get_missing_widget() {
143        let manager = JupyterWidgetManager::new();
144        assert!(manager.get_widget("nonexistent").is_none());
145    }
146    #[test]
147    fn test_ide_plugin_creation() {
148        let plugin = IDEPlugin {
149            plugin_id: Uuid::new_v4(),
150            name: "TrustformeRS Debug".to_string(),
151            version: "1.0.0".to_string(),
152            supported_ides: vec![SupportedIDE::VSCode, SupportedIDE::IntelliJ],
153            capabilities: IDECapabilities {
154                syntax_highlighting: true,
155                code_completion: true,
156                inline_debugging: true,
157                tensor_visualization: true,
158                real_time_metrics: false,
159                breakpoint_management: true,
160                call_stack_navigation: true,
161                variable_inspection: true,
162                performance_profiling: false,
163                error_annotations: true,
164                jupyter_widgets: false,
165                interactive_plots: false,
166                notebook_integration: false,
167                kernel_communication: false,
168            },
169            debugger: None,
170            config: DebugConfig::default(),
171        };
172        assert_eq!(plugin.name, "TrustformeRS Debug");
173        assert_eq!(plugin.supported_ides.len(), 2);
174        assert!(plugin.capabilities.syntax_highlighting);
175        assert!(plugin.debugger.is_none());
176    }
177    #[test]
178    fn test_ide_capabilities_all_enabled() {
179        let caps = IDECapabilities {
180            syntax_highlighting: true,
181            code_completion: true,
182            inline_debugging: true,
183            tensor_visualization: true,
184            real_time_metrics: true,
185            breakpoint_management: true,
186            call_stack_navigation: true,
187            variable_inspection: true,
188            performance_profiling: true,
189            error_annotations: true,
190            jupyter_widgets: true,
191            interactive_plots: true,
192            notebook_integration: true,
193            kernel_communication: true,
194        };
195        assert!(caps.jupyter_widgets);
196        assert!(caps.kernel_communication);
197    }
198    #[test]
199    fn test_ide_message_toggle_breakpoint() {
200        let msg = IDEMessage::ToggleBreakpoint {
201            file: PathBuf::from("/test.rs"),
202            line: 5,
203        };
204        match msg {
205            IDEMessage::ToggleBreakpoint { file, line } => {
206                assert_eq!(line, 5);
207                assert_eq!(file.to_str().expect("path should be valid"), "/test.rs");
208            },
209            _ => panic!("Expected ToggleBreakpoint"),
210        }
211    }
212    #[test]
213    fn test_ide_message_show_tensor_visualization() {
214        let msg = IDEMessage::ShowTensorVisualization {
215            tensor_name: "attention_weights".to_string(),
216        };
217        match msg {
218            IDEMessage::ShowTensorVisualization { tensor_name } => {
219                assert_eq!(tensor_name, "attention_weights");
220            },
221            _ => panic!("Expected ShowTensorVisualization"),
222        }
223    }
224    #[test]
225    fn test_custom_ide_variant() {
226        let ide = SupportedIDE::Custom("neovim".to_string());
227        match ide {
228            SupportedIDE::Custom(name) => assert_eq!(name, "neovim"),
229            _ => panic!("Expected Custom variant"),
230        }
231    }
232    #[test]
233    fn test_ide_capabilities_partial() {
234        let caps = IDECapabilities {
235            syntax_highlighting: true,
236            code_completion: false,
237            inline_debugging: false,
238            tensor_visualization: false,
239            real_time_metrics: false,
240            breakpoint_management: false,
241            call_stack_navigation: false,
242            variable_inspection: false,
243            performance_profiling: false,
244            error_annotations: false,
245            jupyter_widgets: false,
246            interactive_plots: false,
247            notebook_integration: false,
248            kernel_communication: false,
249        };
250        assert!(caps.syntax_highlighting);
251        assert!(!caps.code_completion);
252    }
253    #[test]
254    fn test_ide_message_show_gradient_flow() {
255        let msg = IDEMessage::ShowGradientFlow {
256            layer_name: "encoder.layer.0".to_string(),
257        };
258        match msg {
259            IDEMessage::ShowGradientFlow { layer_name } => {
260                assert_eq!(layer_name, "encoder.layer.0");
261            },
262            _ => panic!("Expected ShowGradientFlow"),
263        }
264    }
265    #[test]
266    fn test_jupyter_widget_manager_kernel_not_connected() {
267        let manager = JupyterWidgetManager::new();
268        assert!(!manager.is_kernel_connected());
269        assert!(manager.get_active_widgets().is_empty());
270    }
271    #[test]
272    fn test_ide_plugin_no_debugger() {
273        let plugin = IDEPlugin {
274            plugin_id: Uuid::new_v4(),
275            name: "test".to_string(),
276            version: "0.1.0".to_string(),
277            supported_ides: vec![SupportedIDE::VSCode],
278            capabilities: IDECapabilities {
279                syntax_highlighting: false,
280                code_completion: false,
281                inline_debugging: false,
282                tensor_visualization: false,
283                real_time_metrics: false,
284                breakpoint_management: false,
285                call_stack_navigation: false,
286                variable_inspection: false,
287                performance_profiling: false,
288                error_annotations: false,
289                jupyter_widgets: false,
290                interactive_plots: false,
291                notebook_integration: false,
292                kernel_communication: false,
293            },
294            debugger: None,
295            config: DebugConfig::default(),
296        };
297        assert!(plugin.debugger.is_none());
298        assert_eq!(plugin.version, "0.1.0");
299    }
300    #[test]
301    fn test_supported_ide_clone() {
302        let ide = SupportedIDE::VSCode;
303        let cloned = ide.clone();
304        assert!(matches!(cloned, SupportedIDE::VSCode));
305    }
306    #[test]
307    fn test_ide_capabilities_clone() {
308        let caps = IDECapabilities {
309            syntax_highlighting: true,
310            code_completion: true,
311            inline_debugging: false,
312            tensor_visualization: false,
313            real_time_metrics: false,
314            breakpoint_management: false,
315            call_stack_navigation: false,
316            variable_inspection: false,
317            performance_profiling: false,
318            error_annotations: false,
319            jupyter_widgets: false,
320            interactive_plots: false,
321            notebook_integration: false,
322            kernel_communication: false,
323        };
324        let cloned = caps.clone();
325        assert!(cloned.syntax_highlighting);
326        assert!(cloned.code_completion);
327    }
328    #[test]
329    fn test_ide_message_set_breakpoint_no_condition() {
330        let msg = IDEMessage::SetBreakpoint {
331            file: PathBuf::from("/test.rs"),
332            line: 1,
333            condition: None,
334        };
335        match msg {
336            IDEMessage::SetBreakpoint { condition, .. } => {
337                assert!(condition.is_none());
338            },
339            _ => panic!("Expected SetBreakpoint"),
340        }
341    }
342    #[test]
343    fn test_multiple_supported_ides() {
344        let ides = [
345            SupportedIDE::VSCode,
346            SupportedIDE::IntelliJ,
347            SupportedIDE::Jupyter,
348            SupportedIDE::JupyterLab,
349        ];
350        assert_eq!(ides.len(), 4);
351        assert!(matches!(ides[0], SupportedIDE::VSCode));
352        assert!(matches!(ides[2], SupportedIDE::Jupyter));
353    }
354    #[test]
355    fn test_ide_plugin_multiple_ides() {
356        let plugin = IDEPlugin {
357            plugin_id: Uuid::new_v4(),
358            name: "multi".to_string(),
359            version: "2.0.0".to_string(),
360            supported_ides: vec![
361                SupportedIDE::VSCode,
362                SupportedIDE::IntelliJ,
363                SupportedIDE::Vim,
364                SupportedIDE::Emacs,
365            ],
366            capabilities: IDECapabilities {
367                syntax_highlighting: true,
368                code_completion: true,
369                inline_debugging: true,
370                tensor_visualization: true,
371                real_time_metrics: true,
372                breakpoint_management: true,
373                call_stack_navigation: true,
374                variable_inspection: true,
375                performance_profiling: true,
376                error_annotations: true,
377                jupyter_widgets: false,
378                interactive_plots: false,
379                notebook_integration: false,
380                kernel_communication: false,
381            },
382            debugger: None,
383            config: DebugConfig::default(),
384        };
385        assert_eq!(plugin.supported_ides.len(), 4);
386    }
387}