mirror of
https://github.com/lbonn/rofi
synced 2024-11-10 14:24:27 +00:00
Add some more tests, make some textbox api's private
This commit is contained in:
parent
d0d1869604
commit
881056ea9b
6 changed files with 89 additions and 53 deletions
|
@ -366,6 +366,7 @@ coverage/index.html: coverage.info
|
|||
.PHONY: coverage-clean
|
||||
coverage-clean:
|
||||
-rm -r coverage.info coverage/
|
||||
-find $(top_builddir) -name '*.gcda' | xargs rm
|
||||
|
||||
.PHONY: .FORCE
|
||||
.FORCE:
|
||||
|
|
|
@ -136,13 +136,6 @@ int textbox_keybinding ( textbox *tb, KeyBindingAction action );
|
|||
*/
|
||||
gboolean textbox_append_char ( textbox *tb, const char *pad, const int pad_len );
|
||||
|
||||
/**
|
||||
* @param tb Handle to the textbox
|
||||
*
|
||||
* Move the cursor to the end of the string.
|
||||
*/
|
||||
void textbox_cursor_end ( textbox *tb );
|
||||
|
||||
/**
|
||||
* @param tb Handle to the textbox
|
||||
* @param pos New cursor position
|
||||
|
@ -207,34 +200,6 @@ int textbox_get_font_width ( const textbox *tb );
|
|||
*/
|
||||
double textbox_get_estimated_char_width ( void );
|
||||
|
||||
/**
|
||||
* @param tb Handle to the textbox
|
||||
*
|
||||
* Delete character before cursor.
|
||||
*/
|
||||
void textbox_cursor_bkspc ( textbox *tb );
|
||||
|
||||
/**
|
||||
* @param tb Handle to the textbox
|
||||
*
|
||||
* Delete character after cursor.
|
||||
*/
|
||||
void textbox_cursor_del ( textbox *tb );
|
||||
|
||||
/**
|
||||
* @param tb Handle to the textbox
|
||||
*
|
||||
* Move cursor one position backward.
|
||||
*/
|
||||
void textbox_cursor_dec ( textbox *tb );
|
||||
|
||||
/**
|
||||
* @param tb Handle to the textbox
|
||||
*
|
||||
* Move cursor one position forward.
|
||||
*/
|
||||
void textbox_cursor_inc ( textbox *tb );
|
||||
|
||||
/**
|
||||
* @param tb Handle to the textbox
|
||||
* @param pos The start position
|
||||
|
|
|
@ -656,7 +656,7 @@ inline static void rofi_view_nav_row_select ( RofiViewState *state )
|
|||
char *str = mode_get_completion ( state->sw, state->line_map[selected] );
|
||||
textbox_text ( state->text, str );
|
||||
g_free ( str );
|
||||
textbox_cursor_end ( state->text );
|
||||
textbox_keybinding ( state->text, MOVE_END );
|
||||
state->refilter = TRUE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,13 @@ static void textbox_free ( widget * );
|
|||
static int textbox_get_width ( widget * );
|
||||
static int _textbox_get_height ( widget * );
|
||||
|
||||
/**
|
||||
* @param tb Handle to the textbox
|
||||
*
|
||||
* Move the cursor to the end of the string.
|
||||
*/
|
||||
static void textbox_cursor_end ( textbox *tb );
|
||||
|
||||
/**
|
||||
* Font + font color cache.
|
||||
* Avoid re-loading font on every change on every textbox.
|
||||
|
@ -406,14 +413,22 @@ void textbox_cursor ( textbox *tb, int pos )
|
|||
widget_queue_redraw ( WIDGET ( tb ) );
|
||||
}
|
||||
|
||||
// move right
|
||||
void textbox_cursor_inc ( textbox *tb )
|
||||
/**
|
||||
* @param tb Handle to the textbox
|
||||
*
|
||||
* Move cursor one position forward.
|
||||
*/
|
||||
static void textbox_cursor_inc ( textbox *tb )
|
||||
{
|
||||
textbox_cursor ( tb, tb->cursor + 1 );
|
||||
}
|
||||
|
||||
// move left
|
||||
void textbox_cursor_dec ( textbox *tb )
|
||||
/**
|
||||
* @param tb Handle to the textbox
|
||||
*
|
||||
* Move cursor one position backward.
|
||||
*/
|
||||
static void textbox_cursor_dec ( textbox *tb )
|
||||
{
|
||||
textbox_cursor ( tb, tb->cursor - 1 );
|
||||
}
|
||||
|
@ -481,7 +496,7 @@ static void textbox_cursor_dec_word ( textbox *tb )
|
|||
}
|
||||
|
||||
// end of line
|
||||
void textbox_cursor_end ( textbox *tb )
|
||||
static void textbox_cursor_end ( textbox *tb )
|
||||
{
|
||||
if ( tb->text == NULL ) {
|
||||
tb->cursor = 0;
|
||||
|
@ -547,8 +562,12 @@ void textbox_delete ( textbox *tb, int pos, int dlen )
|
|||
tb->update = TRUE;
|
||||
}
|
||||
|
||||
// delete on character
|
||||
void textbox_cursor_del ( textbox *tb )
|
||||
/**
|
||||
* @param tb Handle to the textbox
|
||||
*
|
||||
* Delete character after cursor.
|
||||
*/
|
||||
static void textbox_cursor_del ( textbox *tb )
|
||||
{
|
||||
if ( tb->text == NULL ) {
|
||||
return;
|
||||
|
@ -556,8 +575,12 @@ void textbox_cursor_del ( textbox *tb )
|
|||
textbox_delete ( tb, tb->cursor, 1 );
|
||||
}
|
||||
|
||||
// back up and delete one character
|
||||
void textbox_cursor_bkspc ( textbox *tb )
|
||||
/**
|
||||
* @param tb Handle to the textbox
|
||||
*
|
||||
* Delete character before cursor.
|
||||
*/
|
||||
static void textbox_cursor_bkspc ( textbox *tb )
|
||||
{
|
||||
if ( tb->cursor > 0 ) {
|
||||
textbox_cursor_dec ( tb );
|
||||
|
|
|
@ -78,4 +78,24 @@ int main ( int argc, char ** argv )
|
|||
TASSERTE ( levenshtein ( "aap", "noot aap mies" ), 10 );
|
||||
TASSERTE ( levenshtein ( "noot aap mies", "aap" ), 10 );
|
||||
TASSERTE ( levenshtein ( "otp", "noot aap" ), 5 );
|
||||
/**
|
||||
* Quick converision check.
|
||||
*/
|
||||
{
|
||||
char *str = rofi_latin_to_utf8_strdup ( "\xA1\xB5", 2);
|
||||
TASSERT ( g_utf8_collate ( str, "¡µ") == 0 );
|
||||
g_free(str);
|
||||
}
|
||||
|
||||
{
|
||||
char *str = rofi_force_utf8("Valid utf8", 10);
|
||||
TASSERT ( g_utf8_collate ( str, "Valid utf8") == 0 );
|
||||
g_free(str);
|
||||
char in[] = "Valid utf8 until \xc3\x28 we continue here";
|
||||
TASSERT ( g_utf8_validate ( in, -1, NULL ) == FALSE );
|
||||
str = rofi_force_utf8(in, strlen(in));
|
||||
TASSERT ( g_utf8_validate ( str, -1, NULL ) == TRUE );
|
||||
TASSERT ( g_utf8_collate ( str, "Valid utf8 until <20>( we continue here") == 0 );
|
||||
g_free(str);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
|
|||
NORMAL, "test" );
|
||||
TASSERT ( box != NULL );
|
||||
|
||||
textbox_cursor_end ( box );
|
||||
textbox_keybinding ( box, MOVE_END );
|
||||
TASSERT ( box->cursor == 4 );
|
||||
textbox_cursor ( box, -1 );
|
||||
TASSERT ( box->cursor == 0 );
|
||||
|
@ -67,7 +67,7 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
|
|||
TASSERT ( box->cursor == 2 );
|
||||
textbox_insert ( box, 3, "bo", 2 );
|
||||
TASSERT ( strcmp ( box->text, "tesbot" ) == 0 );
|
||||
textbox_cursor_end ( box );
|
||||
textbox_keybinding ( box, MOVE_END );
|
||||
TASSERT ( box->cursor == 6 );
|
||||
|
||||
TASSERT ( widget_get_width ( WIDGET ( box ) ) > 0 );
|
||||
|
@ -78,19 +78,19 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
|
|||
|
||||
TASSERT ( textbox_get_estimated_char_width ( ) > 0 );
|
||||
|
||||
textbox_cursor_bkspc ( box );
|
||||
textbox_keybinding ( box, REMOVE_CHAR_BACK );
|
||||
TASSERT ( strcmp ( box->text, "tesbo" ) == 0 );
|
||||
TASSERT ( box->cursor == 5 );
|
||||
|
||||
textbox_cursor_dec ( box );
|
||||
textbox_keybinding ( box, MOVE_CHAR_BACK );
|
||||
TASSERT ( box->cursor == 4 );
|
||||
textbox_cursor_del ( box );
|
||||
textbox_keybinding ( box, REMOVE_CHAR_FORWARD );
|
||||
TASSERT ( strcmp ( box->text, "tesb" ) == 0 );
|
||||
textbox_cursor_dec ( box );
|
||||
textbox_keybinding ( box, MOVE_CHAR_BACK );
|
||||
TASSERT ( box->cursor == 3 );
|
||||
textbox_cursor_inc ( box );
|
||||
textbox_keybinding ( box, MOVE_CHAR_FORWARD);
|
||||
TASSERT ( box->cursor == 4 );
|
||||
textbox_cursor_inc ( box );
|
||||
textbox_keybinding ( box, MOVE_CHAR_FORWARD);
|
||||
TASSERT ( box->cursor == 4 );
|
||||
// Cursor after delete section.
|
||||
textbox_delete ( box, 0, 1 );
|
||||
|
@ -122,6 +122,33 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
|
|||
TASSERT ( strcmp ( box->text, "aapmies" ) == 0 );
|
||||
TASSERT ( box->cursor == 5 );
|
||||
|
||||
|
||||
textbox_text ( box, "aap noot mies");
|
||||
textbox_cursor ( box, 8 );
|
||||
textbox_keybinding ( box, REMOVE_WORD_BACK );
|
||||
TASSERT ( box->cursor == 4);
|
||||
TASSERT ( strcmp ( box->text, "aap mies") == 0 );
|
||||
textbox_keybinding ( box, REMOVE_TO_EOL );
|
||||
TASSERT ( box->cursor == 4);
|
||||
TASSERT ( strcmp ( box->text, "aap ") == 0 );
|
||||
textbox_text ( box, "aap noot mies");
|
||||
textbox_cursor ( box, 8 );
|
||||
textbox_keybinding ( box, REMOVE_WORD_FORWARD );
|
||||
TASSERT ( strcmp ( box->text, "aap noot") == 0 );
|
||||
textbox_keybinding ( box, MOVE_FRONT );
|
||||
TASSERT ( box->cursor == 0);
|
||||
textbox_keybinding ( box, CLEAR_LINE );
|
||||
TASSERT ( strcmp ( box->text, "") == 0 );
|
||||
textbox_text ( box, "aap noot mies");
|
||||
textbox_keybinding ( box, MOVE_END);
|
||||
textbox_keybinding ( box, MOVE_WORD_BACK );
|
||||
TASSERT ( box->cursor == 9);
|
||||
textbox_keybinding ( box, MOVE_WORD_BACK );
|
||||
TASSERT ( box->cursor == 4);
|
||||
textbox_keybinding ( box, REMOVE_TO_SOL );
|
||||
TASSERT ( strcmp ( box->text, "noot mies") == 0 );
|
||||
TASSERT ( box->cursor == 0);
|
||||
|
||||
textbox_font ( box, HIGHLIGHT );
|
||||
//textbox_draw ( box, draw );
|
||||
|
||||
|
|
Loading…
Reference in a new issue