@@ -118,43 +118,59 @@ mod tests {
118
118
} ,
119
119
CompletionItemKind ,
120
120
} ;
121
- use insta:: { assert_snapshot, assert_debug_snapshot} ;
122
- use rustc_hash:: FxHashSet ;
121
+ use insta:: assert_debug_snapshot;
123
122
124
123
fn do_keyword_completion ( code : & str ) -> Vec < CompletionItem > {
125
124
do_completion ( code, CompletionKind :: Keyword )
126
125
}
127
126
128
- fn assert_completion_keyword ( code : & str , keywords : & [ ( & str , & str ) ] ) {
127
+ fn get_completion_text_and_assert_positions ( code : & str ) -> Vec < ( String , String ) > {
129
128
let ( position, completion_items) =
130
129
do_completion_with_position ( code, CompletionKind :: Keyword ) ;
131
- let mut expected_keywords = FxHashSet :: < ( String , String ) > :: default ( ) ;
132
- for ( key, value) in keywords {
133
- expected_keywords. insert ( ( ( * key) . to_string ( ) , ( * value) . to_string ( ) ) ) ;
134
- }
135
- let mut returned_keywords = FxHashSet :: < ( String , String ) > :: default ( ) ;
136
-
130
+ let mut returned_keywords = Vec :: < ( String , String ) > :: new ( ) ;
131
+
137
132
for item in completion_items {
138
- assert ! ( item. text_edit( ) . len( ) == 1 ) ;
133
+ debug_assert ! ( item. text_edit( ) . len( ) == 1 ) ;
139
134
assert ! ( item. kind( ) == Some ( CompletionItemKind :: Keyword ) ) ;
140
135
let atom = item. text_edit ( ) . iter ( ) . next ( ) . unwrap ( ) . clone ( ) ;
141
136
assert ! ( atom. delete. start( ) == position. offset) ;
142
137
assert ! ( atom. delete. end( ) == position. offset) ;
143
138
let pair = ( item. label ( ) . to_string ( ) , atom. insert ) ;
144
- returned_keywords. insert ( pair) ;
139
+ returned_keywords. push ( pair) ;
145
140
}
146
- let assert_failed_message = format ! ( "Expected keywords: {:#?} \n Received keywords: {:#?}" , expected_keywords , returned_keywords) ;
147
- debug_assert ! ( returned_keywords == expected_keywords , assert_failed_message ) ;
141
+ returned_keywords. sort ( ) ;
142
+ returned_keywords
148
143
}
149
144
150
145
#[ test]
151
146
fn completes_keywords_in_use_stmt_new_approach ( ) {
152
- assert_completion_keyword (
153
- r"
154
- use <|>
155
- " ,
156
- & [ ( "crate" , "crate::" ) , ( "self" , "self" ) , ( "super" , "super::" ) ] ,
147
+ assert_debug_snapshot ! (
148
+ get_completion_text_and_assert_positions( r"
149
+ use <|>
150
+ " ) ,
151
+ @r###"
152
+ [
153
+ (
154
+ "crate",
155
+ "crate::",
156
+ ),
157
+ (
158
+ "self",
159
+ "self",
160
+ ),
161
+ (
162
+ "super",
163
+ "super::",
164
+ ),
165
+ ]
166
+ "###
157
167
) ;
168
+ // assert_completion_keyword(
169
+ // r"
170
+ // use <|>
171
+ // ",
172
+ // &[("crate", "crate::"), ("self", "self"), ("super", "super::")],
173
+ // );
158
174
}
159
175
160
176
#[ test]
0 commit comments