about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKevin Cantu <me@kevincantu.org>2012-02-13 03:07:29 -0800
committerKevin Cantu <me@kevincantu.org>2012-02-13 03:07:29 -0800
commit69834646d2efd2170236b1f8db3a71c77e378c5b (patch)
treed036e7bb13498e9d720eab2a48fc5c99749b25a8
parent2600db4778dac418309320bed235a1025d84c630 (diff)
downloadrust-69834646d2efd2170236b1f8db3a71c77e378c5b.tar.gz
rust-69834646d2efd2170236b1f8db3a71c77e378c5b.zip
(core::str) more test cases
-rw-r--r--src/libcore/str.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/libcore/str.rs b/src/libcore/str.rs
index 472cbc13fb6..4e49a51465e 100644
--- a/src/libcore/str.rs
+++ b/src/libcore/str.rs
@@ -920,7 +920,7 @@ fn find(haystack: str, needle: str) -> option<uint> {
 // Convert a byte position into a char position
 // within a given string
 fn b2c_pos(ss: str, bpos: uint) -> uint {
-   assert bpos < len_bytes(ss);
+   assert bpos == 0u || bpos < len_bytes(ss);
 
    let ii = 0u;
    let cpos = 0u;
@@ -1725,6 +1725,9 @@ mod tests {
     #[test]
     fn test_find_bytes() {
         // byte positions
+        assert (find_bytes("banana", "apple pie") == option::none);
+        assert (find_bytes("", "") == option::some(0u));
+
         let data = "ประเทศไทย中华Việt Nam";
         assert (find_bytes(data, "")     == option::some(0u));
         assert (find_bytes(data, "ประเ") == option::some( 0u));
@@ -1736,6 +1739,9 @@ mod tests {
     #[test]
     fn test_find() {
         // char positions
+        assert (find("banana", "apple pie") == option::none);
+        assert (find("", "") == option::some(0u));
+
         let data = "ประเทศไทย中华Việt Nam";
         assert (find(data, "")     == option::some(0u));
         assert (find(data, "ประเ") == option::some(0u));