Put str tests in a nested tests module
This commit is contained in:
parent
104b9b0864
commit
4a0586b1a5
1 changed files with 35 additions and 30 deletions
|
@ -62,37 +62,42 @@ impl CharAt for str {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[cfg(test)]
|
||||||
fn index_before_is_well_behaved_for_ascii() {
|
mod tests {
|
||||||
let s = "abc";
|
use super::*;
|
||||||
|
|
||||||
// Sanity
|
#[test]
|
||||||
assert_eq!(s.index_before(0), 0);
|
fn index_before_is_well_behaved_for_ascii() {
|
||||||
assert_eq!(s.index_before(2), 1);
|
let s = "abc";
|
||||||
|
|
||||||
// An index beyond the string bounds returns the index of the last character in the string.
|
// Sanity
|
||||||
{
|
assert_eq!(s.index_before(0), 0);
|
||||||
let idx = s.index_before(4);
|
assert_eq!(s.index_before(2), 1);
|
||||||
assert_eq!(idx, 2);
|
|
||||||
assert!(s.is_char_boundary(idx));
|
// An index beyond the string bounds returns the index of the last character in the string.
|
||||||
let last_char = &s[idx ..];
|
{
|
||||||
assert_eq!(last_char.len(), 1);
|
let idx = s.index_before(4);
|
||||||
assert_eq!(last_char.chars().nth(0), Some('c'));
|
assert_eq!(idx, 2);
|
||||||
}
|
assert!(s.is_char_boundary(idx));
|
||||||
}
|
let last_char = &s[idx ..];
|
||||||
|
assert_eq!(last_char.len(), 1);
|
||||||
#[test]
|
assert_eq!(last_char.chars().nth(0), Some('c'));
|
||||||
fn index_after_is_well_behaved_for_ascii() {
|
}
|
||||||
let s = "abc";
|
}
|
||||||
|
|
||||||
// Sanity
|
#[test]
|
||||||
assert_eq!(s.index_after(0), 1);
|
fn index_after_is_well_behaved_for_ascii() {
|
||||||
assert_eq!(s.index_after(2), 3);
|
let s = "abc";
|
||||||
|
|
||||||
// An index beyond the string bounds returns the length of the string
|
// Sanity
|
||||||
{
|
assert_eq!(s.index_after(0), 1);
|
||||||
let idx = s.index_after(4);
|
assert_eq!(s.index_after(2), 3);
|
||||||
assert_eq!(idx, s.len());
|
|
||||||
assert!(s.is_char_boundary(idx));
|
// An index beyond the string bounds returns the length of the string
|
||||||
|
{
|
||||||
|
let idx = s.index_after(4);
|
||||||
|
assert_eq!(idx, s.len());
|
||||||
|
assert!(s.is_char_boundary(idx));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue