1818#define CTRL_L "\x0c"
1919#define CTRL_R "\x12"
2020#define CTRL_U "\x15"
21+ #define CTRL_X "\x18"
2122
2223static void cli_equals (const struct embedded_cli * cli , const char * line )
2324{
@@ -214,6 +215,8 @@ static void test_multiple(void)
214215 {"abc" LEFT LEFT CTRL_L "\n" , "abc" },
215216 {"abc" CTRL_U "\n" , "" },
216217 {"abc" LEFT LEFT CTRL_U "\n" , "bc" },
218+ // The check below ensures we ignore unknown control sequences
219+ {CTRL_X " " CTRL_X " " CTRL_X "\n" , " " },
217220 {NULL , NULL },
218221 };
219222
@@ -300,22 +303,36 @@ static void test_max_chars(void)
300303 TEST_ASSERT (cli .buffer [sizeof (cli .buffer ) - 2 ] == 'f' );
301304}
302305
303- TEST_LIST = {
304- {"simple" , test_simple },
305- {"argc" , test_argc },
306- {"delete" , test_delete },
307- {"cursor_left" , test_cursor_left },
308- {"cursor_right" , test_cursor_right },
306+ static void test_utf8 (void )
307+ {
308+ struct embedded_cli cli ;
309+ char * * argv ;
310+ embedded_cli_init (& cli , NULL , NULL , NULL );
311+ test_insert_line (& cli , "normal ñ ü 中文 text\n" );
312+ int argc = embedded_cli_argc (& cli , & argv );
313+ TEST_ASSERT (argc == 5 );
314+ TEST_ASSERT (strcmp (argv [0 ], "normal" ) == 0 );
315+ TEST_ASSERT (strcmp (argv [1 ], "ñ" ) == 0 );
316+ TEST_ASSERT (strcmp (argv [2 ], "ü" ) == 0 );
317+ TEST_ASSERT (strcmp (argv [3 ], "中文" ) == 0 );
318+ TEST_ASSERT (strcmp (argv [4 ], "text" ) == 0 );
319+ }
320+
321+ TEST_LIST = {{"simple" , test_simple },
322+ {"argc" , test_argc },
323+ {"delete" , test_delete },
324+ {"cursor_left" , test_cursor_left },
325+ {"cursor_right" , test_cursor_right },
309326#if EMBEDDED_CLI_HISTORY_LEN
310- {"history" , test_history },
311- {"history_keys" , test_history_keys },
312- {"search" , test_search },
313- {"up_down" , test_up_down },
327+ {"history" , test_history },
328+ {"history_keys" , test_history_keys },
329+ {"search" , test_search },
330+ {"up_down" , test_up_down },
314331#endif
315- {"multiple" , test_multiple },
316- {"echo" , test_echo },
317- {"quotes" , test_quotes },
318- {"too_many_args" , test_too_many_args },
319- {"max_chars" , test_max_chars },
320- { NULL , NULL },
321- };
332+ {"multiple" , test_multiple },
333+ {"echo" , test_echo },
334+ {"quotes" , test_quotes },
335+ {"too_many_args" , test_too_many_args },
336+ {"max_chars" , test_max_chars },
337+ { "utf8" , test_utf8 },
338+ { NULL , NULL } };
0 commit comments