Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion src/libstd/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint,~str> for ~str {
fn mul(&self,repeat: &uint) -> ~str{
self.repeat(*repeat)
}
}
impl Mul<uint,@str> for @str {
fn mul(&self,repeat: &uint) -> @str{
self.repeat(*repeat).to_managed()
}
}
impl<'self> Mul<uint,~str> for &'self str {
fn mul(&self,repeat: &uint) -> ~str{
self.repeat(*repeat)
}
}

impl<'self> Add<&'self str,~str> for &'self str {
#[inline]
Expand Down Expand Up @@ -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(&~"", &~"")));
Expand Down