#![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::fs;
use tempfile::TempDir;
#[test]
fn test_library_deps_are_added_from_wj_toml() {
let temp_dir = TempDir::new().unwrap();
let project_root = temp_dir.path();
let wj_toml = r#"
[package]
name = "test-editor"
version = "0.1.0"
[dependencies]
windjammer-runtime = { path = "../../../windjammer/crates/windjammer-runtime" }
windjammer-ui = { path = "../../windjammer-ui", features = ["desktop"] }
egui = "0.29"
eframe = "0.29"
egui_dock = "0.14"
serde = { version = "1.0", features = ["derive"] }
[lib]
path = "src/mod.wj"
"#;
fs::write(project_root.join("wj.toml"), wj_toml).unwrap();
let src = project_root.join("src");
fs::create_dir_all(&src).unwrap();
fs::write(src.join("mod.wj"), "// Test module\npub fn test() {}").unwrap();
let lib_output = project_root.join("lib");
fs::create_dir_all(&lib_output).unwrap();
let initial_cargo_toml = r#"[package]
name = "windjammer-app"
version = "0.1.0"
edition = "2021"
[dependencies]
windjammer-runtime = { path = "/some/path", version = "*" }
[lib]
name = "windjammer_app"
path = "lib.rs"
[workspace]
"#;
fs::write(lib_output.join("Cargo.toml"), initial_cargo_toml).unwrap();
let wj_toml_content = fs::read_to_string(project_root.join("wj.toml")).unwrap();
let config: toml::Value = toml::from_str(&wj_toml_content).unwrap();
let cargo_toml_path = lib_output.join("Cargo.toml");
let mut cargo_toml = fs::read_to_string(&cargo_toml_path).unwrap();
if let Some(deps) = config.get("dependencies").and_then(|d| d.as_table()) {
let mut deps_section = String::new();
for (dep_name, dep_value) in deps {
if dep_name == "windjammer-runtime" {
continue;
}
if let Some(dep_table) = dep_value.as_table() {
deps_section.push_str(&format!("{} = {{ ", dep_name));
for (key, value) in dep_table {
if key == "path" {
if let Some(path_str) = value.as_str() {
deps_section.push_str(&format!("path = \"{}\", ", path_str));
}
} else if key == "features" {
if let Some(features_array) = value.as_array() {
deps_section.push_str("features = [");
for (i, feature) in features_array.iter().enumerate() {
if i > 0 {
deps_section.push_str(", ");
}
if let Some(f) = feature.as_str() {
deps_section.push_str(&format!("\"{}\"", f));
}
}
deps_section.push_str("], ");
}
} else if key == "version" {
if let Some(version_str) = value.as_str() {
deps_section.push_str(&format!("version = \"{}\", ", version_str));
}
}
}
if deps_section.ends_with(", ") {
deps_section.truncate(deps_section.len() - 2);
}
deps_section.push_str(" }\n");
} else if let Some(version_str) = dep_value.as_str() {
deps_section.push_str(&format!("{} = \"{}\"\n", dep_name, version_str));
}
}
if !deps_section.is_empty() {
if let Some(lib_pos) = cargo_toml.find("[lib]") {
cargo_toml.insert_str(lib_pos, &deps_section);
}
}
}
assert!(
cargo_toml.contains("egui = "),
"egui dependency should be added"
);
assert!(
cargo_toml.contains("eframe = "),
"eframe dependency should be added"
);
assert!(
cargo_toml.contains("egui_dock = "),
"egui_dock dependency should be added"
);
assert!(
cargo_toml.contains("serde = "),
"serde dependency should be added"
);
assert!(
cargo_toml.contains("windjammer-ui = "),
"windjammer-ui dependency should be added"
);
assert!(
cargo_toml.contains("features = [\"desktop\"]"),
"windjammer-ui features should be preserved"
);
assert!(
cargo_toml.contains("features = [\"derive\"]"),
"serde features should be preserved"
);
}
#[test]
fn test_library_deps_dont_duplicate() {
let temp_dir = TempDir::new().unwrap();
let project_root = temp_dir.path();
let wj_toml = r#"
[package]
name = "test-lib"
[dependencies]
serde = "1.0"
"#;
fs::write(project_root.join("wj.toml"), wj_toml).unwrap();
let lib_output = project_root.join("lib");
fs::create_dir_all(&lib_output).unwrap();
let initial_cargo_toml = r#"[package]
name = "test-lib"
[dependencies]
serde = "1.0"
[lib]
name = "test_lib"
[workspace]
"#;
fs::write(lib_output.join("Cargo.toml"), initial_cargo_toml).unwrap();
let cargo_toml = fs::read_to_string(lib_output.join("Cargo.toml")).unwrap();
let count = cargo_toml.matches("serde = ").count();
assert_eq!(count, 1, "serde dependency should not be duplicated");
}