Skip to content

chore: test for typing comments #347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2025
Merged
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
66 changes: 66 additions & 0 deletions crates/pgt_workspace/src/workspace/server/change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,72 @@ mod tests {
assert!(d.has_fatal_error());
}

#[test]
fn typing_comments() {
let path = PgTPath::new("test.sql");
let input = "select id from users;\n";

let mut d = Document::new(input.to_string(), 0);

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

let _changed1 = d.apply_file_change(&change1);

assert_eq!(d.content, "select id from users;\n-");
assert_eq!(d.positions.len(), 2);

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

let _changed2 = d.apply_file_change(&change2);

assert_eq!(d.content, "select id from users;\n--");
assert_eq!(d.positions.len(), 1);

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

let _changed3 = d.apply_file_change(&change3);

assert_eq!(d.content, "select id from users;\n-- ");
assert_eq!(d.positions.len(), 1);

let change4 = ChangeFileParams {
path: path.clone(),
version: 3,
changes: vec![ChangeParams {
text: "t".to_string(),
range: Some(TextRange::new(25.into(), 26.into())),
}],
};

let _changed4 = d.apply_file_change(&change4);

assert_eq!(d.content, "select id from users;\n-- t");
assert_eq!(d.positions.len(), 1);

assert_document_integrity(&d);
}

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