Skip to content

Commit 2f73594

Browse files
committed
try to add repro
1 parent 4cbeb5d commit 2f73594

File tree

1 file changed

+85
-8
lines changed

1 file changed

+85
-8
lines changed

crates/pgt_lsp/tests/server.rs

+85-8
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use tower_lsp::jsonrpc;
3030
use tower_lsp::jsonrpc::Response;
3131
use tower_lsp::lsp_types as lsp;
3232
use tower_lsp::lsp_types::CodeActionContext;
33-
use tower_lsp::lsp_types::CodeActionOrCommand;
3433
use tower_lsp::lsp_types::CodeActionParams;
3534
use tower_lsp::lsp_types::CodeActionResponse;
3635
use tower_lsp::lsp_types::CompletionParams;
@@ -616,16 +615,15 @@ async fn test_execute_statement() -> Result<()> {
616615
result.unwrap().exists.unwrap()
617616
};
618617

619-
assert_eq!(
620-
users_tbl_exists().await,
621-
false,
618+
assert!(
619+
!(users_tbl_exists().await),
622620
"The user table shouldn't exist at this point."
623621
);
624622

625623
let doc_content = r#"
626624
create table users (
627-
id serial primary key,
628-
name text,
625+
id serial primary key,
626+
name text,
629627
email text
630628
);
631629
"#;
@@ -686,9 +684,8 @@ async fn test_execute_statement() -> Result<()> {
686684
)
687685
.await?;
688686

689-
assert_eq!(
687+
assert!(
690688
users_tbl_exists().await,
691-
true,
692689
"Users table did not exists even though it should've been created by the workspace/executeStatement command."
693690
);
694691

@@ -697,3 +694,83 @@ async fn test_execute_statement() -> Result<()> {
697694

698695
Ok(())
699696
}
697+
698+
#[tokio::test]
699+
async fn test_issue_281() -> Result<()> {
700+
let factory = ServerFactory::default();
701+
let mut fs = MemoryFileSystem::default();
702+
let test_db = get_new_test_db().await;
703+
704+
let setup = r#"
705+
create table public.users (
706+
id serial primary key,
707+
name varchar(255) not null
708+
);
709+
"#;
710+
711+
test_db
712+
.execute(setup)
713+
.await
714+
.expect("Failed to setup test database");
715+
716+
let mut conf = PartialConfiguration::init();
717+
conf.merge_with(PartialConfiguration {
718+
db: Some(PartialDatabaseConfiguration {
719+
database: Some(
720+
test_db
721+
.connect_options()
722+
.get_database()
723+
.unwrap()
724+
.to_string(),
725+
),
726+
..Default::default()
727+
}),
728+
..Default::default()
729+
});
730+
fs.insert(
731+
url!("postgrestools.jsonc").to_file_path().unwrap(),
732+
serde_json::to_string_pretty(&conf).unwrap(),
733+
);
734+
735+
let (service, client) = factory
736+
.create_with_fs(None, DynRef::Owned(Box::new(fs)))
737+
.into_inner();
738+
739+
let (stream, sink) = client.split();
740+
let mut server = Server::new(service);
741+
742+
let (sender, _) = channel(CHANNEL_BUFFER_SIZE);
743+
let reader = tokio::spawn(client_handler(stream, sink, sender));
744+
745+
server.initialize().await?;
746+
server.initialized().await?;
747+
748+
server.load_configuration().await?;
749+
750+
server.open_document("select a").await?;
751+
752+
server
753+
.change_document(
754+
3,
755+
vec![TextDocumentContentChangeEvent {
756+
range: Some(Range {
757+
start: Position {
758+
line: 0,
759+
character: 7,
760+
},
761+
end: Position {
762+
line: 0,
763+
character: 7,
764+
},
765+
}),
766+
range_length: Some(0),
767+
text: "ы".to_string(),
768+
}],
769+
)
770+
.await?;
771+
772+
server.shutdown().await?;
773+
reader.abort();
774+
775+
Ok(())
776+
}

0 commit comments

Comments
 (0)