1
0
mirror of https://gitlab.gnome.org/GNOME/glib.git synced 2026-10-24 00:49:00 +03:00

gfilenamecompleter: Document returned completion order is unspecified

It’s actually the same order as we get the strings from
`GFileEnumerator`, i.e. the inode order on Unix, but telling the user
that is not particularly helpful. If we wanted to return in a specified
order, it would be more useful to do something to do with match length,
but I don’t want to get into trying to work out a good measure for that
at the moment.

So for now, document the returned order as unspecified.

We can always specify an order in future and the only downside will be
that the list potentially gets sorted twice.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Fixes: #3836
This commit is contained in:
Philip Withnall
2026-08-04 12:18:42 +01:00
parent db91208a8e
commit 70355ac696
2 changed files with 23 additions and 4 deletions

View File

@@ -463,8 +463,10 @@ g_filename_completer_get_completion_suffix (GFilenameCompleter *completer,
*
* Gets an array of completion strings for a given initial text.
*
* Returns: (array zero-terminated=1) (transfer full): array of strings with possible completions for @initial_text.
* This array must be freed by g_strfreev() when finished.
* The strings are returned in an undefined order.
*
* Returns: (array zero-terminated=1) (transfer full): array of strings with
* possible completions for @initial_text
**/
char **
g_filename_completer_get_completions (GFilenameCompleter *completer,

View File

@@ -45,6 +45,23 @@ prefix_filenames (const gchar *const strings[],
return g_strv_builder_unref_to_strv (builder);
}
static int
strcmp_data (const void *a,
const void *b,
void *user_data)
{
return strcmp (*((const char * const *) a), *((const char * const *) b));
}
#define assert_cmpstrv_unsorted(a1, a2) \
G_STMT_START { \
const char **_a1 = (const char **) (a1); \
const char **_a2 = (const char **) (a2); \
g_sort_array (_a1, g_strv_length ((char **) _a1), sizeof (*_a1), strcmp_data, NULL); \
g_sort_array (_a2, g_strv_length ((char **) _a2), sizeof (*_a2), strcmp_data, NULL); \
g_assert_cmpstrv (_a1, _a2); \
} G_STMT_END
typedef struct
{
const gchar *string;
@@ -80,7 +97,7 @@ run_test_cases (const FilenameCompleterTestCase test_cases[],
all_expected_completions = prefix_filenames (test_cases[i].all_completions, base_path);
all_results_completions = g_filename_completer_get_completions (all_completer, path_to_complete);
g_assert_cmpstrv (all_expected_completions, all_results_completions);
assert_cmpstrv_unsorted (all_expected_completions, all_results_completions);
g_strfreev (all_expected_completions);
g_strfreev (all_results_completions);
@@ -99,7 +116,7 @@ run_test_cases (const FilenameCompleterTestCase test_cases[],
dirs_expected_completions = prefix_filenames (test_cases[i].dirs_completions, base_path);
dirs_results_completions = g_filename_completer_get_completions (dirs_completer, path_to_complete);
g_assert_cmpstrv (dirs_expected_completions, dirs_results_completions);
assert_cmpstrv_unsorted (dirs_expected_completions, dirs_results_completions);
g_strfreev (dirs_expected_completions);
g_strfreev (dirs_results_completions);