#![cfg(any(
not(any(
feature = "parser_tests",
feature = "analyzer_tests",
feature = "codegen_tests",
feature = "interpreter_tests",
feature = "conformance_tests",
feature = "integration_tests",
)),
feature = "analyzer_tests",
))]
use tempfile::TempDir;
use windjammer::{build_project_ext, CompilationTarget};
#[test]
fn test_external_crate_import_in_submodule() {
let temp = TempDir::new().unwrap();
let src = temp.path().join("src");
let build = temp.path().join("build");
std::fs::create_dir_all(src.join("test")).unwrap();
std::fs::write(
src.join("test/mod.wj"),
r#"
use windjammer_game_core::math::vec3::Vec3
pub fn test_create_vector() {
let v = Vec3::new(1.0, 2.0, 3.0)
assert_eq(v.x, 1.0)
}
"#,
)
.unwrap();
std::fs::write(
src.join("mod.wj"),
r#"
pub mod test
"#,
)
.unwrap();
build_project_ext(
&src.join("mod.wj"),
&build,
CompilationTarget::Rust,
false,
true, &[],
)
.expect("Build should succeed");
let rust_code = std::fs::read_to_string(build.join("test/_mod_items.rs"))
.expect("Failed to read generated test/_mod_items.rs");
assert!(
!rust_code.contains("use self::windjammer_game_core"),
"Should not use 'use self::windjammer_game_core' (windjammer_game_core is crate-level). Found in:\n{}",
rust_code.lines().take(20).collect::<Vec<_>>().join("\n")
);
assert!(
rust_code.contains("use crate::windjammer_game_core")
|| rust_code.contains("use windjammer_game_core")
|| rust_code.contains("use super::windjammer_game_core"),
"Should use 'use crate::windjammer_game_core' or direct path. Found:\n{}",
rust_code.lines().take(20).collect::<Vec<_>>().join("\n")
);
}