diff --git a/c_runtime/bosatsu_ext_Bosatsu_l_Predef.c b/c_runtime/bosatsu_ext_Bosatsu_l_Predef.c index 553099634..12c414497 100644 --- a/c_runtime/bosatsu_ext_Bosatsu_l_Predef.c +++ b/c_runtime/bosatsu_ext_Bosatsu_l_Predef.c @@ -182,7 +182,7 @@ BValue ___bsts_g_Bosatsu_l_Predef_l_partition__String(BValue a, BValue b) { // Some((x, y)) with x = a[0:offset], y = a[offset + b.len():] BValue x = bsts_string_substring(a, 0, offset); BValue y = bsts_string_substring_tail(a, offset + blen); - res = alloc_enum2(1, x, y); + res = alloc_enum1(1, alloc_struct2(x, y)); done: release_value(a); @@ -209,7 +209,7 @@ BValue ___bsts_g_Bosatsu_l_Predef_l_rpartition__String(BValue a, BValue b) { // Some((x, y)) with x = a[0:offset], y = a[offset + b.len():] BValue x = bsts_string_substring(a, 0, offset); BValue y = bsts_string_substring_tail(a, offset + blen); - res = alloc_enum2(1, x, y); + res = alloc_enum1(1, alloc_struct2(x, y)); done: release_value(a); diff --git a/c_runtime/bosatsu_runtime.c b/c_runtime/bosatsu_runtime.c index b2f638b5a..78cb50461 100644 --- a/c_runtime/bosatsu_runtime.c +++ b/c_runtime/bosatsu_runtime.c @@ -578,7 +578,7 @@ int bsts_string_rfind(BValue haystack, BValue needle, int start) { // The maximum valid start index is haystack_len - needle_len - for (size_t i = (size_t)start; i <= 0; i--) { + for (size_t i = (size_t)start; 0 <= i; i--) { if (haystack_str->bytes[i] == needle_str->bytes[0]) { // Potential match found, check the rest of the needle size_t j; diff --git a/test_workspace/Char.bosatsu b/test_workspace/Char.bosatsu index 6a05d05ce..cb8fe407c 100644 --- a/test_workspace/Char.bosatsu +++ b/test_workspace/Char.bosatsu @@ -47,6 +47,15 @@ last_tests = TestSuite( ] ) +partition_tests = TestSuite("partition tests", [ + Assertion("foo".partition_String("f") matches Some(("", "oo")), "foo partition_String f"), + Assertion("foo".partition_String("") matches None, "foo partition_String \"\""), + Assertion("foo".partition_String("x") matches None, "foo partition_String x"), + Assertion("foo".rpartition_String("o") matches Some(("fo", "")), "foo rpartition_String o"), + Assertion("foo".rpartition_String("") matches None, "foo rpartition_String \"\""), + Assertion("foo".rpartition_String("x") matches None, "foo rpartition_String x"), +]) + match_tests = TestSuite("match tests", [ Assertion("👋👋👋" matches "👋$.{_}👋", "test matching 1"), @@ -84,5 +93,6 @@ tests = TestSuite("Char tests", last_tests, match_tests, glob_match_tests, + partition_tests, ] ) \ No newline at end of file