use crate::e2e::field_access::FieldResolver;
use crate::e2e::fixture::Assertion;
#[cfg(test)]
pub(super) struct RenderAssertionContext<'a> {
pub(super) result_var: &'a str,
pub(super) class_name: &'a str,
pub(super) field_resolver: &'a FieldResolver,
pub(super) result_is_simple: bool,
pub(super) result_is_option: bool,
pub(super) enum_fields: &'a std::collections::HashSet<String>,
pub(super) json_scalar_fields: &'a std::collections::HashSet<String>,
pub(super) fields_c_types: &'a std::collections::HashMap<String, String>,
pub(super) is_streaming: bool,
pub(super) kotlin_android_style: bool,
pub(super) not_error_may_assert_presence: bool,
}
#[cfg(test)]
pub(super) fn render_assertion(out: &mut String, assertion: &Assertion, context: RenderAssertionContext) {
let RenderAssertionContext {
result_var,
class_name,
field_resolver,
result_is_simple,
result_is_option,
enum_fields,
json_scalar_fields,
fields_c_types,
is_streaming,
kotlin_android_style,
not_error_may_assert_presence,
} = context;
render_assertion_with_streaming_context(
out,
assertion,
RenderAssertionStreamingContext {
result_var,
class_name,
field_resolver,
result_is_simple,
result_is_option,
enum_fields,
json_scalar_fields,
fields_c_types,
is_streaming,
streaming_item_type: None,
kotlin_android_style,
not_error_may_assert_presence,
},
);
}
pub(super) struct RenderAssertionStreamingContext<'a> {
pub(super) result_var: &'a str,
pub(super) class_name: &'a str,
pub(super) field_resolver: &'a FieldResolver,
pub(super) result_is_simple: bool,
pub(super) result_is_option: bool,
pub(super) enum_fields: &'a std::collections::HashSet<String>,
pub(super) json_scalar_fields: &'a std::collections::HashSet<String>,
pub(super) fields_c_types: &'a std::collections::HashMap<String, String>,
pub(super) is_streaming: bool,
pub(super) streaming_item_type: Option<&'a str>,
pub(super) kotlin_android_style: bool,
pub(super) not_error_may_assert_presence: bool,
}
pub(super) fn render_assertion_with_streaming_context(
out: &mut String,
assertion: &Assertion,
context: RenderAssertionStreamingContext,
) {
let RenderAssertionStreamingContext {
result_var,
class_name: _class_name,
field_resolver,
result_is_simple,
result_is_option,
enum_fields,
json_scalar_fields,
fields_c_types,
is_streaming,
streaming_item_type,
kotlin_android_style,
not_error_may_assert_presence,
} = context;
if super::assertion_mock_capture::try_render_mock_capture_assertion(out, assertion, kotlin_android_style) {
return;
}
if super::assertion_field_gates::try_render_field_shape_gates(
out,
assertion,
super::assertion_field_gates::FieldShapeGatesContext {
field_resolver,
result_var,
result_is_simple,
is_streaming,
streaming_item_type,
kotlin_android_style,
fields_c_types,
},
) {
return;
}
super::assertion_scalar_dispatch::render_scalar_pipeline(
out,
assertion,
super::assertion_scalar_dispatch::ScalarPipelineContext {
field_resolver,
result_var,
result_is_simple,
result_is_option,
enum_fields,
json_scalar_fields,
fields_c_types,
kotlin_android_style,
is_streaming,
not_error_may_assert_presence,
},
);
}
#[cfg(test)]
mod tests;