Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

migrator: Avoid attempting to migrate empty content (#39771)

Dinoa9455eb947bc
diff --git a/crates/migrator/src/migrator.rs b/crates/migrator/src/migrator.rs
index 74205edd8ac..a493b1efbe0 100644
--- a/crates/migrator/src/migrator.rs
+++ b/crates/migrator/src/migrator.rs
@@ -65,7 +65,13 @@ fn migrate(text: &str, patterns: MigrationPatterns, query: &Query) -> Result<Opt
}
}
+/// Runs the provided migrations on the given text.
+/// Will automatically return `Ok(None)` if there's no content to migrate.
fn run_migrations(text: &str, migrations: &[MigrationType]) -> Result<Option<String>> {
+ if text.is_empty() {
+ return Ok(None);
+ }
+
let mut current_text = text.to_string();
let mut result: Option<String> = None;
for migration in migrations.iter() {
@@ -371,6 +377,11 @@ mod tests {
assert_migrated_correctly(migrated, output);
}
+ #[test]
+ fn test_empty_content() {
+ assert_migrate_settings("", None)
+ }
+
#[test]
fn test_replace_array_with_single_string() {
assert_migrate_keymap(