use super::*;
#[test]
fn comparison_equal() {
assert_eq!(
render_template("#{==:alpha,alpha}", &StaticWindowValues),
"1"
);
assert_eq!(
render_template("#{==:alpha,beta}", &StaticWindowValues),
"0"
);
}
#[test]
fn comparison_not_equal() {
assert_eq!(
render_template("#{!=:alpha,beta}", &StaticWindowValues),
"1"
);
assert_eq!(
render_template("#{!=:alpha,alpha}", &StaticWindowValues),
"0"
);
}
#[test]
fn comparison_less_than() {
assert_eq!(render_template("#{<:abc,def}", &StaticWindowValues), "1");
assert_eq!(render_template("#{<:def,abc}", &StaticWindowValues), "0");
}
#[test]
fn comparison_greater_than() {
assert_eq!(render_template("#{>:def,abc}", &StaticWindowValues), "1");
assert_eq!(render_template("#{>:abc,def}", &StaticWindowValues), "0");
}
#[test]
fn comparison_less_equal() {
assert_eq!(render_template("#{<=:abc,abc}", &StaticWindowValues), "1");
assert_eq!(render_template("#{<=:abc,def}", &StaticWindowValues), "1");
assert_eq!(render_template("#{<=:def,abc}", &StaticWindowValues), "0");
}
#[test]
fn comparison_greater_equal() {
assert_eq!(render_template("#{>=:def,def}", &StaticWindowValues), "1");
assert_eq!(render_template("#{>=:def,abc}", &StaticWindowValues), "1");
assert_eq!(render_template("#{>=:abc,def}", &StaticWindowValues), "0");
}
#[test]
fn comparison_with_variable_expansion() {
assert_eq!(
render_template("#{==:#{session_name},alpha}", &StaticWindowValues),
"1"
);
assert_eq!(
render_template("#{!=:#{session_name},beta}", &StaticWindowValues),
"1"
);
}
#[test]
fn fnmatch_basic() {
assert_eq!(render_template("#{m:al*,alpha}", &StaticWindowValues), "1");
assert_eq!(render_template("#{m:be*,alpha}", &StaticWindowValues), "0");
}
#[test]
fn fnmatch_question_mark() {
assert_eq!(
render_template("#{m:alph?,alpha}", &StaticWindowValues),
"1"
);
assert_eq!(render_template("#{m:alp?,alpha}", &StaticWindowValues), "0");
}
#[test]
fn boolean_and() {
assert_eq!(
render_template(
"#{&&:#{window_active},#{session_name}}",
&StaticWindowValues
),
"1"
);
assert_eq!(
render_template(
"#{&&:#{window_last_flag},#{window_active}}",
&StaticWindowValues
),
"0"
);
}
#[test]
fn boolean_or() {
assert_eq!(
render_template(
"#{||:#{window_last_flag},#{window_active}}",
&StaticWindowValues
),
"1"
);
assert_eq!(
render_template("#{||:#{window_last_flag},#{missing}}", &StaticWindowValues),
"0"
);
}
#[test]
fn boolean_not() {
assert_eq!(
render_template("#{!:#{window_active}}", &StaticWindowValues),
"0"
);
assert_eq!(
render_template("#{!:#{window_last_flag}}", &StaticWindowValues),
"1"
);
}
#[test]
fn boolean_not_not() {
assert_eq!(
render_template("#{!!:#{window_active}}", &StaticWindowValues),
"1"
);
assert_eq!(
render_template("#{!!:#{window_last_flag}}", &StaticWindowValues),
"0"
);
}
#[test]
fn boolean_and_nary() {
assert_eq!(
render_template(
"#{&&:#{window_active},#{session_name},#{window_panes}}",
&StaticWindowValues
),
"1"
);
assert_eq!(
render_template(
"#{&&:#{window_active},#{window_last_flag},#{session_name}}",
&StaticWindowValues
),
"0"
);
}
#[test]
fn boolean_or_nary() {
assert_eq!(
render_template(
"#{||:#{window_last_flag},#{missing},#{missing2}}",
&StaticWindowValues
),
"0"
);
assert_eq!(
render_template(
"#{||:#{window_last_flag},#{window_active},#{missing}}",
&StaticWindowValues
),
"1"
);
}
#[test]
fn conditional_multi_pair() {
assert_eq!(
render_template(
"#{?window_last_flag,first,window_active,second,default}",
&StaticWindowValues
),
"second"
);
}
#[test]
fn conditional_multi_pair_default() {
assert_eq!(
render_template(
"#{?window_last_flag,first,missing,second,default}",
&StaticWindowValues
),
"default"
);
}
#[test]
fn conditional_multi_pair_no_default() {
assert_eq!(
render_template(
"#{?window_last_flag,first,missing,second}",
&StaticWindowValues
),
""
);
}
#[test]
fn escape_comma() {
assert_eq!(render_template("a#,b", &StaticWindowValues), "a,b");
}
#[test]
fn escape_closing_brace() {
assert_eq!(render_template("a#}b", &StaticWindowValues), "a}b");
}
#[test]
fn recursion_limit_produces_empty() {
struct RecurseVars;
impl FormatVariables for RecurseVars {
fn format_value(&self, variable: FormatVariable) -> Option<String> {
match variable {
FormatVariable::SessionName => Some("#{E:session_name}".to_owned()),
_ => None,
}
}
}
let result = render_template("#{E:session_name}", &RecurseVars);
assert!(result.len() < 1000, "recursion should be bounded");
}