Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
73 changes: 73 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,79 @@ 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
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ _default:
just --list -u

alias f := format
alias t := test
alias r := ready
alias l := lint
alias t := test

# Installs the tools needed to develop
install-tools:
Expand Down Expand Up @@ -109,4 +109,4 @@ merge-main:

# Make sure to set your PGT_LOG_PATH in your shell profile.
show-logs:
tail -f $(ls $PGT_LOG_PATH/server.log.* | sort -t- -k2,2 -k3,3 -k4,4 | tail -n 1)
tail -f $(ls $PGT_LOG_PATH/server.log.* | sort -t- -k2,2 -k3,3 -k4,4 | tail -n 1)