From 4a0586b1a5599acfd66666cf8d0e83131e09593f Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Mon, 3 Apr 2017 16:55:47 -0400 Subject: [PATCH] Put str tests in a nested tests module --- src/lexer/str.rs | 65 ++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/src/lexer/str.rs b/src/lexer/str.rs index 7a7a239..76ed1a9 100644 --- a/src/lexer/str.rs +++ b/src/lexer/str.rs @@ -62,37 +62,42 @@ impl CharAt for str { } } -#[test] -fn index_before_is_well_behaved_for_ascii() { - let s = "abc"; +#[cfg(test)] +mod tests { + use super::*; - // Sanity - assert_eq!(s.index_before(0), 0); - assert_eq!(s.index_before(2), 1); + #[test] + fn index_before_is_well_behaved_for_ascii() { + let s = "abc"; - // An index beyond the string bounds returns the index of the last character in the string. - { - let idx = s.index_before(4); - assert_eq!(idx, 2); - assert!(s.is_char_boundary(idx)); - let last_char = &s[idx ..]; - assert_eq!(last_char.len(), 1); - assert_eq!(last_char.chars().nth(0), Some('c')); - } -} - -#[test] -fn index_after_is_well_behaved_for_ascii() { - let s = "abc"; - - // Sanity - assert_eq!(s.index_after(0), 1); - assert_eq!(s.index_after(2), 3); - - // 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)); + // Sanity + assert_eq!(s.index_before(0), 0); + assert_eq!(s.index_before(2), 1); + + // An index beyond the string bounds returns the index of the last character in the string. + { + let idx = s.index_before(4); + assert_eq!(idx, 2); + assert!(s.is_char_boundary(idx)); + let last_char = &s[idx ..]; + assert_eq!(last_char.len(), 1); + assert_eq!(last_char.chars().nth(0), Some('c')); + } + } + + #[test] + fn index_after_is_well_behaved_for_ascii() { + let s = "abc"; + + // Sanity + assert_eq!(s.index_after(0), 1); + assert_eq!(s.index_after(2), 3); + + // 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)); + } } }