Skip to content

Commit 6983464

Browse files
committed
(core::str) more test cases
1 parent 2600db4 commit 6983464

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/libcore/str.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ fn find(haystack: str, needle: str) -> option<uint> {
920920
// Convert a byte position into a char position
921921
// within a given string
922922
fn b2c_pos(ss: str, bpos: uint) -> uint {
923-
assert bpos < len_bytes(ss);
923+
assert bpos == 0u || bpos < len_bytes(ss);
924924

925925
let ii = 0u;
926926
let cpos = 0u;
@@ -1725,6 +1725,9 @@ mod tests {
17251725
#[test]
17261726
fn test_find_bytes() {
17271727
// byte positions
1728+
assert (find_bytes("banana", "apple pie") == option::none);
1729+
assert (find_bytes("", "") == option::some(0u));
1730+
17281731
let data = "ประเทศไทย中华Việt Nam";
17291732
assert (find_bytes(data, "") == option::some(0u));
17301733
assert (find_bytes(data, "ประเ") == option::some( 0u));
@@ -1736,6 +1739,9 @@ mod tests {
17361739
#[test]
17371740
fn test_find() {
17381741
// char positions
1742+
assert (find("banana", "apple pie") == option::none);
1743+
assert (find("", "") == option::some(0u));
1744+
17391745
let data = "ประเทศไทย中华Việt Nam";
17401746
assert (find(data, "") == option::some(0u));
17411747
assert (find(data, "ประเ") == option::some(0u));

0 commit comments

Comments
 (0)