diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 0811dab407ef5..432dd87fa5fce 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -1037,11 +1037,28 @@ pub mod raw { } + #[cfg(not(test))] pub mod traits { - use ops::Add; + use ops::{Add,Mul}; use cmp::{TotalOrd, Ordering, Less, Equal, Greater, Eq, Ord, Equiv, TotalEq}; use super::{Str, eq_slice}; + + impl Mul for ~str { + fn mul(&self,repeat: &uint) -> ~str{ + self.repeat(*repeat) + } + } + impl Mul for @str { + fn mul(&self,repeat: &uint) -> @str{ + self.repeat(*repeat).to_managed() + } + } + impl<'self> Mul for &'self str { + fn mul(&self,repeat: &uint) -> ~str{ + self.repeat(*repeat) + } + } impl<'self> Add<&'self str,~str> for &'self str { #[inline] @@ -2362,6 +2379,20 @@ mod tests { use vec::{ImmutableVector, CopyableVector}; use cmp::{TotalOrd, Less, Equal, Greater}; + #[test] + fn test_repeat_string() { + assert_eq!(@"foo" * 1 , @"foo"); + assert_eq!(@"foo" * 0 , @""); + assert_eq!(@"foo" * 2 , @"foofoo"); + + assert_eq!(~"foo" * 1,~"foo"); + assert_eq!(~"foo" * 0, ~""); + assert_eq!(~"foo" * 2, ~"foofoo"); + + assert_eq!("foo" * 1, ~"foo"); + assert_eq!("foo" * 0, ~""); + assert_eq!("foo" * 2, ~"foofoo"); + } #[test] fn test_eq() { assert!((eq(&~"", &~"")));