Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions crates/pgt_workspace/src/workspace/server/change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,69 @@ mod tests {
assert_document_integrity(&doc);
}

#[test]
fn comment_at_begin() {
let path = PgTPath::new("test.sql");

let mut doc = Document::new(path.clone(), "-- Add new schema named \"private\"\nCREATE SCHEMA \"private\";".to_string(), 0);

let change = ChangeFileParams {
path: path.clone(),
version: 1,
changes: vec![ChangeParams {
text: "".to_string(),
range: Some(TextRange::new(0.into(), 1.into())),
}],
};

let changed = doc.apply_file_change(&change);

assert_eq!(doc.content, "- Add new schema named \"private\"\nCREATE SCHEMA \"private\";");

assert_eq!(changed.len(), 3);
assert!(matches!(
changed[0],
StatementChange::Deleted(Statement { id: 0, .. })
));
assert!(matches!(
changed[1],
StatementChange::Added(AddedStatement { .. })
));
assert!(matches!(
changed[2],
StatementChange::Added(AddedStatement { .. })
));

let change_2 = ChangeFileParams {
path: path.clone(),
version: 2,
changes: vec![ChangeParams {
text: "-".to_string(),
range: Some(TextRange::new(0.into(), 0.into())),
}],
};

let changed_2 = doc.apply_file_change(&change_2);

assert_eq!(doc.content, "-- Add new schema named \"private\"\nCREATE SCHEMA \"private\";");

assert_eq!(changed_2.len(), 3);
assert!(matches!(
changed_2[0],
StatementChange::Deleted(Statement { .. })
));
assert!(matches!(
changed_2[1],
StatementChange::Deleted(Statement { .. })
));
assert!(matches!(
changed_2[2],
StatementChange::Added(AddedStatement { .. })
));

assert_document_integrity(&doc);
}

#[test]
fn apply_changes_within_statement() {
let input = "select id from users;\nselect * from contacts;";
Expand Down
Loading