Skip to content

Commit 006810c

Browse files
authored
chore: add test (#260)
1 parent f845087 commit 006810c

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

Diff for: crates/pgt_workspace/src/workspace/server/change.rs

+73
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,79 @@ mod tests {
11161116
assert_document_integrity(&doc);
11171117
}
11181118

1119+
#[test]
1120+
fn comment_at_begin() {
1121+
let path = PgTPath::new("test.sql");
1122+
1123+
let mut doc = Document::new(
1124+
path.clone(),
1125+
"-- Add new schema named \"private\"\nCREATE SCHEMA \"private\";".to_string(),
1126+
0,
1127+
);
1128+
1129+
let change = ChangeFileParams {
1130+
path: path.clone(),
1131+
version: 1,
1132+
changes: vec![ChangeParams {
1133+
text: "".to_string(),
1134+
range: Some(TextRange::new(0.into(), 1.into())),
1135+
}],
1136+
};
1137+
1138+
let changed = doc.apply_file_change(&change);
1139+
1140+
assert_eq!(
1141+
doc.content,
1142+
"- Add new schema named \"private\"\nCREATE SCHEMA \"private\";"
1143+
);
1144+
1145+
assert_eq!(changed.len(), 3);
1146+
assert!(matches!(
1147+
changed[0],
1148+
StatementChange::Deleted(Statement { id: 0, .. })
1149+
));
1150+
assert!(matches!(
1151+
changed[1],
1152+
StatementChange::Added(AddedStatement { .. })
1153+
));
1154+
assert!(matches!(
1155+
changed[2],
1156+
StatementChange::Added(AddedStatement { .. })
1157+
));
1158+
1159+
let change_2 = ChangeFileParams {
1160+
path: path.clone(),
1161+
version: 2,
1162+
changes: vec![ChangeParams {
1163+
text: "-".to_string(),
1164+
range: Some(TextRange::new(0.into(), 0.into())),
1165+
}],
1166+
};
1167+
1168+
let changed_2 = doc.apply_file_change(&change_2);
1169+
1170+
assert_eq!(
1171+
doc.content,
1172+
"-- Add new schema named \"private\"\nCREATE SCHEMA \"private\";"
1173+
);
1174+
1175+
assert_eq!(changed_2.len(), 3);
1176+
assert!(matches!(
1177+
changed_2[0],
1178+
StatementChange::Deleted(Statement { .. })
1179+
));
1180+
assert!(matches!(
1181+
changed_2[1],
1182+
StatementChange::Deleted(Statement { .. })
1183+
));
1184+
assert!(matches!(
1185+
changed_2[2],
1186+
StatementChange::Added(AddedStatement { .. })
1187+
));
1188+
1189+
assert_document_integrity(&doc);
1190+
}
1191+
11191192
#[test]
11201193
fn apply_changes_within_statement() {
11211194
let input = "select id from users;\nselect * from contacts;";

Diff for: justfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ _default:
22
just --list -u
33

44
alias f := format
5-
alias t := test
65
alias r := ready
76
alias l := lint
7+
alias t := test
88

99
# Installs the tools needed to develop
1010
install-tools:
@@ -109,4 +109,4 @@ merge-main:
109109

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

0 commit comments

Comments
 (0)