simplify_baml 0.2.0

Simplified BAML runtime for structured LLM outputs using native Rust types with macros
Documentation
use simplify_baml::*;
use simplify_baml::schema::SchemaFormatter;
use simplify_baml_macros::BamlSchema;

#[derive(BamlSchema)]
#[baml(description = "A person with contact info")]
#[allow(dead_code)]
struct PersonWithContact {
    #[baml(description = "Full name", rename = "fullName")]
    name: String,

    #[baml(rename = "emailAddress", description = "Email contact")]
    email: Option<String>,
}

#[derive(BamlSchema)]
#[allow(dead_code)]
struct PersonSeparateAttrs {
    #[baml(description = "Separate desc")]
    #[baml(rename = "separateName")]
    name2: String,
}

#[test]
fn test_multiple_baml_attrs_in_single_attribute() {
    let registry = BamlSchemaRegistry::new()
        .register::<PersonWithContact>();
    
    let ir = registry.build();
    
    assert_eq!(ir.classes.len(), 1);
    let class = &ir.classes[0];
    assert_eq!(class.name, "PersonWithContact");
    assert_eq!(class.description, Some("A person with contact info".to_string()));
    
    assert_eq!(class.fields.len(), 2);
    
    let name_field = &class.fields[0];
    assert_eq!(name_field.name, "fullName", "Expected rename to work for name field");
    assert_eq!(name_field.description, Some("Full name".to_string()), "Expected description for name field");
    assert!(!name_field.optional);
    
    let email_field = &class.fields[1];
    assert_eq!(email_field.name, "emailAddress", "Expected rename to work for email field (reverse order)");
    assert_eq!(email_field.description, Some("Email contact".to_string()), "Expected description for email field");
    assert!(email_field.optional);
}

#[test]
fn test_separate_baml_attrs() {
    let registry = BamlSchemaRegistry::new()
        .register::<PersonSeparateAttrs>();
    
    let ir = registry.build();
    let class = &ir.classes[0];
    let name_field = &class.fields[0];
    
    assert_eq!(name_field.name, "separateName", "Separate attrs should also work");
    assert_eq!(name_field.description, Some("Separate desc".to_string()));
}

#[test]
fn test_schema_rendering_with_combined_attrs() {
    let registry = BamlSchemaRegistry::new()
        .register::<PersonWithContact>();
    
    let ir = registry.build();
    let output_type = FieldType::Class("PersonWithContact".to_string());
    let schema = SchemaFormatter::new(&ir).render(&output_type);
    
    assert!(schema.contains("fullName:"), "Expected 'fullName:' in schema:\n{}", schema);
    assert!(schema.contains("emailAddress?:"), "Expected 'emailAddress?:' in schema:\n{}", schema);
    assert!(schema.contains("Full name"), "Expected 'Full name' in schema:\n{}", schema);
    assert!(schema.contains("Email contact"), "Expected 'Email contact' in schema:\n{}", schema);
}