@@ -293,6 +293,43 @@ def with_failing_method(klass, method_name, message)
293293 klass . define_method ( method_name , original_method )
294294 end
295295
296+ def test_call_candidates_are_sorted_with_underscore_methods_last
297+ type = Struct . new ( :methods ) . new ( %i[ _zeta beta _alpha alpha ] )
298+ result = ReplTypeCompletor ::Result . new ( [ :call , '' , type , false ] , binding , __FILE__ )
299+
300+ assert_equal %w[ alpha beta _alpha _zeta ] , result . completion_candidates
301+ end
302+
303+ def test_call_or_const_candidates_are_sorted_within_groups
304+ type = Struct . new ( :methods , :constants ) . new ( %i[ z_method a_method ] , %i[ ZConst AConst ] )
305+ result = ReplTypeCompletor ::Result . new ( [ :call_or_const , '' , type , false ] , binding , __FILE__ )
306+
307+ assert_equal %w[ a_method z_method AConst ZConst ] , result . completion_candidates
308+ end
309+
310+ def test_const_candidates_are_sorted_before_reserved_words
311+ scope = Struct . new ( :constants ) . new ( %w[ ZConst AConst ] )
312+ result = ReplTypeCompletor ::Result . new ( [ :const , '' , nil , scope ] , binding , __FILE__ )
313+
314+ assert_equal %w[ AConst ZConst ] + ReplTypeCompletor ::Result ::RESERVED_WORDS , result . completion_candidates
315+ end
316+
317+ def test_ivar_candidates_are_sorted_within_groups
318+ scope = Struct . new ( :instance_variables , :class_variables ) . new ( %w[ @z @a ] , %w[ @@z @@a ] )
319+ result = ReplTypeCompletor ::Result . new ( [ :ivar , '@' , scope ] , binding , __FILE__ )
320+
321+ assert_equal %w[ a z @a @z ] , result . completion_candidates
322+ end
323+
324+ def test_lvar_or_method_candidates_are_sorted_within_groups
325+ type = Struct . new ( :all_methods ) . new ( %i[ z_method a_method ] )
326+ scope = Struct . new ( :self_type , :local_variables ) . new ( type , %w[ z_local a_local ] )
327+ result = ReplTypeCompletor ::Result . new ( [ :lvar_or_method , '' , scope ] , binding , __FILE__ )
328+
329+ expected = %w[ a_local z_local a_method z_method ] + ReplTypeCompletor ::Result ::RESERVED_WORDS
330+ assert_equal expected , result . completion_candidates
331+ end
332+
296333 def test_analyze_error
297334 with_failing_method ( ReplTypeCompletor . singleton_class , :analyze_code , 'error_in_analyze_code' ) do
298335 assert_nil ReplTypeCompletor . analyze ( '1.' , binding : binding )
0 commit comments