@@ -27,8 +27,8 @@ pub fn complete_schemas<'a>(ctx: &'a CompletionContext, builder: &mut Completion
2727mod tests {
2828
2929 use crate :: {
30- CompletionItemKind , complete ,
31- test_helper:: { CURSOR_POS , get_test_deps , get_test_params } ,
30+ CompletionItemKind ,
31+ test_helper:: { CURSOR_POS , CompletionAssertion , assert_complete_results } ,
3232 } ;
3333
3434 #[ tokio:: test]
@@ -46,27 +46,59 @@ mod tests {
4646 );
4747 "# ;
4848
49- let query = format ! ( "select * from {}" , CURSOR_POS ) ;
49+ assert_complete_results (
50+ format ! ( "select * from {}" , CURSOR_POS ) . as_str ( ) ,
51+ vec ! [
52+ CompletionAssertion :: LabelAndKind ( "public" . to_string( ) , CompletionItemKind :: Schema ) ,
53+ CompletionAssertion :: LabelAndKind ( "auth" . to_string( ) , CompletionItemKind :: Schema ) ,
54+ CompletionAssertion :: LabelAndKind (
55+ "internal" . to_string( ) ,
56+ CompletionItemKind :: Schema ,
57+ ) ,
58+ CompletionAssertion :: LabelAndKind (
59+ "private" . to_string( ) ,
60+ CompletionItemKind :: Schema ,
61+ ) ,
62+ CompletionAssertion :: LabelAndKind (
63+ "information_schema" . to_string( ) ,
64+ CompletionItemKind :: Schema ,
65+ ) ,
66+ CompletionAssertion :: LabelAndKind (
67+ "pg_catalog" . to_string( ) ,
68+ CompletionItemKind :: Schema ,
69+ ) ,
70+ CompletionAssertion :: LabelAndKind (
71+ "pg_toast" . to_string( ) ,
72+ CompletionItemKind :: Schema ,
73+ ) ,
74+ CompletionAssertion :: LabelAndKind ( "users" . to_string( ) , CompletionItemKind :: Table ) ,
75+ ] ,
76+ setup,
77+ )
78+ . await ;
79+ }
5080
51- let ( tree, cache) = get_test_deps ( setup, query. as_str ( ) . into ( ) ) . await ;
52- let params = get_test_params ( & tree, & cache, query. as_str ( ) . into ( ) ) ;
53- let items = complete ( params) ;
81+ #[ tokio:: test]
82+ async fn suggests_tables_and_schemas_with_matching_keys ( ) {
83+ let setup = r#"
84+ create schema ultimate;
5485
55- assert ! ( !items. is_empty( ) ) ;
86+ -- add a table to compete against schemas
87+ create table users (
88+ id serial primary key,
89+ name text,
90+ password text
91+ );
92+ "# ;
5693
57- assert_eq ! (
58- items
59- . into_iter( )
60- . take( 5 )
61- . map( |i| ( i. label, i. kind) )
62- . collect:: <Vec <( String , CompletionItemKind ) >>( ) ,
94+ assert_complete_results (
95+ format ! ( "select * from u{}" , CURSOR_POS ) . as_str ( ) ,
6396 vec ! [
64- ( "public" . to_string( ) , CompletionItemKind :: Schema ) ,
65- ( "auth" . to_string( ) , CompletionItemKind :: Schema ) ,
66- ( "internal" . to_string( ) , CompletionItemKind :: Schema ) ,
67- ( "private" . to_string( ) , CompletionItemKind :: Schema ) ,
68- ( "users" . to_string( ) , CompletionItemKind :: Table ) ,
69- ]
70- ) ;
97+ CompletionAssertion :: LabelAndKind ( "users" . into( ) , CompletionItemKind :: Table ) ,
98+ CompletionAssertion :: LabelAndKind ( "ultimate" . into( ) , CompletionItemKind :: Schema ) ,
99+ ] ,
100+ setup,
101+ )
102+ . await ;
71103 }
72104}
0 commit comments