use super::*;
#[test]
fn truncation_left() {
assert_eq!(
render_template("#{=3:session_name}", &StaticWindowValues),
"alp"
);
}
#[test]
fn truncation_with_marker() {
assert_eq!(
render_template("#{=/3/...:session_name}", &StaticWindowValues),
"alp..."
);
}
#[test]
fn substitution_basic() {
assert_eq!(
render_template("#{s/alpha/beta/:session_name}", &StaticWindowValues),
"beta"
);
}
#[test]
fn substitution_uses_regex_and_case_insensitive_flag() {
assert_eq!(
render_template("#{s/AL.HA/beta/i:session_name}", &StaticWindowValues),
"beta"
);
}
#[test]
fn modifier_basename() {
struct PathVars;
impl FormatVariables for PathVars {
fn format_value(&self, variable: FormatVariable) -> Option<String> {
match variable {
FormatVariable::SessionName => Some("/home/user/test".to_owned()),
_ => None,
}
}
}
assert_eq!(render_template("#{b:session_name}", &PathVars), "test");
}
#[test]
fn modifier_dirname() {
struct PathVars;
impl FormatVariables for PathVars {
fn format_value(&self, variable: FormatVariable) -> Option<String> {
match variable {
FormatVariable::SessionName => Some("/home/user/test".to_owned()),
_ => None,
}
}
}
assert_eq!(
render_template("#{d:session_name}", &PathVars),
"/home/user"
);
}
#[test]
fn modifier_length() {
assert_eq!(
render_template("#{n:session_name}", &StaticWindowValues),
"5" );
}
#[test]
fn style_passthrough() {
assert_eq!(
render_template("#[fg=red]hello#[default]", &StaticWindowValues),
"#[fg=red]hello#[default]"
);
}
#[test]
fn conditional_inside_comparison() {
assert_eq!(
render_template(
"#{?#{==:#{session_name},alpha},match,no-match}",
&StaticWindowValues
),
"match"
);
}
#[test]
fn escaped_comma_inside_conditional_value() {
assert_eq!(
render_template("#{?window_active,a#,b,fallback}", &StaticWindowValues),
"a,b"
);
}
#[test]
fn escaped_comma_in_boolean_operand() {
assert_eq!(
render_template("#{||:hello#,world}", &StaticWindowValues),
"1" );
}
#[test]
fn escaped_brace_in_literal() {
assert_eq!(render_template("#{l:a#}b}", &StaticWindowValues), "a}b");
}
#[test]
fn literal_unescape_respects_nested_format_depth() {
assert_eq!(
render_template("#{l:outer #{inner#,value} end}", &StaticWindowValues),
"outer #{inner#,value} end"
);
}
#[test]
fn job_expansion_returns_empty() {
assert_eq!(
render_template("before#(echo hello)after", &StaticWindowValues),
"beforeafter"
);
}
#[test]
fn job_expansion_unclosed_breaks_out() {
assert_eq!(
render_template("before#(no close", &StaticWindowValues),
"before"
);
}
#[test]
fn comparison_both_sides_expanded() {
assert_eq!(
render_template("#{==:#{window_index},#{window_index}}", &StaticWindowValues),
"1"
);
assert_eq!(
render_template(
"#{!=:#{window_index},#{session_windows}}",
&StaticWindowValues
),
"1"
);
}
#[test]
fn comparison_no_comma_returns_empty() {
assert_eq!(
render_template("#{==:no-comma-here}", &StaticWindowValues),
""
);
}
#[test]
fn fnmatch_character_class() {
assert_eq!(
render_template("#{m:[a-z]*,alpha}", &StaticWindowValues),
"1"
);
assert_eq!(
render_template("#{m:[0-9]*,alpha}", &StaticWindowValues),
"0"
);
}
#[test]
fn multi_pair_conditional_with_nested_expansion() {
assert_eq!(
render_template(
"#{?#{window_last_flag},first,#{window_active},#{window_name},default}",
&StaticWindowValues
),
"logs"
);
}
#[test]
fn modifier_chain_basename_and_length() {
struct PathVars;
impl FormatVariables for PathVars {
fn format_value(&self, variable: FormatVariable) -> Option<String> {
match variable {
FormatVariable::SessionName => Some("/home/user/test".to_owned()),
_ => None,
}
}
}
assert_eq!(
render_template("#{b;n:session_name}", &PathVars),
"4" );
}
#[test]
fn modifier_dirname_no_slash() {
assert_eq!(
render_template("#{d:session_name}", &StaticWindowValues),
"." );
}
#[test]
fn trailing_hash_in_various_positions() {
assert_eq!(render_template("abc#", &StaticWindowValues), "abc");
assert_eq!(
render_template("#{session_name}#", &StaticWindowValues),
"alpha"
);
assert_eq!(render_template("#####", &StaticWindowValues), "##");
}
#[test]
fn format_skip_colon_escape() {
assert_eq!(format_skip(b"a#:b:c", b":"), Some(4));
}
#[test]
fn style_with_nested_expression() {
assert_eq!(
render_template("before#[fg=red]middle#[default]after", &StaticWindowValues),
"before#[fg=red]middle#[default]after"
);
}
#[test]
fn double_hash_before_style_passthrough() {
assert_eq!(
render_template("##[fg=red]text", &StaticWindowValues),
"##[fg=red]text"
);
}