#![cfg(any(
not(any(
feature = "parser_tests",
feature = "analyzer_tests",
feature = "codegen_tests",
feature = "interpreter_tests",
feature = "conformance_tests",
feature = "integration_tests",
)),
feature = "integration_tests",
))]
use std::path::PathBuf;
#[test]
#[cfg_attr(tarpaulin, ignore)]
fn test_static_method_inference() {
let out_tmp = tempfile::tempdir().expect("tempdir");
let wj_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests")
.join("static_method_inference_test.wj");
windjammer::build_project(
&wj_path,
out_tmp.path(),
windjammer::CompilationTarget::Rust,
false,
)
.expect("Failed to run windjammer compiler");
let generated_code =
std::fs::read_to_string(out_tmp.path().join("static_method_inference_test.rs"))
.or_else(|_| {
std::fs::read_to_string(
out_tmp
.path()
.join("wj")
.join("windjammer")
.join("tests")
.join("static_method_inference_test.rs"),
)
})
.expect("Failed to read generated code (tried both possible paths)");
assert!(
generated_code.contains("pub fn new(x: f32, y: f32) -> Point"),
"new() should not have &self parameter"
);
assert!(
generated_code.contains("pub fn from_coords(x: f32, y: f32) -> Point"),
"from_coords() should not have &self parameter"
);
assert!(
generated_code.contains("pub fn zero() -> Point"),
"zero() should not have &self parameter"
);
assert!(
generated_code.contains("pub fn distance(&self, other: Point) -> f32"),
"distance() should have &self parameter"
);
assert!(
generated_code.contains("pub fn new(width: i32, height: i32) -> Grid"),
"Grid::new() should not have &self parameter (this is the bug!)"
);
}