use super::assertions::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(),
)
}
#[allow(clippy::too_many_arguments)]
fn render(assertion: &Assertion) -> String {
let resolver = empty_resolver();
let mut out = String::new();
render_assertion(
&mut out,
assertion,
"result",
"Result",
&resolver,
false,
false,
false,
false,
None,
&std::collections::HashSet::new(),
&std::collections::HashMap::new(),
false,
&std::collections::HashSet::new(),
true,
);
out
}
#[test]
fn an_equals_assertion_keeps_its_statement_indentation() {
let assertion = Assertion {
assertion_type: "equals".to_string(),
field: Some("content".to_string()),
value: Some(serde_json::Value::String("hello".to_string())),
..Assertion::default()
};
assert_eq!(
render(&assertion),
" assertEquals(\"hello\", result.content());\n"
);
}
#[test]
fn a_contains_all_assertion_keeps_one_statement_per_line() {
let assertion = Assertion {
assertion_type: "contains_all".to_string(),
field: Some("content".to_string()),
values: Some(vec![
serde_json::Value::String("alef".to_string()),
serde_json::Value::String("binding".to_string()),
]),
..Assertion::default()
};
assert_eq!(
render(&assertion),
" assertTrue(result.content().contains(\"alef\"), \"expected to contain: \" + \"alef\");\n assertTrue(result.content().contains(\"binding\"), \"expected to contain: \" + \"binding\");\n"
);
}