Skip to content

Commit

Permalink
auto merge of #14170 : pcwalton/rust/detildestr-misclibs, r=alexcrichton
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed May 15, 2014
2 parents 2a7a391 + 351a564 commit e10fd31
Show file tree
Hide file tree
Showing 223 changed files with 1,996 additions and 1,785 deletions.
12 changes: 9 additions & 3 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ pub fn parse_config(args: Vec<~str> ) -> Config {
"(none)" != opt_str2(matches.opt_str("adb-test-dir")) &&
!opt_str2(matches.opt_str("adb-test-dir")).is_empty(),
lldb_python_dir: matches.opt_str("lldb-python-dir"),
test_shard: test::opt_shard(matches.opt_str("test-shard")),
test_shard: test::opt_shard(matches.opt_str("test-shard")
.map(|x| x.to_strbuf())),
verbose: matches.opt_present("verbose")
}
}
Expand Down Expand Up @@ -235,7 +236,10 @@ pub fn run_tests(config: &Config) {

pub fn test_opts(config: &Config) -> test::TestOpts {
test::TestOpts {
filter: config.filter.clone(),
filter: match config.filter {
None => None,
Some(ref filter) => Some(filter.to_strbuf()),
},
run_ignored: config.run_ignored,
logfile: config.logfile.clone(),
run_tests: true,
Expand Down Expand Up @@ -314,7 +318,9 @@ pub fn make_test_name(config: &Config, testfile: &Path) -> test::TestName {
format!("{}/{}", dir.unwrap_or(""), filename.unwrap_or(""))
}

test::DynTestName(format!("[{}] {}", config.mode, shorten(testfile)))
test::DynTestName(format_strbuf!("[{}] {}",
config.mode,
shorten(testfile)))
}

pub fn make_test_closure(config: &Config, testfile: &Path) -> test::TestFn {
Expand Down
10 changes: 5 additions & 5 deletions src/libarena/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ mod tests {
}

struct Noncopy {
string: ~str,
string: StrBuf,
array: Vec<int> ,
}

Expand All @@ -539,7 +539,7 @@ mod tests {
let arena = TypedArena::new();
for _ in range(0, 100000) {
arena.alloc(Noncopy {
string: "hello world".to_owned(),
string: "hello world".to_strbuf(),
array: vec!( 1, 2, 3, 4, 5 ),
});
}
Expand All @@ -550,7 +550,7 @@ mod tests {
let arena = TypedArena::new();
b.iter(|| {
arena.alloc(Noncopy {
string: "hello world".to_owned(),
string: "hello world".to_strbuf(),
array: vec!( 1, 2, 3, 4, 5 ),
})
})
Expand All @@ -560,7 +560,7 @@ mod tests {
pub fn bench_noncopy_nonarena(b: &mut Bencher) {
b.iter(|| {
box Noncopy {
string: "hello world".to_owned(),
string: "hello world".to_strbuf(),
array: vec!( 1, 2, 3, 4, 5 ),
}
})
Expand All @@ -571,7 +571,7 @@ mod tests {
let arena = Arena::new();
b.iter(|| {
arena.alloc(|| Noncopy {
string: "hello world".to_owned(),
string: "hello world".to_strbuf(),
array: vec!( 1, 2, 3, 4, 5 ),
})
})
Expand Down
24 changes: 12 additions & 12 deletions src/libcollections/lru_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,23 +270,23 @@ mod tests {

#[test]
fn test_put_update() {
let mut cache: LruCache<~str, Vec<u8>> = LruCache::new(1);
cache.put("1".to_owned(), vec![10, 10]);
cache.put("1".to_owned(), vec![10, 19]);
assert_opt_eq(cache.get(&"1".to_owned()), vec![10, 19]);
let mut cache: LruCache<StrBuf, Vec<u8>> = LruCache::new(1);
cache.put("1".to_strbuf(), vec![10, 10]);
cache.put("1".to_strbuf(), vec![10, 19]);
assert_opt_eq(cache.get(&"1".to_strbuf()), vec![10, 19]);
assert_eq!(cache.len(), 1);
}

#[test]
fn test_expire_lru() {
let mut cache: LruCache<~str, ~str> = LruCache::new(2);
cache.put("foo1".to_owned(), "bar1".to_owned());
cache.put("foo2".to_owned(), "bar2".to_owned());
cache.put("foo3".to_owned(), "bar3".to_owned());
assert!(cache.get(&"foo1".to_owned()).is_none());
cache.put("foo2".to_owned(), "bar2update".to_owned());
cache.put("foo4".to_owned(), "bar4".to_owned());
assert!(cache.get(&"foo3".to_owned()).is_none());
let mut cache: LruCache<StrBuf, StrBuf> = LruCache::new(2);
cache.put("foo1".to_strbuf(), "bar1".to_strbuf());
cache.put("foo2".to_strbuf(), "bar2".to_strbuf());
cache.put("foo3".to_strbuf(), "bar3".to_strbuf());
assert!(cache.get(&"foo1".to_strbuf()).is_none());
cache.put("foo2".to_strbuf(), "bar2update".to_strbuf());
cache.put("foo4".to_strbuf(), "bar4".to_strbuf());
assert!(cache.get(&"foo3".to_strbuf()).is_none());
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions src/libglob/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ impl Pattern {
* brackets. The resulting string will, when compiled into a `Pattern`,
* match the input string and nothing else.
*/
pub fn escape(s: &str) -> ~str {
pub fn escape(s: &str) -> StrBuf {
let mut escaped = StrBuf::new();
for c in s.chars() {
match c {
Expand All @@ -325,7 +325,7 @@ impl Pattern {
}
}
}
escaped.into_owned()
escaped
}

/**
Expand Down Expand Up @@ -767,8 +767,8 @@ mod test {
#[test]
fn test_pattern_escape() {
let s = "_[_]_?_*_!_";
assert_eq!(Pattern::escape(s), "_[[]_[]]_[?]_[*]_!_".to_owned());
assert!(Pattern::new(Pattern::escape(s)).matches(s));
assert_eq!(Pattern::escape(s), "_[[]_[]]_[?]_[*]_!_".to_strbuf());
assert!(Pattern::new(Pattern::escape(s).as_slice()).matches(s));
}

#[test]
Expand Down
13 changes: 8 additions & 5 deletions src/libgraphviz/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,10 @@ impl<'a> LabelText<'a> {
}

/// Renders text as string suitable for a label in a .dot file.
pub fn escape(&self) -> ~str {
pub fn escape(&self) -> StrBuf {
match self {
&LabelStr(ref s) => s.as_slice().escape_default(),
&EscStr(ref s) => LabelText::escape_str(s.as_slice()).into_owned(),
&LabelStr(ref s) => s.as_slice().escape_default().to_strbuf(),
&EscStr(ref s) => LabelText::escape_str(s.as_slice()).to_strbuf(),
}
}
}
Expand Down Expand Up @@ -661,11 +661,14 @@ mod tests {
}
}

fn test_input(g: LabelledGraph) -> IoResult<~str> {
fn test_input(g: LabelledGraph) -> IoResult<StrBuf> {
let mut writer = MemWriter::new();
render(&g, &mut writer).unwrap();
let mut r = BufReader::new(writer.get_ref());
r.read_to_str()
match r.read_to_str() {
Ok(string) => Ok(string.to_strbuf()),
Err(err) => Err(err),
}
}

// All of the tests use raw-strings as the format for the expected outputs,
Expand Down
25 changes: 17 additions & 8 deletions src/libhexfloat/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,39 @@ pub fn macro_registrar(register: |Name, SyntaxExtension|) {

//Check if the literal is valid (as LLVM expects),
//and return a descriptive error if not.
fn hex_float_lit_err(s: &str) -> Option<(uint, ~str)> {
fn hex_float_lit_err(s: &str) -> Option<(uint, StrBuf)> {
let mut chars = s.chars().peekable();
let mut i = 0;
if chars.peek() == Some(&'-') { chars.next(); i+= 1 }
if chars.next() != Some('0') { return Some((i, "Expected '0'".to_owned())); } i+=1;
if chars.next() != Some('x') { return Some((i, "Expected 'x'".to_owned())); } i+=1;
if chars.next() != Some('0') {
return Some((i, "Expected '0'".to_strbuf()));
} i+=1;
if chars.next() != Some('x') {
return Some((i, "Expected 'x'".to_strbuf()));
} i+=1;
let mut d_len = 0;
for _ in chars.take_while(|c| c.is_digit_radix(16)) { chars.next(); i+=1; d_len += 1;}
if chars.next() != Some('.') { return Some((i, "Expected '.'".to_owned())); } i+=1;
if chars.next() != Some('.') {
return Some((i, "Expected '.'".to_strbuf()));
} i+=1;
let mut f_len = 0;
for _ in chars.take_while(|c| c.is_digit_radix(16)) { chars.next(); i+=1; f_len += 1;}
if d_len == 0 && f_len == 0 {
return Some((i, "Expected digits before or after decimal point".to_owned()));
return Some((i, "Expected digits before or after decimal \
point".to_strbuf()));
}
if chars.next() != Some('p') { return Some((i, "Expected 'p'".to_owned())); } i+=1;
if chars.next() != Some('p') {
return Some((i, "Expected 'p'".to_strbuf()));
} i+=1;
if chars.peek() == Some(&'-') { chars.next(); i+= 1 }
let mut e_len = 0;
for _ in chars.take_while(|c| c.is_digit()) { chars.next(); i+=1; e_len += 1}
if e_len == 0 {
return Some((i, "Expected exponent digits".to_owned()));
return Some((i, "Expected exponent digits".to_strbuf()));
}
match chars.next() {
None => None,
Some(_) => Some((i, "Expected end of string".to_owned()))
Some(_) => Some((i, "Expected end of string".to_strbuf()))
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/liblog/directive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::cmp;

#[deriving(Show, Clone)]
pub struct LogDirective {
pub name: Option<~str>,
pub name: Option<StrBuf>,
pub level: u32,
}

Expand Down Expand Up @@ -64,7 +64,7 @@ pub fn parse_logging_spec(spec: &str) -> Vec<LogDirective> {
}
};
dirs.push(LogDirective {
name: name.map(|s| s.to_owned()),
name: name.map(|s| s.to_strbuf()),
level: log_level,
});
}
Expand All @@ -80,13 +80,13 @@ mod tests {
let dirs = parse_logging_spec("crate1::mod1=1,crate1::mod2,crate2=4");
let dirs = dirs.as_slice();
assert_eq!(dirs.len(), 3);
assert_eq!(dirs[0].name, Some("crate1::mod1".to_owned()));
assert_eq!(dirs[0].name, Some("crate1::mod1".to_strbuf()));
assert_eq!(dirs[0].level, 1);

assert_eq!(dirs[1].name, Some("crate1::mod2".to_owned()));
assert_eq!(dirs[1].name, Some("crate1::mod2".to_strbuf()));
assert_eq!(dirs[1].level, ::MAX_LOG_LEVEL);

assert_eq!(dirs[2].name, Some("crate2".to_owned()));
assert_eq!(dirs[2].name, Some("crate2".to_strbuf()));
assert_eq!(dirs[2].level, 4);
}

Expand All @@ -96,7 +96,7 @@ mod tests {
let dirs = parse_logging_spec("crate1::mod1=1=2,crate2=4");
let dirs = dirs.as_slice();
assert_eq!(dirs.len(), 1);
assert_eq!(dirs[0].name, Some("crate2".to_owned()));
assert_eq!(dirs[0].name, Some("crate2".to_strbuf()));
assert_eq!(dirs[0].level, 4);
}

Expand All @@ -106,7 +106,7 @@ mod tests {
let dirs = parse_logging_spec("crate1::mod1=noNumber,crate2=4");
let dirs = dirs.as_slice();
assert_eq!(dirs.len(), 1);
assert_eq!(dirs[0].name, Some("crate2".to_owned()));
assert_eq!(dirs[0].name, Some("crate2".to_strbuf()));
assert_eq!(dirs[0].level, 4);
}

Expand All @@ -116,7 +116,7 @@ mod tests {
let dirs = parse_logging_spec("crate1::mod1=wrong,crate2=warn");
let dirs = dirs.as_slice();
assert_eq!(dirs.len(), 1);
assert_eq!(dirs[0].name, Some("crate2".to_owned()));
assert_eq!(dirs[0].name, Some("crate2".to_strbuf()));
assert_eq!(dirs[0].level, ::WARN);
}

Expand All @@ -128,7 +128,7 @@ mod tests {
assert_eq!(dirs.len(), 2);
assert_eq!(dirs[0].name, None);
assert_eq!(dirs[0].level, 2);
assert_eq!(dirs[1].name, Some("crate2".to_owned()));
assert_eq!(dirs[1].name, Some("crate2".to_strbuf()));
assert_eq!(dirs[1].level, 4);
}
}
46 changes: 32 additions & 14 deletions src/liblog/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ fn enabled(level: u32, module: &str,
// Search for the longest match, the vector is assumed to be pre-sorted.
for directive in iter.rev() {
match directive.name {
Some(ref name) if !module.starts_with(*name) => {},
Some(ref name) if !module.starts_with(name.as_slice()) => {},
Some(..) | None => {
return level <= directive.level
}
Expand Down Expand Up @@ -362,8 +362,16 @@ mod tests {

#[test]
fn match_full_path() {
let dirs = [LogDirective { name: Some("crate2".to_owned()), level: 3 },
LogDirective { name: Some("crate1::mod1".to_owned()), level: 2 }];
let dirs = [
LogDirective {
name: Some("crate2".to_strbuf()),
level: 3
},
LogDirective {
name: Some("crate1::mod1".to_strbuf()),
level: 2
}
];
assert!(enabled(2, "crate1::mod1", dirs.iter()));
assert!(!enabled(3, "crate1::mod1", dirs.iter()));
assert!(enabled(3, "crate2", dirs.iter()));
Expand All @@ -372,39 +380,49 @@ mod tests {

#[test]
fn no_match() {
let dirs = [LogDirective { name: Some("crate2".to_owned()), level: 3 },
LogDirective { name: Some("crate1::mod1".to_owned()), level: 2 }];
let dirs = [
LogDirective { name: Some("crate2".to_strbuf()), level: 3 },
LogDirective { name: Some("crate1::mod1".to_strbuf()), level: 2 }
];
assert!(!enabled(2, "crate3", dirs.iter()));
}

#[test]
fn match_beginning() {
let dirs = [LogDirective { name: Some("crate2".to_owned()), level: 3 },
LogDirective { name: Some("crate1::mod1".to_owned()), level: 2 }];
let dirs = [
LogDirective { name: Some("crate2".to_strbuf()), level: 3 },
LogDirective { name: Some("crate1::mod1".to_strbuf()), level: 2 }
];
assert!(enabled(3, "crate2::mod1", dirs.iter()));
}

#[test]
fn match_beginning_longest_match() {
let dirs = [LogDirective { name: Some("crate2".to_owned()), level: 3 },
LogDirective { name: Some("crate2::mod".to_owned()), level: 4 },
LogDirective { name: Some("crate1::mod1".to_owned()), level: 2 }];
let dirs = [
LogDirective { name: Some("crate2".to_strbuf()), level: 3 },
LogDirective { name: Some("crate2::mod".to_strbuf()), level: 4 },
LogDirective { name: Some("crate1::mod1".to_strbuf()), level: 2 }
];
assert!(enabled(4, "crate2::mod1", dirs.iter()));
assert!(!enabled(4, "crate2", dirs.iter()));
}

#[test]
fn match_default() {
let dirs = [LogDirective { name: None, level: 3 },
LogDirective { name: Some("crate1::mod1".to_owned()), level: 2 }];
let dirs = [
LogDirective { name: None, level: 3 },
LogDirective { name: Some("crate1::mod1".to_strbuf()), level: 2 }
];
assert!(enabled(2, "crate1::mod1", dirs.iter()));
assert!(enabled(3, "crate2::mod2", dirs.iter()));
}

#[test]
fn zero_level() {
let dirs = [LogDirective { name: None, level: 3 },
LogDirective { name: Some("crate1::mod1".to_owned()), level: 0 }];
let dirs = [
LogDirective { name: None, level: 3 },
LogDirective { name: Some("crate1::mod1".to_strbuf()), level: 0 }
];
assert!(!enabled(1, "crate1::mod1", dirs.iter()));
assert!(enabled(3, "crate2::mod2", dirs.iter()));
}
Expand Down
Loading

0 comments on commit e10fd31

Please sign in to comment.