Skip to content

Commit 74ef0b9

Browse files
committed
fix: typing comments
1 parent c6001fe commit 74ef0b9

File tree

1 file changed

+66
-0
lines changed
  • crates/pgt_workspace/src/workspace/server

1 file changed

+66
-0
lines changed

crates/pgt_workspace/src/workspace/server/change.rs

+66
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,72 @@ mod tests {
460460
assert!(d.has_fatal_error());
461461
}
462462

463+
#[test]
464+
fn typing_comments() {
465+
let path = PgTPath::new("test.sql");
466+
let input = "select id from users;\n";
467+
468+
let mut d = Document::new(input.to_string(), 0);
469+
470+
let change1 = ChangeFileParams {
471+
path: path.clone(),
472+
version: 1,
473+
changes: vec![ChangeParams {
474+
text: "-".to_string(),
475+
range: Some(TextRange::new(22.into(), 23.into())),
476+
}],
477+
};
478+
479+
let _changed1 = d.apply_file_change(&change1);
480+
481+
assert_eq!(d.content, "select id from users;\n-");
482+
assert_eq!(d.positions.len(), 2);
483+
484+
let change2 = ChangeFileParams {
485+
path: path.clone(),
486+
version: 2,
487+
changes: vec![ChangeParams {
488+
text: "-".to_string(),
489+
range: Some(TextRange::new(23.into(), 24.into())),
490+
}],
491+
};
492+
493+
let _changed2 = d.apply_file_change(&change2);
494+
495+
assert_eq!(d.content, "select id from users;\n--");
496+
assert_eq!(d.positions.len(), 1);
497+
498+
let change3 = ChangeFileParams {
499+
path: path.clone(),
500+
version: 3,
501+
changes: vec![ChangeParams {
502+
text: " ".to_string(),
503+
range: Some(TextRange::new(24.into(), 25.into())),
504+
}],
505+
};
506+
507+
let _changed3 = d.apply_file_change(&change3);
508+
509+
assert_eq!(d.content, "select id from users;\n-- ");
510+
assert_eq!(d.positions.len(), 1);
511+
512+
let change4 = ChangeFileParams {
513+
path: path.clone(),
514+
version: 3,
515+
changes: vec![ChangeParams {
516+
text: "t".to_string(),
517+
range: Some(TextRange::new(25.into(), 26.into())),
518+
}],
519+
};
520+
521+
let _changed4 = d.apply_file_change(&change4);
522+
523+
assert_eq!(d.content, "select id from users;\n-- t");
524+
assert_eq!(d.positions.len(), 1);
525+
526+
assert_document_integrity(&d);
527+
}
528+
463529
#[test]
464530
fn change_into_scan_error_within_statement() {
465531
let path = PgTPath::new("test.sql");

0 commit comments

Comments
 (0)