use crate::tui::render::utils::{apply_rtl, apply_rtl_lines, is_arabic_char, is_rtl_char};
use ratatui::style::{Modifier, Style};
use ratatui::text::{Line, Span};
#[test]
fn latin_only_text_is_untouched() {
assert_eq!(apply_rtl("hello world, cargo build --release"), None);
}
#[test]
fn hebrew_pure_run_is_reordered_not_shaped() {
let input = "שלום";
let expected: String = input.chars().rev().collect();
assert_eq!(apply_rtl(input), Some(expected));
}
#[test]
fn arabic_is_shaped_then_reordered() {
let input = "ادخل";
let shaped = arabic_reshaper::arabic_reshape(input);
let expected: String = shaped.chars().rev().collect();
let out = apply_rtl(input).expect("Arabic input must produce visual order");
assert_eq!(out, expected);
assert_ne!(out, input);
}
#[test]
fn mixed_latin_line_keeps_latin_words_intact() {
let input = "run cargo build في الطريق";
let out = apply_rtl(input).expect("line contains RTL");
assert!(out.contains("cargo build"));
assert_ne!(out, input);
}
#[test]
fn span_pass_reorders_text_and_preserves_styles() {
let line = Line::from(vec![
Span::styled("שלום", Style::default().bold()),
Span::raw("!!"),
]);
let out = apply_rtl_lines(vec![line]);
assert_eq!(out[0].spans.len(), 2);
assert_eq!(out[0].spans[0].content.as_ref(), "םולש");
assert!(out[0].spans[0].style.add_modifier.contains(Modifier::BOLD));
assert_eq!(out[0].spans[1].content.as_ref(), "!!");
}
#[test]
fn rtl_and_arabic_detection() {
assert!(is_rtl_char('ش')); assert!(is_rtl_char('ש')); assert!(!is_rtl_char('a'));
assert!(!is_rtl_char('5'));
assert!(is_arabic_char('ش'));
assert!(!is_arabic_char('ש'));
}