use super::test_case::{DartTestCaseContext, render_test_case};
use crate::core::config::ResolvedCrateConfig;
use crate::e2e::config::E2eConfig;
use crate::e2e::fixture::{Assertion, Fixture};
fn render_void_call(assertions: Vec<Assertion>) -> String {
let fixture = Fixture {
id: "prefetch_languages".to_string(),
description: "Prefetch languages".to_string(),
assertions,
..Fixture::default()
};
let mut e2e_config = E2eConfig::default();
e2e_config.call.function = "prefetch_languages".to_string();
e2e_config.call.returns_void = true;
let config = ResolvedCrateConfig::default();
let type_defs: Vec<crate::core::ir::TypeDef> = Vec::new();
let enums: Vec<crate::core::ir::EnumDef> = Vec::new();
let functions: Vec<crate::core::ir::FunctionDef> = Vec::new();
let first_class_map = super::values::build_dart_first_class_map(&type_defs, &enums, &e2e_config);
let mut out = String::new();
render_test_case(
&mut out,
&fixture,
DartTestCaseContext {
e2e_config: &e2e_config,
lang: "dart",
bridge_class: &config.dart_bridge_class_name(),
dart_first_class_map: &first_class_map,
adapters: &config.adapters,
config: &config,
type_defs: &type_defs,
enums: &enums,
functions: &functions,
errors: &[],
native_typed_dtos: true,
is_snippet: false,
},
);
out
}
fn not_error_assertion() -> Assertion {
Assertion {
assertion_type: "not_error".to_string(),
..Assertion::default()
}
}
#[test]
fn void_not_error_wraps_the_call_in_expect_later_completes() {
let out = render_void_call(vec![not_error_assertion()]);
assert!(
out.contains("await expectLater(") && out.contains("prefetchLanguages"),
"expected the void call wrapped in expectLater(..., completes), got:\n{out}"
);
assert!(
out.contains("completes"),
"expected the `completes` matcher, got:\n{out}"
);
assert!(
!out.contains("await bridge.prefetchLanguages();\n") && !out.contains("await PrefetchLanguages();\n"),
"the call must not also appear as a bare, unasserted statement, got:\n{out}"
);
}
#[test]
fn void_call_without_not_error_stays_a_bare_await_statement() {
let out = render_void_call(vec![]);
assert!(
out.contains("prefetchLanguages"),
"expected the call to still be emitted, got:\n{out}"
);
assert!(
!out.contains("expectLater"),
"must not wrap the call when no not_error assertion is present, got:\n{out}"
);
}