From 13bf60d9f0eaac57f05a1522f70123ad23f0061c Mon Sep 17 00:00:00 2001 From: fennecdjay Date: Thu, 5 Nov 2020 19:49:07 +0100 Subject: [PATCH] :white_check_mark: test string find --- src/lib/string.c | 20 ++++---------------- tests/string/find.gw | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 tests/string/find.gw diff --git a/src/lib/string.c b/src/lib/string.c index b87a31d2..a99fbfef 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -302,10 +302,6 @@ static MFUN(string_findStr) { strcpy(str, STRING(o)); m_int ret = -1; const M_Object obj = *(M_Object*)MEM(SZ_INT); - if(!obj) { - *(m_uint*)RETURN = 0; - return; - } const m_str arg = STRING(obj); const m_int len = strlen(str); m_int i = 0; @@ -331,10 +327,6 @@ static MFUN(string_findStrStart) { m_int ret = -1; const m_int start = *(m_int*)MEM(SZ_INT); const M_Object obj = *(M_Object*)MEM(SZ_INT * 2); - if(!obj) { - *(M_Object*)RETURN = NULL; - return; - } const m_str arg = STRING(obj); const m_int len = strlen(str); m_int i = start; @@ -418,10 +410,6 @@ static MFUN(string_rfindStrStart) { m_int ret = -1; m_int start = *(m_int*)MEM(SZ_INT); const M_Object obj = *(M_Object*)MEM(SZ_INT * 2); - if(!obj) { - *(m_uint*)RETURN = 0; - return; - } m_str arg = STRING(obj); m_int i = start; @@ -518,12 +506,12 @@ GWION_IMPORT(string) { GWI_BB(gwi_func_end(gwi, string_findStart, ae_flag_none)) gwi_func_ini(gwi, "int", "find"); - gwi_func_arg(gwi, "string", "str"); + gwi_func_arg(gwi, "nonnull string", "str"); GWI_BB(gwi_func_end(gwi, string_findStr, ae_flag_none)) gwi_func_ini(gwi, "int", "find"); gwi_func_arg(gwi, "int", "pos"); - gwi_func_arg(gwi, "string", "str"); + gwi_func_arg(gwi, "nonnull string", "str"); GWI_BB(gwi_func_end(gwi, string_findStrStart, ae_flag_none)) gwi_func_ini(gwi, "int", "rfind"); @@ -536,12 +524,12 @@ GWION_IMPORT(string) { GWI_BB(gwi_func_end(gwi, string_rfindStart, ae_flag_none)) gwi_func_ini(gwi, "int", "rfind"); - gwi_func_arg(gwi, "string", "str"); + gwi_func_arg(gwi, "nonnull string", "str"); GWI_BB(gwi_func_end(gwi, string_rfindStr, ae_flag_none)) gwi_func_ini(gwi, "int", "rfind"); gwi_func_arg(gwi, "int", "pos"); - gwi_func_arg(gwi, "string", "str"); + gwi_func_arg(gwi, "nonnull string", "str"); GWI_BB(gwi_func_end(gwi, string_rfindStrStart, ae_flag_none)) gwi_func_ini(gwi, "void", "erase"); diff --git a/tests/string/find.gw b/tests/string/find.gw new file mode 100644 index 00000000..6c42ccad --- /dev/null +++ b/tests/string/find.gw @@ -0,0 +1,26 @@ +<<< "test".find('e') >>>; +<<< "test".find('a') >>>; +<<< "".find('a') >>>; + +<<< "test".find(-1, 'e') >>>; +<<< "test".find(0, 'e') >>>; +<<< "test".find(1, 'a') >>>; +<<< "".find(1, 'a') >>>; + +<<< "test".find("es") >>>; +<<< "test".find("a") >>>; +<<< "".find("") >>>; + +<<< "test".find(-1, "es") >>>; +<<< "test".find(0, "es") >>>; +<<< "test".find(1, "a") >>>; +<<< "".find(1, "") >>>; + +<<< "test".rfind("es") >>>; +<<< "test".rfind("a") >>>; +<<< "".rfind("") >>>; + +<<< "test".rfind(-1, "es") >>>; +<<< "test".rfind(0, "e") >>>; +<<< "test".rfind(1, "a") >>>; +<<< "".rfind(1, "") >>>; -- 2.43.0