use super::test_method::render_test_method;
use crate::e2e::config::{CallConfig, E2eConfig};
use crate::e2e::fixture::{Assertion, Fixture};
fn void_fixture(id: &str, assertions: Vec<Assertion>) -> Fixture {
Fixture {
docs: None,
requirements: Vec::new(),
id: id.to_string(),
category: None,
description: "test".to_string(),
tags: vec![],
skip: None,
env: None,
setup: Vec::new(),
call: None,
input: serde_json::Value::Null,
mock_response: None,
source: String::new(),
http: None,
asyncapi: None,
websocket: None,
preserve_input_urls: false,
assertions,
visitor: None,
args: vec![],
assertion_recipes: vec![],
}
}
fn render_void_call(assertions: Vec<Assertion>) -> String {
let fixture = void_fixture("prefetch_languages", assertions);
let call = CallConfig {
function: "prefetchLanguages".to_string(),
module: "MyLib".to_string(),
result_var: "result".to_string(),
returns_void: true,
..Default::default()
};
let e2e_config = E2eConfig {
call,
..Default::default()
};
let config = crate::core::config::ResolvedCrateConfig::default();
let type_defs: Vec<crate::core::ir::TypeDef> = Vec::new();
let mut out = String::new();
render_test_method(
&mut out,
&fixture,
"SampleClass",
"",
"",
&[],
None,
false,
&e2e_config,
&std::collections::HashMap::new(),
false,
&[],
&config,
&type_defs,
&[],
&[],
&[],
);
out
}
#[test]
fn void_not_error_wraps_the_call_in_assert_does_not_throw() {
let out = render_void_call(vec![Assertion {
assertion_type: "not_error".to_string(),
..Default::default()
}]);
assert!(
out.contains("assertDoesNotThrow(() -> SampleClass.prefetchLanguages());"),
"expected the void call wrapped in assertDoesNotThrow, got:\n{out}"
);
assert!(
!out.contains(" SampleClass.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_statement() {
let out = render_void_call(vec![]);
assert!(
out.contains(" SampleClass.prefetchLanguages();\n"),
"expected a bare call statement, got:\n{out}"
);
assert!(
!out.contains("assertDoesNotThrow"),
"must not wrap the call when no not_error assertion is present, got:\n{out}"
);
}