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

    #[test]
    fn test_generate_up_sql_for_added_table() {
        let old_schema = Schema::from_sql("CREATE TABLE users (id INT PRIMARY KEY, name TEXT);").unwrap();
        let new_schema = Schema::from_sql("CREATE TABLE users (id INT PRIMARY KEY, name TEXT); CREATE TABLE posts (id INT PRIMARY KEY);").unwrap();
        let diff = SchemaDiff::compare(&old_schema, &new_schema);
        let sql = generate_sql(&diff, "sqlite");
        assert!(sql.up.contains("CREATE TABLE"));
        assert!(sql.up.contains("posts"));
        assert!(sql.down.contains("DROP TABLE"));
    }

    #[test]
    fn test_generate_up_sql_for_added_column() {
        let old_schema = Schema::from_sql("CREATE TABLE users (id INT PRIMARY KEY);").unwrap();
        let new_schema = Schema::from_sql("CREATE TABLE users (id INT PRIMARY KEY, email TEXT);").unwrap();
        let diff = SchemaDiff::compare(&old_schema, &new_schema);
        let sql = generate_sql(&diff, "sqlite");
        assert!(sql.up.contains("ALTER TABLE"));
        assert!(sql.up.contains("ADD COLUMN"));
        assert!(sql.up.contains("email"));
    }

    #[test]
    fn test_generate_down_sql_for_removed_column() {
        let old_schema = Schema::from_sql("CREATE TABLE users (id INT PRIMARY KEY, email TEXT);").unwrap();
        let new_schema = Schema::from_sql("CREATE TABLE users (id INT PRIMARY KEY);").unwrap();
        let diff = SchemaDiff::compare(&old_schema, &new_schema);
        let sql = generate_sql(&diff, "sqlite");
        assert!(sql.up.contains("DROP COLUMN"));
        assert!(sql.up.contains("email"));
    }
}