use folk_builder::config::BuildConfig;

#[test]
fn parse_sample_config() {
    let toml_str = r#"
[build]
output = "folk-custom"
rust_version = "1.85"

[[plugin]]
crate_name = "folk_plugin_http"
version = "0.1.0"
config_key = "http"

[[plugin]]
crate_name = "folk_plugin_jobs"
version = "0.1.0"
config_key = "jobs"

[[plugin]]
crate_name = "my_custom_plugin"
path = "../my-plugin"
"#;

    let cfg: BuildConfig = toml::from_str(toml_str).unwrap();
    assert_eq!(cfg.build.output, "folk-custom");
    assert_eq!(cfg.build.rust_version, "1.85");
    assert_eq!(cfg.plugin.len(), 3);

    assert_eq!(cfg.plugin[0].crate_name, "folk_plugin_http");
    assert_eq!(cfg.plugin[0].version.as_deref(), Some("0.1.0"));
    assert_eq!(cfg.plugin[0].config_key, "http");

    assert_eq!(cfg.plugin[1].crate_name, "folk_plugin_jobs");
    assert_eq!(cfg.plugin[1].config_key, "jobs");

    assert_eq!(cfg.plugin[2].crate_name, "my_custom_plugin");
    assert_eq!(cfg.plugin[2].path.as_deref(), Some("../my-plugin"));
    assert!(cfg.plugin[2].version.is_none());
}

#[test]
fn default_rust_version() {
    let toml_str = r#"
[build]
output = "folk-minimal"
"#;

    let cfg: BuildConfig = toml::from_str(toml_str).unwrap();
    assert_eq!(cfg.build.rust_version, "1.85");
    assert!(cfg.plugin.is_empty());
}
