#![cfg(feature = "dap")]
use pmat::services::dap::timeline_tui::VariableInspectorView;
#[test]
fn test_variable_inspector_creation() {
let inspector = VariableInspectorView::new();
assert_eq!(inspector.variable_count(), 0);
assert_eq!(inspector.scroll_offset(), 0);
}
#[test]
fn test_variable_inspector_with_variables() {
let variables = vec![
("x".to_string(), "42".to_string()),
("y".to_string(), "hello".to_string()),
("z".to_string(), "[1, 2, 3]".to_string()),
];
let inspector = VariableInspectorView::from_variables(variables);
assert_eq!(inspector.variable_count(), 3);
}
#[test]
fn test_set_scroll_offset() {
let mut inspector = VariableInspectorView::new();
inspector.add_variable("x".to_string(), "42".to_string());
inspector.add_variable("y".to_string(), "100".to_string());
inspector.set_scroll_offset(1);
assert_eq!(inspector.scroll_offset(), 1);
}
#[test]
fn test_scroll_offset_bounds() {
let mut inspector = VariableInspectorView::new();
inspector.add_variable("x".to_string(), "42".to_string());
inspector.set_scroll_offset(10);
assert_eq!(inspector.scroll_offset(), 0);
}
#[test]
fn test_scroll_down() {
let mut inspector = VariableInspectorView::from_variables(vec![
("a".to_string(), "1".to_string()),
("b".to_string(), "2".to_string()),
("c".to_string(), "3".to_string()),
]);
inspector.scroll_down();
assert_eq!(inspector.scroll_offset(), 1);
inspector.scroll_down();
assert_eq!(inspector.scroll_offset(), 2);
}
#[test]
fn test_scroll_up() {
let mut inspector = VariableInspectorView::from_variables(vec![
("a".to_string(), "1".to_string()),
("b".to_string(), "2".to_string()),
("c".to_string(), "3".to_string()),
]);
inspector.set_scroll_offset(2);
inspector.scroll_up();
assert_eq!(inspector.scroll_offset(), 1);
}
#[test]
fn test_scroll_up_at_top() {
let mut inspector =
VariableInspectorView::from_variables(vec![("a".to_string(), "1".to_string())]);
inspector.scroll_up();
assert_eq!(inspector.scroll_offset(), 0);
}
#[test]
fn test_scroll_down_at_bottom() {
let mut inspector = VariableInspectorView::from_variables(vec![
("a".to_string(), "1".to_string()),
("b".to_string(), "2".to_string()),
]);
inspector.set_scroll_offset(1);
inspector.scroll_down();
assert_eq!(inspector.scroll_offset(), 1);
}
#[test]
fn test_page_down() {
let mut inspector = VariableInspectorView::from_variables(vec![
("a".to_string(), "1".to_string()),
("b".to_string(), "2".to_string()),
("c".to_string(), "3".to_string()),
("d".to_string(), "4".to_string()),
("e".to_string(), "5".to_string()),
]);
inspector.set_viewport_height(2);
inspector.page_down();
assert_eq!(inspector.scroll_offset(), 2);
}
#[test]
fn test_page_up() {
let mut inspector = VariableInspectorView::from_variables(vec![
("a".to_string(), "1".to_string()),
("b".to_string(), "2".to_string()),
("c".to_string(), "3".to_string()),
("d".to_string(), "4".to_string()),
]);
inspector.set_viewport_height(2);
inspector.set_scroll_offset(3);
inspector.page_up();
assert_eq!(inspector.scroll_offset(), 1);
}
#[test]
fn test_viewport_height() {
let mut inspector = VariableInspectorView::new();
inspector.set_viewport_height(10);
assert_eq!(inspector.viewport_height(), 10);
}
#[test]
fn test_visible_range() {
let mut inspector = VariableInspectorView::from_variables(vec![
("a".to_string(), "1".to_string()),
("b".to_string(), "2".to_string()),
("c".to_string(), "3".to_string()),
("d".to_string(), "4".to_string()),
("e".to_string(), "5".to_string()),
]);
inspector.set_viewport_height(3);
inspector.set_scroll_offset(1);
let range = inspector.visible_range();
assert_eq!(range, (1, 4)); }
#[test]
fn test_get_variable_at_index() {
let inspector = VariableInspectorView::from_variables(vec![
("x".to_string(), "42".to_string()),
("y".to_string(), "100".to_string()),
]);
let var = inspector.get_variable(1);
assert_eq!(var, Some((&"y".to_string(), &"100".to_string())));
}
#[test]
fn test_get_variable_out_of_bounds() {
let inspector =
VariableInspectorView::from_variables(vec![("x".to_string(), "42".to_string())]);
let var = inspector.get_variable(10);
assert_eq!(var, None);
}
#[test]
fn test_format_variable_line() {
let inspector =
VariableInspectorView::from_variables(vec![("counter".to_string(), "42".to_string())]);
let line = inspector.format_line(0);
assert_eq!(line, Some("counter: 42".to_string()));
}
#[test]
fn test_format_visible_lines() {
let mut inspector = VariableInspectorView::from_variables(vec![
("a".to_string(), "1".to_string()),
("b".to_string(), "2".to_string()),
("c".to_string(), "3".to_string()),
]);
inspector.set_viewport_height(2);
inspector.set_scroll_offset(1);
let lines = inspector.visible_lines();
assert_eq!(lines, vec!["b: 2", "c: 3"]);
}
#[test]
fn test_empty_inspector_scroll() {
let mut inspector = VariableInspectorView::new();
inspector.scroll_down();
inspector.scroll_up();
assert_eq!(inspector.scroll_offset(), 0);
}