use super::render_assertion;
use crate::e2e::field_access::FieldResolver;
use crate::e2e::fixture::Assertion;
fn empty_resolver() -> FieldResolver {
FieldResolver::new(
&std::collections::HashMap::new(),
&std::collections::HashSet::new(),
&std::collections::HashSet::new(),
&std::collections::HashSet::new(),
&std::collections::HashSet::new(),
)
}
#[test]
fn an_equals_assertion_keeps_its_statement_indentation() {
let resolver = empty_resolver();
let assertion = Assertion {
assertion_type: "equals".to_string(),
field: Some("content".to_string()),
value: Some(serde_json::Value::String("hello".to_string())),
..Assertion::default()
};
let mut out = String::new();
render_assertion(
&mut out,
&assertion,
"result",
"SampleClass",
"SampleException",
&resolver,
false,
false,
false,
false,
&std::collections::HashSet::new(),
&std::collections::HashMap::new(),
);
assert_eq!(out, " Assert.Equal(\"hello\", result.Content);\n");
}
#[test]
fn a_multiline_not_empty_switch_assertion_keeps_its_opening_line_indentation() {
let resolver = empty_resolver();
let assertion = Assertion {
assertion_type: "not_empty".to_string(),
field: Some("content".to_string()),
..Assertion::default()
};
let mut out = String::new();
render_assertion(
&mut out,
&assertion,
"result",
"SampleClass",
"SampleException",
&resolver,
false,
false,
false,
false,
&std::collections::HashSet::new(),
&std::collections::HashMap::new(),
);
assert_eq!(
out,
" Assert.True(((object?)result.Content) switch\n {\n null => false,\n string text => text.Length > 0,\n System.Collections.ICollection items => items.Count > 0,\n _ => true,\n }, \"expected non-empty value\");\n"
);
}