use super::*;
use crate::autocomplete::jq_functions::JQ_FUNCTION_METADATA;
use crate::tooltip::operator_content::OPERATOR_CONTENT;
use proptest::prelude::*;
#[test]
fn test_format_tooltip_title_function() {
assert_eq!(format_tooltip_title(true, "select"), "fn: select");
assert_eq!(format_tooltip_title(true, "map"), "fn: map");
assert_eq!(format_tooltip_title(true, "sort_by"), "fn: sort_by");
}
#[test]
fn test_format_tooltip_title_operator() {
assert_eq!(format_tooltip_title(false, "//"), "operator: //");
assert_eq!(format_tooltip_title(false, "|="), "operator: |=");
assert_eq!(format_tooltip_title(false, "//="), "operator: //=");
assert_eq!(format_tooltip_title(false, ".."), "operator: ..");
}
proptest! {
#![proptest_config(ProptestConfig::with_cases(100))]
#[test]
fn prop_function_title_format(func_index in 0usize..JQ_FUNCTION_METADATA.len()) {
let func = &JQ_FUNCTION_METADATA[func_index];
let func_name = func.name;
let title = format_tooltip_title(true, func_name);
prop_assert!(
title.starts_with("fn: "),
"Function title '{}' should start with 'fn: '",
title
);
prop_assert!(
title.ends_with(func_name),
"Function title '{}' should end with function name '{}'",
title,
func_name
);
let expected = format!("fn: {}", func_name);
prop_assert_eq!(
title,
expected,
"Function title should be exactly 'fn: {}'",
func_name
);
}
#[test]
fn prop_operator_title_format(op_index in 0usize..OPERATOR_CONTENT.len()) {
let op = &OPERATOR_CONTENT[op_index];
let op_name = op.function;
let title = format_tooltip_title(false, op_name);
prop_assert!(
title.starts_with("operator: "),
"Operator title '{}' should start with 'operator: '",
title
);
prop_assert!(
title.ends_with(op_name),
"Operator title '{}' should end with operator '{}'",
title,
op_name
);
let expected = format!("operator: {}", op_name);
prop_assert_eq!(
title,
expected,
"Operator title should be exactly 'operator: {}'",
op_name
);
}
}
#[test]
fn test_wrap_text_truncates_to_two_lines() {
let long_text = "This is a very long text that will definitely wrap into more than two lines when we have a small max width like twenty characters total width";
let result = wrap_text(long_text, 20);
assert!(result.len() <= 2, "Should truncate to max 2 lines");
}
#[test]
fn test_wrap_text_short_text() {
let short_text = "Hello";
let result = wrap_text(short_text, 50);
assert_eq!(result.len(), 1);
assert_eq!(result[0], "Hello");
}
#[test]
fn test_wrap_text_exactly_two_lines() {
let text = "First line text here and second line";
let result = wrap_text(text, 20);
assert!(!result.is_empty());
}