use super::helpers::*;
use tower_lsp_server::ls_types::*;
#[tokio::test]
async fn test_open_document() {
let server = TestLspServer::new();
server
.open_document("file:///test.qmd", "# Hello\n\nWorld", "quarto")
.await;
let content = server.get_document_content("file:///test.qmd").await;
assert_eq!(content, Some("# Hello\n\nWorld".to_string()));
}
#[tokio::test]
async fn test_close_document() {
let server = TestLspServer::new();
server
.open_document("file:///test.qmd", "# Hello", "quarto")
.await;
server.close_document("file:///test.qmd").await;
let content = server.get_document_content("file:///test.qmd").await;
assert_eq!(content, None);
}
#[tokio::test]
async fn test_edit_document_full_replace() {
let server = TestLspServer::new();
server
.open_document("file:///test.qmd", "# Original", "quarto")
.await;
server
.edit_document(
"file:///test.qmd",
vec![full_document_change("# Modified\n\nNew content")],
)
.await;
let content = server.get_document_content("file:///test.qmd").await;
assert_eq!(content, Some("# Modified\n\nNew content".to_string()));
}
#[tokio::test]
async fn test_server_advertises_save_capability() {
let server = TestLspServer::new();
let result = server.initialize_result("file:///workspace").await;
let Some(TextDocumentSyncCapability::Options(sync)) = result.capabilities.text_document_sync
else {
panic!("expected TextDocumentSync options");
};
assert!(
matches!(
sync.save,
Some(TextDocumentSyncSaveOptions::SaveOptions(_))
| Some(TextDocumentSyncSaveOptions::Supported(true))
),
"server should advertise save support, got {:?}",
sync.save
);
}
#[tokio::test]
async fn test_open_edit_save_keeps_document_state() {
let server = TestLspServer::new();
server.initialize("file:///workspace").await;
server
.open_document("file:///test.qmd", "# Original", "quarto")
.await;
server
.edit_document(
"file:///test.qmd",
vec![full_document_change("# Edited\n\nBody")],
)
.await;
server.save_document("file:///test.qmd").await;
let content = server.get_document_content("file:///test.qmd").await;
assert_eq!(content, Some("# Edited\n\nBody".to_string()));
}