autosuggest: add tests to clang suggest provider
A small refactor became obvious because the lookup is not really using the curword passed in - we want all options then filter later!
This commit is contained in:
parent
c5a4aafe4d
commit
53e7419009
|
@ -163,6 +163,7 @@ static void
|
||||||
_suggest_list_update(Edi_Editor *editor, char *word)
|
_suggest_list_update(Edi_Editor *editor, char *word)
|
||||||
{
|
{
|
||||||
Edi_Editor_Suggest_Item *suggest_it;
|
Edi_Editor_Suggest_Item *suggest_it;
|
||||||
|
Edi_Editor_Suggest_Provider *provider;
|
||||||
Eina_List *list, *l;
|
Eina_List *list, *l;
|
||||||
Elm_Genlist_Item_Class *ic;
|
Elm_Genlist_Item_Class *ic;
|
||||||
Elm_Object_Item *item;
|
Elm_Object_Item *item;
|
||||||
|
@ -175,10 +176,11 @@ _suggest_list_update(Edi_Editor *editor, char *word)
|
||||||
ic->item_style = "full";
|
ic->item_style = "full";
|
||||||
ic->func.content_get = _suggest_list_content_get;
|
ic->func.content_get = _suggest_list_content_get;
|
||||||
|
|
||||||
|
provider = edi_editor_suggest_provider_get(editor);
|
||||||
EINA_LIST_FOREACH(list, l, suggest_it)
|
EINA_LIST_FOREACH(list, l, suggest_it)
|
||||||
{
|
{
|
||||||
const char *term;
|
const char *term;
|
||||||
term = edi_editor_suggest_provider_get(editor)->summary_get(editor, suggest_it);
|
term = provider->summary_get(editor, suggest_it);
|
||||||
|
|
||||||
if (eina_str_has_prefix(term, word))
|
if (eina_str_has_prefix(term, word))
|
||||||
{
|
{
|
||||||
|
@ -229,7 +231,7 @@ _suggest_list_set(Edi_Editor *editor)
|
||||||
elm_code_widget_cursor_position_get(editor->entry, &row, &col);
|
elm_code_widget_cursor_position_get(editor->entry, &row, &col);
|
||||||
|
|
||||||
curword = _edi_editor_current_word_get(editor, row, col);
|
curword = _edi_editor_current_word_get(editor, row, col);
|
||||||
list = edi_editor_suggest_provider_get(editor)->lookup(editor, curword);
|
list = edi_editor_suggest_provider_get(editor)->lookup(editor, row, col - strlen(curword));
|
||||||
|
|
||||||
evas_object_data_set(editor->suggest_genlist, "suggest_list", list);
|
evas_object_data_set(editor->suggest_genlist, "suggest_list", list);
|
||||||
_suggest_list_update(editor, curword);
|
_suggest_list_update(editor, curword);
|
||||||
|
|
|
@ -31,7 +31,7 @@ typedef struct _Edi_Editor_Suggest_Provider
|
||||||
|
|
||||||
void (*add)(Edi_Editor *editor);
|
void (*add)(Edi_Editor *editor);
|
||||||
void (*del)(Edi_Editor *editor);
|
void (*del)(Edi_Editor *editor);
|
||||||
Eina_List *(*lookup)(Edi_Editor *editor, const char *word);
|
Eina_List *(*lookup)(Edi_Editor *editor, unsigned int row, unsigned int col);
|
||||||
const char *(*summary_get)(Edi_Editor *editor, Edi_Editor_Suggest_Item *item);
|
const char *(*summary_get)(Edi_Editor *editor, Edi_Editor_Suggest_Item *item);
|
||||||
char *(*detail_get)(Edi_Editor *editor, Edi_Editor_Suggest_Item *item);
|
char *(*detail_get)(Edi_Editor *editor, Edi_Editor_Suggest_Item *item);
|
||||||
void (*item_free)(Edi_Editor_Suggest_Item *item);
|
void (*item_free)(Edi_Editor_Suggest_Item *item);
|
||||||
|
|
|
@ -2,6 +2,13 @@
|
||||||
# include "config.h"
|
# include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if HAVE_LIBCLANG
|
||||||
|
#include <clang-c/Index.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <Eina.h>
|
||||||
|
#include <Elementary.h>
|
||||||
|
|
||||||
#include "edi_editor_suggest_provider.h"
|
#include "edi_editor_suggest_provider.h"
|
||||||
|
|
||||||
#include "edi_config.h"
|
#include "edi_config.h"
|
||||||
|
@ -89,7 +96,7 @@ _edi_editor_sugget_c_del(Edi_Editor *editor)
|
||||||
}
|
}
|
||||||
|
|
||||||
Eina_List *
|
Eina_List *
|
||||||
_edi_editor_suggest_c_lookup(Edi_Editor *editor, const char *curword)
|
_edi_editor_suggest_c_lookup(Edi_Editor *editor, unsigned int row, unsigned int col)
|
||||||
{
|
{
|
||||||
Eina_List *list = NULL;
|
Eina_List *list = NULL;
|
||||||
|
|
||||||
|
@ -97,22 +104,21 @@ _edi_editor_suggest_c_lookup(Edi_Editor *editor, const char *curword)
|
||||||
CXCodeCompleteResults *res;
|
CXCodeCompleteResults *res;
|
||||||
struct CXUnsavedFile unsaved_file;
|
struct CXUnsavedFile unsaved_file;
|
||||||
Elm_Code *code;
|
Elm_Code *code;
|
||||||
const char *path;
|
const char *path = NULL;
|
||||||
unsigned int col, row;
|
|
||||||
|
|
||||||
if (!editor->as_unit)
|
if (!editor->as_unit)
|
||||||
return list;
|
return list;
|
||||||
|
|
||||||
code = elm_code_widget_code_get(editor->entry);
|
code = elm_code_widget_code_get(editor->entry);
|
||||||
path = elm_code_file_path_get(code->file);
|
if (code->file->file)
|
||||||
elm_code_widget_cursor_position_get(editor->entry, &row, &col);
|
path = elm_code_file_path_get(code->file);
|
||||||
|
|
||||||
unsaved_file.Filename = path;
|
unsaved_file.Filename = path;
|
||||||
unsaved_file.Contents = elm_code_widget_text_between_positions_get(
|
unsaved_file.Contents = elm_code_widget_text_between_positions_get(
|
||||||
editor->entry, 1, 1, col, row);
|
editor->entry, 1, 1, col, row);
|
||||||
unsaved_file.Length = strlen(unsaved_file.Contents);
|
unsaved_file.Length = strlen(unsaved_file.Contents);
|
||||||
|
|
||||||
res = clang_codeCompleteAt(editor->as_unit, path, row, col - strlen(curword),
|
res = clang_codeCompleteAt(editor->as_unit, path, row, col,
|
||||||
&unsaved_file, 1,
|
&unsaved_file, 1,
|
||||||
CXCodeComplete_IncludeMacros |
|
CXCodeComplete_IncludeMacros |
|
||||||
CXCodeComplete_IncludeCodePatterns);
|
CXCodeComplete_IncludeCodePatterns);
|
||||||
|
|
|
@ -4,18 +4,24 @@ CLEANFILES = check-results.xml
|
||||||
if EFL_HAVE_TESTS
|
if EFL_HAVE_TESTS
|
||||||
|
|
||||||
check_PROGRAMS = edi_suite
|
check_PROGRAMS = edi_suite
|
||||||
|
efl_cflags_safe = '@EFL_CFLAGS@'
|
||||||
|
clang_include = '$(CLANG_INCLUDE)'
|
||||||
|
|
||||||
edi_suite_SOURCES = \
|
edi_suite_SOURCES = \
|
||||||
edi_test_path.c \
|
edi_test_path.c \
|
||||||
edi_test_content_provider.c \
|
edi_test_content_provider.c \
|
||||||
|
edi_test_editor_suggest_provider.c \
|
||||||
|
edi_test_editor_suggest_provider_c.c \
|
||||||
edi_suite.c
|
edi_suite.c
|
||||||
|
|
||||||
edi_suite_CPPFLAGS = -I$(top_builddir)/src/lib/ -I$(top_builddir)/src/bin/ \
|
edi_suite_CPPFLAGS = -I$(top_builddir)/src/lib/ -I$(top_builddir)/src/bin/ \
|
||||||
-I$(top_srcdir)/src/lib \
|
-I$(top_srcdir)/src/lib \
|
||||||
-I$(top_srcdir)/src/bin \
|
-I$(top_srcdir)/src/bin \
|
||||||
-DPACKAGE_TESTS_DIR=\"$(top_srcdir)/src/tests/\" \
|
-DPACKAGE_TESTS_DIR=\"`pwd`/$(top_srcdir)/src/tests/\" \
|
||||||
-DPACKAGE_BUILD_DIR=\"`pwd`/$(top_builddir)/src/tests/\" \
|
-DPACKAGE_BUILD_DIR=\"`pwd`/$(top_builddir)/src/tests/\" \
|
||||||
-DEFL_BETA_API_SUPPORT \
|
-DEFL_BETA_API_SUPPORT \
|
||||||
|
-DEFL_CFLAGS=\"$(efl_cflags_safe)\" \
|
||||||
|
-DCLANG_INCLUDES=\"$(clang_include)\" \
|
||||||
@EFL_CFLAGS@ \
|
@EFL_CFLAGS@ \
|
||||||
@CHECK_CFLAGS@
|
@CHECK_CFLAGS@
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,9 @@ static const struct {
|
||||||
} tests[] = {
|
} tests[] = {
|
||||||
{ "basic", edi_test_basic },
|
{ "basic", edi_test_basic },
|
||||||
{ "path", edi_test_path },
|
{ "path", edi_test_path },
|
||||||
{ "content_provider", edi_test_content_provider }
|
{ "content_provider", edi_test_content_provider },
|
||||||
|
{ "editor_suggest_provider", edi_test_editor_suggest_provider },
|
||||||
|
{ "editor_suggest_provider_c", edi_test_editor_suggest_provider_c }
|
||||||
};
|
};
|
||||||
|
|
||||||
START_TEST(edi_initialization)
|
START_TEST(edi_initialization)
|
||||||
|
|
|
@ -9,5 +9,7 @@ void edi_test_basic(TCase *tc);
|
||||||
void edi_test_console(TCase *tc);
|
void edi_test_console(TCase *tc);
|
||||||
void edi_test_path(TCase *tc);
|
void edi_test_path(TCase *tc);
|
||||||
void edi_test_content_provider(TCase *tc);
|
void edi_test_content_provider(TCase *tc);
|
||||||
|
void edi_test_editor_suggest_provider(TCase *tc);
|
||||||
|
void edi_test_editor_suggest_provider_c(TCase *tc);
|
||||||
|
|
||||||
#endif /* _EDI_SUITE_H */
|
#endif /* _EDI_SUITE_H */
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "editor/edi_editor_suggest_provider.c"
|
||||||
|
|
||||||
|
#include "edi_suite.h"
|
||||||
|
|
||||||
|
START_TEST (edi_test_editor_suggest_provider_lookup)
|
||||||
|
{
|
||||||
|
Edi_Editor editor;
|
||||||
|
Edi_Editor_Suggest_Provider *provider;
|
||||||
|
|
||||||
|
editor.mimetype = "text/x-csrc";
|
||||||
|
provider = edi_editor_suggest_provider_get(&editor);
|
||||||
|
|
||||||
|
ck_assert(provider);
|
||||||
|
ck_assert_str_eq(provider->id, "c");
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
|
void edi_test_editor_suggest_provider(TCase *tc)
|
||||||
|
{
|
||||||
|
tcase_add_test(tc, edi_test_editor_suggest_provider_lookup);
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,106 @@
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <Elementary.h>
|
||||||
|
|
||||||
|
#include "../bin/edi_private.h"
|
||||||
|
#include "editor/edi_editor_suggest_provider.h"
|
||||||
|
|
||||||
|
#include "edi_suite.h"
|
||||||
|
|
||||||
|
static Elm_Code *
|
||||||
|
_setup(Edi_Editor *editor, Evas_Object *win)
|
||||||
|
{
|
||||||
|
Elm_Code *code;
|
||||||
|
Elm_Code_Widget *widget;
|
||||||
|
|
||||||
|
code = elm_code_create();
|
||||||
|
elm_code_file_open(code, PACKAGE_TESTS_DIR "test.c");
|
||||||
|
|
||||||
|
widget = elm_code_widget_add(win, code);
|
||||||
|
editor->entry = widget;
|
||||||
|
elm_code_widget_cursor_position_set(widget, 3, 12);
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Eina_List *
|
||||||
|
_filtered_list_get(Edi_Editor *editor, Edi_Editor_Suggest_Provider *provider,
|
||||||
|
Eina_List *list, const char *word)
|
||||||
|
{
|
||||||
|
Edi_Editor_Suggest_Item *suggest_it;
|
||||||
|
Eina_List *l, *ret = NULL;
|
||||||
|
|
||||||
|
EINA_LIST_FOREACH(list, l, suggest_it)
|
||||||
|
{
|
||||||
|
const char *term;
|
||||||
|
term = provider->summary_get(editor, suggest_it);
|
||||||
|
|
||||||
|
if (eina_str_has_prefix(term, word))
|
||||||
|
ret = eina_list_append(ret, suggest_it);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
START_TEST (edi_test_editor_suggest_provider_c_lookup)
|
||||||
|
{
|
||||||
|
Elm_Code *code;
|
||||||
|
Evas_Object *win;
|
||||||
|
Edi_Editor editor;
|
||||||
|
Edi_Editor_Suggest_Provider *provider;
|
||||||
|
Eina_List *list;
|
||||||
|
|
||||||
|
elm_init(1, NULL);
|
||||||
|
win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
|
||||||
|
editor.mimetype = "text/x-csrc";
|
||||||
|
code = _setup(&editor, win);
|
||||||
|
|
||||||
|
provider = edi_editor_suggest_provider_get(&editor);
|
||||||
|
provider->add(&editor);
|
||||||
|
list = provider->lookup(&editor, 3, 12);
|
||||||
|
ck_assert_int_eq(eina_list_count(_filtered_list_get(&editor, provider, list, "_xyzabc_")), 1);
|
||||||
|
|
||||||
|
provider->del(&editor);
|
||||||
|
elm_code_free(code);
|
||||||
|
elm_shutdown();
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
|
START_TEST (edi_test_editor_suggest_provider_c_summary)
|
||||||
|
{
|
||||||
|
Elm_Code *code;
|
||||||
|
Evas_Object *win;
|
||||||
|
Edi_Editor editor;
|
||||||
|
Edi_Editor_Suggest_Provider *provider;
|
||||||
|
Edi_Editor_Suggest_Item *item;
|
||||||
|
Eina_List *list;
|
||||||
|
const char *key;
|
||||||
|
|
||||||
|
elm_init(1, NULL);
|
||||||
|
win = elm_win_add(NULL, "entry", ELM_WIN_BASIC);
|
||||||
|
editor.mimetype = "text/x-csrc";
|
||||||
|
code = _setup(&editor, win);
|
||||||
|
|
||||||
|
provider = edi_editor_suggest_provider_get(&editor);
|
||||||
|
provider->add(&editor);
|
||||||
|
list = provider->lookup(&editor, 3, 12);
|
||||||
|
item = eina_list_nth(_filtered_list_get(&editor, provider, list, "_xyzabc_"), 0);
|
||||||
|
key = provider->summary_get(&editor, item);
|
||||||
|
ck_assert_str_eq(key, "_xyzabc_test");
|
||||||
|
|
||||||
|
provider->del(&editor);
|
||||||
|
elm_code_free(code);
|
||||||
|
elm_shutdown();
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
|
void edi_test_editor_suggest_provider_c(TCase *tc)
|
||||||
|
{
|
||||||
|
#if HAVE_LIBCLANG
|
||||||
|
tcase_add_test(tc, edi_test_editor_suggest_provider_c_lookup);
|
||||||
|
tcase_add_test(tc, edi_test_editor_suggest_provider_c_summary);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
static void _xyzabc_test() {}
|
||||||
|
static void _thing() {
|
||||||
|
_xyzabc_
|
Loading…
Reference in New Issue