//! Tests for environment variable loading.

use cfgmatic::EnvLoader;

#[test]
fn test_env_loader_build_name() {
    let loader = EnvLoader::new().prefix("MYAPP");
    assert_eq!(loader.build_name(&["port"]), "MYAPP__PORT");
    assert_eq!(loader.build_name(&["db", "url"]), "MYAPP__DB__URL");

    let loader = EnvLoader::new();
    assert_eq!(loader.build_name(&["port"]), "PORT");
}

#[test]
fn test_env_loader_custom_separator() {
    let loader = EnvLoader::new().prefix("MYAPP").separator("_");
    assert_eq!(loader.build_name(&["port"]), "MYAPP_PORT");
    assert_eq!(loader.build_name(&["db", "url"]), "MYAPP_DB_URL");
}

#[test]
fn test_env_loader_try_load() {
    let loader = EnvLoader::new().prefix("TEST_LOAD");

    // Test with no env var
    let result: Result<Option<u32>, _> = loader.try_load(&["missing"]);
    assert!(result.unwrap().is_none());
}
