#[cfg(test)]
mod tests {
    use masl_diagnostics::diagnostic::Diagnostic;
    use masl_hir::analyze;
    use masl_parser::parse;

    fn get_validation_warnings(source: &str) -> Vec<Diagnostic> {
        let ast = parse(source).unwrap();
        let hir = analyze(ast).unwrap();

        // Temporarily collect warnings
        let mut diags = Vec::new();
        masl_validator::rules::check_encapsulation(&hir, &mut diags);
        diags
    }

    #[test]
    fn test_encapsulation_warning() {
        // Traversal targets relation 'admin' instead of public grant
        let source = r#"
            namespace test
            schema 1
            subject User
            resource Org {
                relation {
                    admin: User
                }
                grant {
                    manage => admin
                }
            }
            resource Repo {
                relation {
                    org: Org
                }
                grant {
                    write => org::admin
                }
            }
        "#;
        let warnings = get_validation_warnings(source);
        assert!(
            warnings.iter().any(|w| w.code == "W0600"),
            "Expected W0600 warning not found: {:?}",
            warnings
        );
    }

    #[test]
    fn test_encapsulation_correct() {
        // Traversal targets public grant 'manage'
        let source = r#"
            namespace test
            schema 1
            subject User
            resource Org {
                relation {
                    admin: User
                }
                grant {
                    manage => admin
                }
            }
            resource Repo {
                relation {
                    org: Org
                }
                grant {
                    write => org::manage
                }
            }
        "#;
        let warnings = get_validation_warnings(source);
        assert!(warnings.is_empty(), "Expected no warnings: {:?}", warnings);
    }
}
