#[cfg(test)]
mod tests {
    use dbnexus_cli::schema::Schema;
    use dbnexus_cli::diff::SchemaDiff;

    #[test]
    fn test_detect_added_table() {
        let old_schema = Schema::from_sql("CREATE TABLE users (id INT);").unwrap();
        let new_schema = Schema::from_sql("CREATE TABLE users (id INT); CREATE TABLE posts (id INT);").unwrap();
        let diff = SchemaDiff::compare(&old_schema, &new_schema);
        assert_eq!(diff.added_tables.len(), 1);
        assert_eq!(diff.added_tables[0].name, "posts");
    }

    #[test]
    fn test_detect_removed_table() {
        let old_schema = Schema::from_sql("CREATE TABLE users (id INT); CREATE TABLE posts (id INT);").unwrap();
        let new_schema = Schema::from_sql("CREATE TABLE users (id INT);").unwrap();
        let diff = SchemaDiff::compare(&old_schema, &new_schema);
        assert_eq!(diff.removed_tables.len(), 1);
        assert_eq!(diff.removed_tables[0], "posts");
    }

    #[test]
    fn test_detect_added_column() {
        let old_schema = Schema::from_sql("CREATE TABLE users (id INT);").unwrap();
        let new_schema = Schema::from_sql("CREATE TABLE users (id INT, name TEXT);").unwrap();
        let diff = SchemaDiff::compare(&old_schema, &new_schema);
        assert!(diff.table_changes.contains_key("users"));
        let table_diff = diff.table_changes.get("users").unwrap();
        assert_eq!(table_diff.added_columns.len(), 1);
        assert_eq!(table_diff.added_columns[0], "name");
    }

    #[test]
    fn test_detect_removed_column() {
        let old_schema = Schema::from_sql("CREATE TABLE users (id INT, name TEXT);").unwrap();
        let new_schema = Schema::from_sql("CREATE TABLE users (id INT);").unwrap();
        let diff = SchemaDiff::compare(&old_schema, &new_schema);
        assert!(diff.table_changes.contains_key("users"));
        let table_diff = diff.table_changes.get("users").unwrap();
        assert_eq!(table_diff.removed_columns.len(), 1);
        assert_eq!(table_diff.removed_columns[0], "name");
    }

    #[test]
    fn test_has_changes() {
        let old_schema = Schema::from_sql("CREATE TABLE users (id INT);").unwrap();
        let new_schema = Schema::from_sql("CREATE TABLE users (id INT);").unwrap();
        let diff = SchemaDiff::compare(&old_schema, &new_schema);
        assert!(!diff.has_changes());

        let new_schema2 = Schema::from_sql("CREATE TABLE users (id INT, name TEXT);").unwrap();
        let diff2 = SchemaDiff::compare(&old_schema, &new_schema2);
        assert!(diff2.has_changes());
    }
}