1
Fork 0

cleanup warnings from libextra

This commit is contained in:
Erick Tryzelaar 2013-05-23 09:39:00 -07:00
parent dc970c13f4
commit 609a9e69e1
20 changed files with 460 additions and 474 deletions

View file

@ -12,10 +12,6 @@
use core::prelude::*; use core::prelude::*;
use core::old_iter;
use core::str;
use core::vec;
pub trait ToBase64 { pub trait ToBase64 {
fn to_base64(&self) -> ~str; fn to_base64(&self) -> ~str;
} }
@ -242,12 +238,12 @@ mod tests {
#[test] #[test]
fn test_from_base64() { fn test_from_base64() {
assert_eq!((~"").from_base64(), str::to_bytes(~"")); assert_eq!((~"").from_base64(), str::to_bytes(""));
assert!((~"Zg==").from_base64() == str::to_bytes(~"f")); assert!((~"Zg==").from_base64() == str::to_bytes("f"));
assert_eq!((~"Zm8=").from_base64(), str::to_bytes(~"fo")); assert_eq!((~"Zm8=").from_base64(), str::to_bytes("fo"));
assert_eq!((~"Zm9v").from_base64(), str::to_bytes(~"foo")); assert_eq!((~"Zm9v").from_base64(), str::to_bytes("foo"));
assert!((~"Zm9vYg==").from_base64() == str::to_bytes(~"foob")); assert!((~"Zm9vYg==").from_base64() == str::to_bytes("foob"));
assert_eq!((~"Zm9vYmE=").from_base64(), str::to_bytes(~"fooba")) assert_eq!((~"Zm9vYmE=").from_base64(), str::to_bytes("fooba"))
assert_eq!((~"Zm9vYmFy").from_base64(), str::to_bytes(~"foobar")); assert_eq!((~"Zm9vYmFy").from_base64(), str::to_bytes("foobar"));
} }
} }

View file

@ -10,8 +10,6 @@
use core::prelude::*; use core::prelude::*;
use core::vec::from_elem;
struct SmallBitv { struct SmallBitv {
/// only the lowest nbits of this value are used. the rest is undefined. /// only the lowest nbits of this value are used. the rest is undefined.
bits: uint bits: uint
@ -257,7 +255,7 @@ pub impl Bitv {
let nelems = nbits/uint::bits + let nelems = nbits/uint::bits +
if nbits % uint::bits == 0 {0} else {1}; if nbits % uint::bits == 0 {0} else {1};
let elem = if init {!0} else {0}; let elem = if init {!0} else {0};
let s = from_elem(nelems, elem); let s = vec::from_elem(nelems, elem);
Big(~BigBitv::new(s)) Big(~BigBitv::new(s))
}; };
Bitv {rep: rep, nbits: nbits} Bitv {rep: rep, nbits: nbits}
@ -502,7 +500,7 @@ impl Clone for Bitv {
Bitv{nbits: self.nbits, rep: Small(~SmallBitv{bits: b.bits})} Bitv{nbits: self.nbits, rep: Small(~SmallBitv{bits: b.bits})}
} }
Big(ref b) => { Big(ref b) => {
let mut st = from_elem(self.nbits / uint::bits + 1, 0); let mut st = vec::from_elem(self.nbits / uint::bits + 1, 0);
let len = st.len(); let len = st.len();
for uint::range(0, len) |i| { st[i] = b.storage[i]; }; for uint::range(0, len) |i| { st[i] = b.storage[i]; };
Bitv{nbits: self.nbits, rep: Big(~BigBitv{storage: st})} Bitv{nbits: self.nbits, rep: Big(~BigBitv{storage: st})}
@ -872,17 +870,14 @@ mod tests {
#[test] #[test]
fn test_0_elements() { fn test_0_elements() {
let mut act; let act = Bitv::new(0u, false);
let exp; let exp = vec::from_elem::<uint>(0u, 0u);
act = Bitv::new(0u, false);
exp = vec::from_elem::<uint>(0u, 0u);
assert!(act.eq_vec(exp)); assert!(act.eq_vec(exp));
} }
#[test] #[test]
fn test_1_element() { fn test_1_element() {
let mut act; let mut act = Bitv::new(1u, false);
act = Bitv::new(1u, false);
assert!(act.eq_vec(~[0u])); assert!(act.eq_vec(~[0u]));
act = Bitv::new(1u, true); act = Bitv::new(1u, true);
assert!(act.eq_vec(~[1u])); assert!(act.eq_vec(~[1u]));
@ -1488,7 +1483,7 @@ mod tests {
#[bench] #[bench]
fn bench_bitv_big_union(b: &mut BenchHarness) { fn bench_bitv_big_union(b: &mut BenchHarness) {
let mut b1 = Bitv::new(bench_bits, false); let mut b1 = Bitv::new(bench_bits, false);
let mut b2 = Bitv::new(bench_bits, false); let b2 = Bitv::new(bench_bits, false);
do b.iter { do b.iter {
b1.union(&b2); b1.union(&b2);
} }

View file

@ -540,13 +540,13 @@ mod tests {
#[test] #[test]
fn test_dlist_concat() { fn test_dlist_concat() {
let a = from_vec(~[1,2]); let a = from_vec([1,2]);
let b = from_vec(~[3,4]); let b = from_vec([3,4]);
let c = from_vec(~[5,6]); let c = from_vec([5,6]);
let d = from_vec(~[7,8]); let d = from_vec([7,8]);
let ab = from_vec(~[a,b]); let ab = from_vec([a,b]);
let cd = from_vec(~[c,d]); let cd = from_vec([c,d]);
let abcd = concat(concat(from_vec(~[ab,cd]))); let abcd = concat(concat(from_vec([ab,cd])));
abcd.assert_consistent(); assert_eq!(abcd.len(), 8); abcd.assert_consistent(); assert_eq!(abcd.len(), 8);
abcd.assert_consistent(); assert_eq!(abcd.pop().get(), 1); abcd.assert_consistent(); assert_eq!(abcd.pop().get(), 1);
abcd.assert_consistent(); assert_eq!(abcd.pop().get(), 2); abcd.assert_consistent(); assert_eq!(abcd.pop().get(), 2);
@ -560,8 +560,8 @@ mod tests {
} }
#[test] #[test]
fn test_dlist_append() { fn test_dlist_append() {
let a = from_vec(~[1,2,3]); let a = from_vec([1,2,3]);
let b = from_vec(~[4,5,6]); let b = from_vec([4,5,6]);
a.append(b); a.append(b);
assert_eq!(a.len(), 6); assert_eq!(a.len(), 6);
assert_eq!(b.len(), 0); assert_eq!(b.len(), 0);
@ -576,7 +576,7 @@ mod tests {
} }
#[test] #[test]
fn test_dlist_append_empty() { fn test_dlist_append_empty() {
let a = from_vec(~[1,2,3]); let a = from_vec([1,2,3]);
let b = DList::<int>(); let b = DList::<int>();
a.append(b); a.append(b);
assert_eq!(a.len(), 3); assert_eq!(a.len(), 3);
@ -590,7 +590,7 @@ mod tests {
#[test] #[test]
fn test_dlist_append_to_empty() { fn test_dlist_append_to_empty() {
let a = DList::<int>(); let a = DList::<int>();
let b = from_vec(~[4,5,6]); let b = from_vec([4,5,6]);
a.append(b); a.append(b);
assert_eq!(a.len(), 3); assert_eq!(a.len(), 3);
assert_eq!(b.len(), 0); assert_eq!(b.len(), 0);
@ -626,8 +626,8 @@ mod tests {
} }
#[test] #[test]
fn test_dlist_prepend() { fn test_dlist_prepend() {
let a = from_vec(~[1,2,3]); let a = from_vec([1,2,3]);
let b = from_vec(~[4,5,6]); let b = from_vec([4,5,6]);
b.prepend(a); b.prepend(a);
assert_eq!(a.len(), 0); assert_eq!(a.len(), 0);
assert_eq!(b.len(), 6); assert_eq!(b.len(), 6);
@ -642,7 +642,7 @@ mod tests {
} }
#[test] #[test]
fn test_dlist_reverse() { fn test_dlist_reverse() {
let a = from_vec(~[5,4,3,2,1]); let a = from_vec([5,4,3,2,1]);
a.reverse(); a.reverse();
assert_eq!(a.len(), 5); assert_eq!(a.len(), 5);
a.assert_consistent(); assert_eq!(a.pop().get(), 1); a.assert_consistent(); assert_eq!(a.pop().get(), 1);
@ -661,7 +661,7 @@ mod tests {
} }
#[test] #[test]
fn test_dlist_each_node() { fn test_dlist_each_node() {
let a = from_vec(~[1,2,4,5]); let a = from_vec([1,2,4,5]);
for a.each_node |nobe| { for a.each_node |nobe| {
if nobe.data > 3 { if nobe.data > 3 {
a.insert_before(3, nobe); a.insert_before(3, nobe);
@ -678,7 +678,7 @@ mod tests {
} }
#[test] #[test]
fn test_dlist_clear() { fn test_dlist_clear() {
let a = from_vec(~[5,4,3,2,1]); let a = from_vec([5,4,3,2,1]);
a.clear(); a.clear();
assert_eq!(a.len(), 0); assert_eq!(a.len(), 0);
a.assert_consistent(); a.assert_consistent();
@ -686,20 +686,20 @@ mod tests {
#[test] #[test]
fn test_dlist_is_empty() { fn test_dlist_is_empty() {
let empty = DList::<int>(); let empty = DList::<int>();
let full1 = from_vec(~[1,2,3]); let full1 = from_vec([1,2,3]);
assert!(empty.is_empty()); assert!(empty.is_empty());
assert!(!full1.is_empty()); assert!(!full1.is_empty());
} }
#[test] #[test]
fn test_dlist_head_tail() { fn test_dlist_head_tail() {
let l = from_vec(~[1,2,3]); let l = from_vec([1,2,3]);
assert_eq!(l.head(), 1); assert_eq!(l.head(), 1);
assert_eq!(l.tail(), 3); assert_eq!(l.tail(), 3);
assert_eq!(l.len(), 3); assert_eq!(l.len(), 3);
} }
#[test] #[test]
fn test_dlist_pop() { fn test_dlist_pop() {
let l = from_vec(~[1,2,3]); let l = from_vec([1,2,3]);
assert_eq!(l.pop().get(), 1); assert_eq!(l.pop().get(), 1);
assert_eq!(l.tail(), 3); assert_eq!(l.tail(), 3);
assert_eq!(l.head(), 2); assert_eq!(l.head(), 2);
@ -712,7 +712,7 @@ mod tests {
} }
#[test] #[test]
fn test_dlist_pop_tail() { fn test_dlist_pop_tail() {
let l = from_vec(~[1,2,3]); let l = from_vec([1,2,3]);
assert_eq!(l.pop_tail().get(), 3); assert_eq!(l.pop_tail().get(), 3);
assert_eq!(l.tail(), 2); assert_eq!(l.tail(), 2);
assert_eq!(l.head(), 1); assert_eq!(l.head(), 1);
@ -758,7 +758,7 @@ mod tests {
} }
#[test] #[test]
fn test_dlist_break_early() { fn test_dlist_break_early() {
let l = from_vec(~[1,2,3,4,5]); let l = from_vec([1,2,3,4,5]);
let mut x = 0; let mut x = 0;
for l.each |i| { for l.each |i| {
x += 1; x += 1;

View file

@ -96,8 +96,6 @@ total line count).
use core::prelude::*; use core::prelude::*;
use core::io::ReaderUtil;
/** /**
A summary of the internal state of a `FileInput` object. `line_num` A summary of the internal state of a `FileInput` object. `line_num`
and `line_num_file` represent the number of lines read in total and in and `line_num_file` represent the number of lines read in total and in
@ -407,7 +405,6 @@ pub fn input_vec_state(files: ~[Option<Path>],
mod test { mod test {
use core::prelude::*; use core::prelude::*;
use core::io::WriterUtil;
use super::{FileInput, pathify, input_vec, input_vec_state}; use super::{FileInput, pathify, input_vec, input_vec_state};
fn make_file(path : &Path, contents: &[~str]) { fn make_file(path : &Path, contents: &[~str]) {
@ -441,7 +438,7 @@ mod test {
// 3 files containing 0\n, 1\n, and 2\n respectively // 3 files containing 0\n, 1\n, and 2\n respectively
for filenames.eachi |i, &filename| { for filenames.eachi |i, &filename| {
make_file(filename.get_ref(), ~[fmt!("%u", i)]); make_file(filename.get_ref(), [fmt!("%u", i)]);
} }
let fi = FileInput::from_vec(copy filenames); let fi = FileInput::from_vec(copy filenames);
@ -471,7 +468,7 @@ mod test {
// 3 files containing 1\n, 2\n, and 3\n respectively // 3 files containing 1\n, 2\n, and 3\n respectively
for filenames.eachi |i, &filename| { for filenames.eachi |i, &filename| {
make_file(filename.get_ref(), ~[fmt!("%u", i)]); make_file(filename.get_ref(), [fmt!("%u", i)]);
} }
let fi = FileInput::from_vec(filenames); let fi = FileInput::from_vec(filenames);
@ -533,9 +530,9 @@ mod test {
3, 3,
|i| fmt!("tmp/lib-fileinput-test-empty-files-%u.tmp", i)),true); |i| fmt!("tmp/lib-fileinput-test-empty-files-%u.tmp", i)),true);
make_file(filenames[0].get_ref(), ~[~"1", ~"2"]); make_file(filenames[0].get_ref(), [~"1", ~"2"]);
make_file(filenames[1].get_ref(), ~[]); make_file(filenames[1].get_ref(), []);
make_file(filenames[2].get_ref(), ~[~"3", ~"4"]); make_file(filenames[2].get_ref(), [~"3", ~"4"]);
let mut count = 0; let mut count = 0;
for input_vec_state(copy filenames) |line, state| { for input_vec_state(copy filenames) |line, state| {
@ -580,7 +577,7 @@ mod test {
make_file(&filename.get(), contents); make_file(&filename.get(), contents);
} }
let mut in = FileInput::from_vec(filenames); let in = FileInput::from_vec(filenames);
// read once from 0 // read once from 0
assert_eq!(in.read_line(), ~"0 1"); assert_eq!(in.read_line(), ~"0 1");

View file

@ -16,12 +16,8 @@ Simple compression
use core::prelude::*; use core::prelude::*;
use core::libc::{c_void, size_t, c_int};
use core::libc; use core::libc;
use core::vec; use core::libc::{c_void, size_t, c_int};
#[cfg(test)] use core::rand;
#[cfg(test)] use core::rand::RngUtil;
pub mod rustrt { pub mod rustrt {
use core::libc::{c_int, c_void, size_t}; use core::libc::{c_int, c_void, size_t};
@ -83,6 +79,12 @@ pub fn inflate_bytes(bytes: &const [u8]) -> ~[u8] {
} }
} }
#[cfg(test)]
mod tests {
use super::*;
use core::rand;
use core::rand::RngUtil;
#[test] #[test]
#[allow(non_implicitly_copyable_typarams)] #[allow(non_implicitly_copyable_typarams)]
fn test_flate_round_trip() { fn test_flate_round_trip() {
@ -107,3 +109,4 @@ fn test_flate_round_trip() {
assert_eq!(in, out); assert_eq!(in, out);
} }
} }
}

View file

@ -681,12 +681,12 @@ mod tests {
#[test] #[test]
fn test_reqopt_long() { fn test_reqopt_long() {
let args = ~[~"--test=20"]; let args = ~[~"--test=20"];
let opts = ~[reqopt(~"test")]; let opts = ~[reqopt("test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Ok(ref m) => { Ok(ref m) => {
assert!((opt_present(m, ~"test"))); assert!((opt_present(m, "test")));
assert_eq!(opt_str(m, ~"test"), ~"20"); assert_eq!(opt_str(m, "test"), ~"20");
} }
_ => { fail!("test_reqopt_long failed"); } _ => { fail!("test_reqopt_long failed"); }
} }
@ -695,7 +695,7 @@ mod tests {
#[test] #[test]
fn test_reqopt_long_missing() { fn test_reqopt_long_missing() {
let args = ~[~"blah"]; let args = ~[~"blah"];
let opts = ~[reqopt(~"test")]; let opts = ~[reqopt("test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, OptionMissing_), Err(copy f) => check_fail_type(f, OptionMissing_),
@ -706,7 +706,7 @@ mod tests {
#[test] #[test]
fn test_reqopt_long_no_arg() { fn test_reqopt_long_no_arg() {
let args = ~[~"--test"]; let args = ~[~"--test"];
let opts = ~[reqopt(~"test")]; let opts = ~[reqopt("test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, ArgumentMissing_), Err(copy f) => check_fail_type(f, ArgumentMissing_),
@ -717,7 +717,7 @@ mod tests {
#[test] #[test]
fn test_reqopt_long_multi() { fn test_reqopt_long_multi() {
let args = ~[~"--test=20", ~"--test=30"]; let args = ~[~"--test=20", ~"--test=30"];
let opts = ~[reqopt(~"test")]; let opts = ~[reqopt("test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, OptionDuplicated_), Err(copy f) => check_fail_type(f, OptionDuplicated_),
@ -728,12 +728,12 @@ mod tests {
#[test] #[test]
fn test_reqopt_short() { fn test_reqopt_short() {
let args = ~[~"-t", ~"20"]; let args = ~[~"-t", ~"20"];
let opts = ~[reqopt(~"t")]; let opts = ~[reqopt("t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Ok(ref m) => { Ok(ref m) => {
assert!((opt_present(m, ~"t"))); assert!((opt_present(m, "t")));
assert_eq!(opt_str(m, ~"t"), ~"20"); assert_eq!(opt_str(m, "t"), ~"20");
} }
_ => fail!() _ => fail!()
} }
@ -742,7 +742,7 @@ mod tests {
#[test] #[test]
fn test_reqopt_short_missing() { fn test_reqopt_short_missing() {
let args = ~[~"blah"]; let args = ~[~"blah"];
let opts = ~[reqopt(~"t")]; let opts = ~[reqopt("t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, OptionMissing_), Err(copy f) => check_fail_type(f, OptionMissing_),
@ -753,7 +753,7 @@ mod tests {
#[test] #[test]
fn test_reqopt_short_no_arg() { fn test_reqopt_short_no_arg() {
let args = ~[~"-t"]; let args = ~[~"-t"];
let opts = ~[reqopt(~"t")]; let opts = ~[reqopt("t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, ArgumentMissing_), Err(copy f) => check_fail_type(f, ArgumentMissing_),
@ -764,7 +764,7 @@ mod tests {
#[test] #[test]
fn test_reqopt_short_multi() { fn test_reqopt_short_multi() {
let args = ~[~"-t", ~"20", ~"-t", ~"30"]; let args = ~[~"-t", ~"20", ~"-t", ~"30"];
let opts = ~[reqopt(~"t")]; let opts = ~[reqopt("t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, OptionDuplicated_), Err(copy f) => check_fail_type(f, OptionDuplicated_),
@ -777,12 +777,12 @@ mod tests {
#[test] #[test]
fn test_optopt_long() { fn test_optopt_long() {
let args = ~[~"--test=20"]; let args = ~[~"--test=20"];
let opts = ~[optopt(~"test")]; let opts = ~[optopt("test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Ok(ref m) => { Ok(ref m) => {
assert!((opt_present(m, ~"test"))); assert!((opt_present(m, "test")));
assert_eq!(opt_str(m, ~"test"), ~"20"); assert_eq!(opt_str(m, "test"), ~"20");
} }
_ => fail!() _ => fail!()
} }
@ -791,10 +791,10 @@ mod tests {
#[test] #[test]
fn test_optopt_long_missing() { fn test_optopt_long_missing() {
let args = ~[~"blah"]; let args = ~[~"blah"];
let opts = ~[optopt(~"test")]; let opts = ~[optopt("test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Ok(ref m) => assert!(!opt_present(m, ~"test")), Ok(ref m) => assert!(!opt_present(m, "test")),
_ => fail!() _ => fail!()
} }
} }
@ -802,7 +802,7 @@ mod tests {
#[test] #[test]
fn test_optopt_long_no_arg() { fn test_optopt_long_no_arg() {
let args = ~[~"--test"]; let args = ~[~"--test"];
let opts = ~[optopt(~"test")]; let opts = ~[optopt("test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, ArgumentMissing_), Err(copy f) => check_fail_type(f, ArgumentMissing_),
@ -813,7 +813,7 @@ mod tests {
#[test] #[test]
fn test_optopt_long_multi() { fn test_optopt_long_multi() {
let args = ~[~"--test=20", ~"--test=30"]; let args = ~[~"--test=20", ~"--test=30"];
let opts = ~[optopt(~"test")]; let opts = ~[optopt("test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, OptionDuplicated_), Err(copy f) => check_fail_type(f, OptionDuplicated_),
@ -824,12 +824,12 @@ mod tests {
#[test] #[test]
fn test_optopt_short() { fn test_optopt_short() {
let args = ~[~"-t", ~"20"]; let args = ~[~"-t", ~"20"];
let opts = ~[optopt(~"t")]; let opts = ~[optopt("t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Ok(ref m) => { Ok(ref m) => {
assert!((opt_present(m, ~"t"))); assert!((opt_present(m, "t")));
assert_eq!(opt_str(m, ~"t"), ~"20"); assert_eq!(opt_str(m, "t"), ~"20");
} }
_ => fail!() _ => fail!()
} }
@ -838,10 +838,10 @@ mod tests {
#[test] #[test]
fn test_optopt_short_missing() { fn test_optopt_short_missing() {
let args = ~[~"blah"]; let args = ~[~"blah"];
let opts = ~[optopt(~"t")]; let opts = ~[optopt("t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Ok(ref m) => assert!(!opt_present(m, ~"t")), Ok(ref m) => assert!(!opt_present(m, "t")),
_ => fail!() _ => fail!()
} }
} }
@ -849,7 +849,7 @@ mod tests {
#[test] #[test]
fn test_optopt_short_no_arg() { fn test_optopt_short_no_arg() {
let args = ~[~"-t"]; let args = ~[~"-t"];
let opts = ~[optopt(~"t")]; let opts = ~[optopt("t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, ArgumentMissing_), Err(copy f) => check_fail_type(f, ArgumentMissing_),
@ -860,7 +860,7 @@ mod tests {
#[test] #[test]
fn test_optopt_short_multi() { fn test_optopt_short_multi() {
let args = ~[~"-t", ~"20", ~"-t", ~"30"]; let args = ~[~"-t", ~"20", ~"-t", ~"30"];
let opts = ~[optopt(~"t")]; let opts = ~[optopt("t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, OptionDuplicated_), Err(copy f) => check_fail_type(f, OptionDuplicated_),
@ -873,10 +873,10 @@ mod tests {
#[test] #[test]
fn test_optflag_long() { fn test_optflag_long() {
let args = ~[~"--test"]; let args = ~[~"--test"];
let opts = ~[optflag(~"test")]; let opts = ~[optflag("test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Ok(ref m) => assert!(opt_present(m, ~"test")), Ok(ref m) => assert!(opt_present(m, "test")),
_ => fail!() _ => fail!()
} }
} }
@ -884,10 +884,10 @@ mod tests {
#[test] #[test]
fn test_optflag_long_missing() { fn test_optflag_long_missing() {
let args = ~[~"blah"]; let args = ~[~"blah"];
let opts = ~[optflag(~"test")]; let opts = ~[optflag("test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Ok(ref m) => assert!(!opt_present(m, ~"test")), Ok(ref m) => assert!(!opt_present(m, "test")),
_ => fail!() _ => fail!()
} }
} }
@ -895,7 +895,7 @@ mod tests {
#[test] #[test]
fn test_optflag_long_arg() { fn test_optflag_long_arg() {
let args = ~[~"--test=20"]; let args = ~[~"--test=20"];
let opts = ~[optflag(~"test")]; let opts = ~[optflag("test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => { Err(copy f) => {
@ -909,7 +909,7 @@ mod tests {
#[test] #[test]
fn test_optflag_long_multi() { fn test_optflag_long_multi() {
let args = ~[~"--test", ~"--test"]; let args = ~[~"--test", ~"--test"];
let opts = ~[optflag(~"test")]; let opts = ~[optflag("test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, OptionDuplicated_), Err(copy f) => check_fail_type(f, OptionDuplicated_),
@ -920,10 +920,10 @@ mod tests {
#[test] #[test]
fn test_optflag_short() { fn test_optflag_short() {
let args = ~[~"-t"]; let args = ~[~"-t"];
let opts = ~[optflag(~"t")]; let opts = ~[optflag("t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Ok(ref m) => assert!(opt_present(m, ~"t")), Ok(ref m) => assert!(opt_present(m, "t")),
_ => fail!() _ => fail!()
} }
} }
@ -931,10 +931,10 @@ mod tests {
#[test] #[test]
fn test_optflag_short_missing() { fn test_optflag_short_missing() {
let args = ~[~"blah"]; let args = ~[~"blah"];
let opts = ~[optflag(~"t")]; let opts = ~[optflag("t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Ok(ref m) => assert!(!opt_present(m, ~"t")), Ok(ref m) => assert!(!opt_present(m, "t")),
_ => fail!() _ => fail!()
} }
} }
@ -942,7 +942,7 @@ mod tests {
#[test] #[test]
fn test_optflag_short_arg() { fn test_optflag_short_arg() {
let args = ~[~"-t", ~"20"]; let args = ~[~"-t", ~"20"];
let opts = ~[optflag(~"t")]; let opts = ~[optflag("t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Ok(ref m) => { Ok(ref m) => {
@ -957,7 +957,7 @@ mod tests {
#[test] #[test]
fn test_optflag_short_multi() { fn test_optflag_short_multi() {
let args = ~[~"-t", ~"-t"]; let args = ~[~"-t", ~"-t"];
let opts = ~[optflag(~"t")]; let opts = ~[optflag("t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, OptionDuplicated_), Err(copy f) => check_fail_type(f, OptionDuplicated_),
@ -969,11 +969,11 @@ mod tests {
#[test] #[test]
fn test_optflagmulti_short1() { fn test_optflagmulti_short1() {
let args = ~[~"-v"]; let args = ~[~"-v"];
let opts = ~[optflagmulti(~"v")]; let opts = ~[optflagmulti("v")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Ok(ref m) => { Ok(ref m) => {
assert_eq!(opt_count(m, ~"v"), 1); assert_eq!(opt_count(m, "v"), 1);
} }
_ => fail!() _ => fail!()
} }
@ -982,11 +982,11 @@ mod tests {
#[test] #[test]
fn test_optflagmulti_short2a() { fn test_optflagmulti_short2a() {
let args = ~[~"-v", ~"-v"]; let args = ~[~"-v", ~"-v"];
let opts = ~[optflagmulti(~"v")]; let opts = ~[optflagmulti("v")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Ok(ref m) => { Ok(ref m) => {
assert_eq!(opt_count(m, ~"v"), 2); assert_eq!(opt_count(m, "v"), 2);
} }
_ => fail!() _ => fail!()
} }
@ -995,11 +995,11 @@ mod tests {
#[test] #[test]
fn test_optflagmulti_short2b() { fn test_optflagmulti_short2b() {
let args = ~[~"-vv"]; let args = ~[~"-vv"];
let opts = ~[optflagmulti(~"v")]; let opts = ~[optflagmulti("v")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Ok(ref m) => { Ok(ref m) => {
assert_eq!(opt_count(m, ~"v"), 2); assert_eq!(opt_count(m, "v"), 2);
} }
_ => fail!() _ => fail!()
} }
@ -1008,11 +1008,11 @@ mod tests {
#[test] #[test]
fn test_optflagmulti_long1() { fn test_optflagmulti_long1() {
let args = ~[~"--verbose"]; let args = ~[~"--verbose"];
let opts = ~[optflagmulti(~"verbose")]; let opts = ~[optflagmulti("verbose")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Ok(ref m) => { Ok(ref m) => {
assert_eq!(opt_count(m, ~"verbose"), 1); assert_eq!(opt_count(m, "verbose"), 1);
} }
_ => fail!() _ => fail!()
} }
@ -1021,11 +1021,11 @@ mod tests {
#[test] #[test]
fn test_optflagmulti_long2() { fn test_optflagmulti_long2() {
let args = ~[~"--verbose", ~"--verbose"]; let args = ~[~"--verbose", ~"--verbose"];
let opts = ~[optflagmulti(~"verbose")]; let opts = ~[optflagmulti("verbose")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Ok(ref m) => { Ok(ref m) => {
assert_eq!(opt_count(m, ~"verbose"), 2); assert_eq!(opt_count(m, "verbose"), 2);
} }
_ => fail!() _ => fail!()
} }
@ -1035,12 +1035,12 @@ mod tests {
#[test] #[test]
fn test_optmulti_long() { fn test_optmulti_long() {
let args = ~[~"--test=20"]; let args = ~[~"--test=20"];
let opts = ~[optmulti(~"test")]; let opts = ~[optmulti("test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Ok(ref m) => { Ok(ref m) => {
assert!((opt_present(m, ~"test"))); assert!((opt_present(m, "test")));
assert_eq!(opt_str(m, ~"test"), ~"20"); assert_eq!(opt_str(m, "test"), ~"20");
} }
_ => fail!() _ => fail!()
} }
@ -1049,10 +1049,10 @@ mod tests {
#[test] #[test]
fn test_optmulti_long_missing() { fn test_optmulti_long_missing() {
let args = ~[~"blah"]; let args = ~[~"blah"];
let opts = ~[optmulti(~"test")]; let opts = ~[optmulti("test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Ok(ref m) => assert!(!opt_present(m, ~"test")), Ok(ref m) => assert!(!opt_present(m, "test")),
_ => fail!() _ => fail!()
} }
} }
@ -1060,7 +1060,7 @@ mod tests {
#[test] #[test]
fn test_optmulti_long_no_arg() { fn test_optmulti_long_no_arg() {
let args = ~[~"--test"]; let args = ~[~"--test"];
let opts = ~[optmulti(~"test")]; let opts = ~[optmulti("test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, ArgumentMissing_), Err(copy f) => check_fail_type(f, ArgumentMissing_),
@ -1071,13 +1071,13 @@ mod tests {
#[test] #[test]
fn test_optmulti_long_multi() { fn test_optmulti_long_multi() {
let args = ~[~"--test=20", ~"--test=30"]; let args = ~[~"--test=20", ~"--test=30"];
let opts = ~[optmulti(~"test")]; let opts = ~[optmulti("test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Ok(ref m) => { Ok(ref m) => {
assert!(opt_present(m, ~"test")); assert!(opt_present(m, "test"));
assert_eq!(opt_str(m, ~"test"), ~"20"); assert_eq!(opt_str(m, "test"), ~"20");
let pair = opt_strs(m, ~"test"); let pair = opt_strs(m, "test");
assert!(pair[0] == ~"20"); assert!(pair[0] == ~"20");
assert!(pair[1] == ~"30"); assert!(pair[1] == ~"30");
} }
@ -1088,12 +1088,12 @@ mod tests {
#[test] #[test]
fn test_optmulti_short() { fn test_optmulti_short() {
let args = ~[~"-t", ~"20"]; let args = ~[~"-t", ~"20"];
let opts = ~[optmulti(~"t")]; let opts = ~[optmulti("t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Ok(ref m) => { Ok(ref m) => {
assert!((opt_present(m, ~"t"))); assert!((opt_present(m, "t")));
assert_eq!(opt_str(m, ~"t"), ~"20"); assert_eq!(opt_str(m, "t"), ~"20");
} }
_ => fail!() _ => fail!()
} }
@ -1102,10 +1102,10 @@ mod tests {
#[test] #[test]
fn test_optmulti_short_missing() { fn test_optmulti_short_missing() {
let args = ~[~"blah"]; let args = ~[~"blah"];
let opts = ~[optmulti(~"t")]; let opts = ~[optmulti("t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Ok(ref m) => assert!(!opt_present(m, ~"t")), Ok(ref m) => assert!(!opt_present(m, "t")),
_ => fail!() _ => fail!()
} }
} }
@ -1113,7 +1113,7 @@ mod tests {
#[test] #[test]
fn test_optmulti_short_no_arg() { fn test_optmulti_short_no_arg() {
let args = ~[~"-t"]; let args = ~[~"-t"];
let opts = ~[optmulti(~"t")]; let opts = ~[optmulti("t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, ArgumentMissing_), Err(copy f) => check_fail_type(f, ArgumentMissing_),
@ -1124,13 +1124,13 @@ mod tests {
#[test] #[test]
fn test_optmulti_short_multi() { fn test_optmulti_short_multi() {
let args = ~[~"-t", ~"20", ~"-t", ~"30"]; let args = ~[~"-t", ~"20", ~"-t", ~"30"];
let opts = ~[optmulti(~"t")]; let opts = ~[optmulti("t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Ok(ref m) => { Ok(ref m) => {
assert!((opt_present(m, ~"t"))); assert!((opt_present(m, "t")));
assert_eq!(opt_str(m, ~"t"), ~"20"); assert_eq!(opt_str(m, "t"), ~"20");
let pair = opt_strs(m, ~"t"); let pair = opt_strs(m, "t");
assert!(pair[0] == ~"20"); assert!(pair[0] == ~"20");
assert!(pair[1] == ~"30"); assert!(pair[1] == ~"30");
} }
@ -1141,7 +1141,7 @@ mod tests {
#[test] #[test]
fn test_unrecognized_option_long() { fn test_unrecognized_option_long() {
let args = ~[~"--untest"]; let args = ~[~"--untest"];
let opts = ~[optmulti(~"t")]; let opts = ~[optmulti("t")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, UnrecognizedOption_), Err(copy f) => check_fail_type(f, UnrecognizedOption_),
@ -1152,7 +1152,7 @@ mod tests {
#[test] #[test]
fn test_unrecognized_option_short() { fn test_unrecognized_option_short() {
let args = ~[~"-t"]; let args = ~[~"-t"];
let opts = ~[optmulti(~"test")]; let opts = ~[optmulti("test")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Err(copy f) => check_fail_type(f, UnrecognizedOption_), Err(copy f) => check_fail_type(f, UnrecognizedOption_),
@ -1167,26 +1167,26 @@ mod tests {
~"--flag", ~"--long=30", ~"-f", ~"-m", ~"40", ~"--flag", ~"--long=30", ~"-f", ~"-m", ~"40",
~"-m", ~"50", ~"-n", ~"-A B", ~"-n", ~"-60 70"]; ~"-m", ~"50", ~"-n", ~"-A B", ~"-n", ~"-60 70"];
let opts = let opts =
~[optopt(~"s"), optflag(~"flag"), reqopt(~"long"), ~[optopt("s"), optflag("flag"), reqopt("long"),
optflag(~"f"), optmulti(~"m"), optmulti(~"n"), optflag("f"), optmulti("m"), optmulti("n"),
optopt(~"notpresent")]; optopt("notpresent")];
let rs = getopts(args, opts); let rs = getopts(args, opts);
match rs { match rs {
Ok(ref m) => { Ok(ref m) => {
assert!(m.free[0] == ~"prog"); assert!(m.free[0] == ~"prog");
assert!(m.free[1] == ~"free1"); assert!(m.free[1] == ~"free1");
assert_eq!(opt_str(m, ~"s"), ~"20"); assert_eq!(opt_str(m, "s"), ~"20");
assert!(m.free[2] == ~"free2"); assert!(m.free[2] == ~"free2");
assert!((opt_present(m, ~"flag"))); assert!((opt_present(m, "flag")));
assert_eq!(opt_str(m, ~"long"), ~"30"); assert_eq!(opt_str(m, "long"), ~"30");
assert!((opt_present(m, ~"f"))); assert!((opt_present(m, "f")));
let pair = opt_strs(m, ~"m"); let pair = opt_strs(m, "m");
assert!(pair[0] == ~"40"); assert!(pair[0] == ~"40");
assert!(pair[1] == ~"50"); assert!(pair[1] == ~"50");
let pair = opt_strs(m, ~"n"); let pair = opt_strs(m, "n");
assert!(pair[0] == ~"-A B"); assert!(pair[0] == ~"-A B");
assert!(pair[1] == ~"-60 70"); assert!(pair[1] == ~"-60 70");
assert!((!opt_present(m, ~"notpresent"))); assert!((!opt_present(m, "notpresent")));
} }
_ => fail!() _ => fail!()
} }
@ -1195,43 +1195,43 @@ mod tests {
#[test] #[test]
fn test_multi() { fn test_multi() {
let args = ~[~"-e", ~"foo", ~"--encrypt", ~"foo"]; let args = ~[~"-e", ~"foo", ~"--encrypt", ~"foo"];
let opts = ~[optopt(~"e"), optopt(~"encrypt"), optopt(~"f")]; let opts = ~[optopt("e"), optopt("encrypt"), optopt("f")];
let matches = &match getopts(args, opts) { let matches = &match getopts(args, opts) {
result::Ok(m) => m, result::Ok(m) => m,
result::Err(_) => fail!() result::Err(_) => fail!()
}; };
assert!(opts_present(matches, ~[~"e"])); assert!(opts_present(matches, [~"e"]));
assert!(opts_present(matches, ~[~"encrypt"])); assert!(opts_present(matches, [~"encrypt"]));
assert!(opts_present(matches, ~[~"encrypt", ~"e"])); assert!(opts_present(matches, [~"encrypt", ~"e"]));
assert!(opts_present(matches, ~[~"e", ~"encrypt"])); assert!(opts_present(matches, [~"e", ~"encrypt"]));
assert!(!opts_present(matches, ~[~"f"])); assert!(!opts_present(matches, [~"f"]));
assert!(!opts_present(matches, ~[~"thing"])); assert!(!opts_present(matches, [~"thing"]));
assert!(!opts_present(matches, ~[])); assert!(!opts_present(matches, []));
assert_eq!(opts_str(matches, ~[~"e"]), ~"foo"); assert_eq!(opts_str(matches, [~"e"]), ~"foo");
assert_eq!(opts_str(matches, ~[~"encrypt"]), ~"foo"); assert_eq!(opts_str(matches, [~"encrypt"]), ~"foo");
assert_eq!(opts_str(matches, ~[~"e", ~"encrypt"]), ~"foo"); assert_eq!(opts_str(matches, [~"e", ~"encrypt"]), ~"foo");
assert_eq!(opts_str(matches, ~[~"encrypt", ~"e"]), ~"foo"); assert_eq!(opts_str(matches, [~"encrypt", ~"e"]), ~"foo");
} }
#[test] #[test]
fn test_nospace() { fn test_nospace() {
let args = ~[~"-Lfoo", ~"-M."]; let args = ~[~"-Lfoo", ~"-M."];
let opts = ~[optmulti(~"L"), optmulti(~"M")]; let opts = ~[optmulti("L"), optmulti("M")];
let matches = &match getopts(args, opts) { let matches = &match getopts(args, opts) {
result::Ok(m) => m, result::Ok(m) => m,
result::Err(_) => fail!() result::Err(_) => fail!()
}; };
assert!(opts_present(matches, ~[~"L"])); assert!(opts_present(matches, [~"L"]));
assert_eq!(opts_str(matches, ~[~"L"]), ~"foo"); assert_eq!(opts_str(matches, [~"L"]), ~"foo");
assert!(opts_present(matches, ~[~"M"])); assert!(opts_present(matches, [~"M"]));
assert_eq!(opts_str(matches, ~[~"M"]), ~"."); assert_eq!(opts_str(matches, [~"M"]), ~".");
} }
#[test] #[test]
fn test_groups_reqopt() { fn test_groups_reqopt() {
let opt = groups::reqopt(~"b", ~"banana", ~"some bananas", ~"VAL"); let opt = groups::reqopt("b", "banana", "some bananas", "VAL");
assert!(opt == OptGroup { short_name: ~"b", assert!(opt == OptGroup { short_name: ~"b",
long_name: ~"banana", long_name: ~"banana",
hint: ~"VAL", hint: ~"VAL",
@ -1242,7 +1242,7 @@ mod tests {
#[test] #[test]
fn test_groups_optopt() { fn test_groups_optopt() {
let opt = groups::optopt(~"a", ~"apple", ~"some apples", ~"VAL"); let opt = groups::optopt("a", "apple", "some apples", "VAL");
assert!(opt == OptGroup { short_name: ~"a", assert!(opt == OptGroup { short_name: ~"a",
long_name: ~"apple", long_name: ~"apple",
hint: ~"VAL", hint: ~"VAL",
@ -1253,7 +1253,7 @@ mod tests {
#[test] #[test]
fn test_groups_optflag() { fn test_groups_optflag() {
let opt = groups::optflag(~"k", ~"kiwi", ~"some kiwis"); let opt = groups::optflag("k", "kiwi", "some kiwis");
assert!(opt == OptGroup { short_name: ~"k", assert!(opt == OptGroup { short_name: ~"k",
long_name: ~"kiwi", long_name: ~"kiwi",
hint: ~"", hint: ~"",
@ -1264,8 +1264,7 @@ mod tests {
#[test] #[test]
fn test_groups_optflagopt() { fn test_groups_optflagopt() {
let opt = groups::optflagopt(~"p", ~"pineapple", let opt = groups::optflagopt("p", "pineapple", "some pineapples", "VAL");
~"some pineapples", ~"VAL");
assert!(opt == OptGroup { short_name: ~"p", assert!(opt == OptGroup { short_name: ~"p",
long_name: ~"pineapple", long_name: ~"pineapple",
hint: ~"VAL", hint: ~"VAL",
@ -1276,8 +1275,7 @@ mod tests {
#[test] #[test]
fn test_groups_optmulti() { fn test_groups_optmulti() {
let opt = groups::optmulti(~"l", ~"lime", let opt = groups::optmulti("l", "lime", "some limes", "VAL");
~"some limes", ~"VAL");
assert!(opt == OptGroup { short_name: ~"l", assert!(opt == OptGroup { short_name: ~"l",
long_name: ~"lime", long_name: ~"lime",
hint: ~"VAL", hint: ~"VAL",
@ -1288,9 +1286,8 @@ mod tests {
#[test] #[test]
fn test_groups_long_to_short() { fn test_groups_long_to_short() {
let short = ~[reqopt(~"b"), reqopt(~"banana")]; let short = ~[reqopt("b"), reqopt("banana")];
let verbose = groups::reqopt(~"b", ~"banana", let verbose = groups::reqopt("b", "banana", "some bananas", "VAL");
~"some bananas", ~"VAL");
assert_eq!(groups::long_to_short(&verbose), short); assert_eq!(groups::long_to_short(&verbose), short);
} }
@ -1298,19 +1295,19 @@ mod tests {
#[test] #[test]
fn test_groups_getopts() { fn test_groups_getopts() {
let short = ~[ let short = ~[
reqopt(~"b"), reqopt(~"banana"), reqopt("b"), reqopt("banana"),
optopt(~"a"), optopt(~"apple"), optopt("a"), optopt("apple"),
optflag(~"k"), optflagopt(~"kiwi"), optflag("k"), optflagopt("kiwi"),
optflagopt(~"p"), optflagopt("p"),
optmulti(~"l") optmulti("l")
]; ];
let verbose = ~[ let verbose = ~[
groups::reqopt(~"b", ~"banana", ~"Desc", ~"VAL"), groups::reqopt("b", "banana", "Desc", "VAL"),
groups::optopt(~"a", ~"apple", ~"Desc", ~"VAL"), groups::optopt("a", "apple", "Desc", "VAL"),
groups::optflag(~"k", ~"kiwi", ~"Desc"), groups::optflag("k", "kiwi", "Desc"),
groups::optflagopt(~"p", ~"", ~"Desc", ~"VAL"), groups::optflagopt("p", "", "Desc", "VAL"),
groups::optmulti(~"l", ~"", ~"Desc", ~"VAL"), groups::optmulti("l", "", "Desc", "VAL"),
]; ];
let sample_args = ~[~"-k", ~"15", ~"--apple", ~"1", ~"k", let sample_args = ~[~"-k", ~"15", ~"--apple", ~"1", ~"k",
@ -1324,12 +1321,12 @@ mod tests {
#[test] #[test]
fn test_groups_usage() { fn test_groups_usage() {
let optgroups = ~[ let optgroups = ~[
groups::reqopt(~"b", ~"banana", ~"Desc", ~"VAL"), groups::reqopt("b", "banana", "Desc", "VAL"),
groups::optopt(~"a", ~"012345678901234567890123456789", groups::optopt("a", "012345678901234567890123456789",
~"Desc", ~"VAL"), "Desc", "VAL"),
groups::optflag(~"k", ~"kiwi", ~"Desc"), groups::optflag("k", "kiwi", "Desc"),
groups::optflagopt(~"p", ~"", ~"Desc", ~"VAL"), groups::optflagopt("p", "", "Desc", "VAL"),
groups::optmulti(~"l", ~"", ~"Desc", ~"VAL"), groups::optmulti("l", "", "Desc", "VAL"),
]; ];
let expected = let expected =
@ -1345,7 +1342,7 @@ Options:
"; ";
let generated_usage = groups::usage(~"Usage: fruits", optgroups); let generated_usage = groups::usage("Usage: fruits", optgroups);
debug!("expected: <<%s>>", expected); debug!("expected: <<%s>>", expected);
debug!("generated: <<%s>>", generated_usage); debug!("generated: <<%s>>", generated_usage);
@ -1358,10 +1355,10 @@ Options:
// lines wrap after 78: or rather descriptions wrap after 54 // lines wrap after 78: or rather descriptions wrap after 54
let optgroups = ~[ let optgroups = ~[
groups::optflag(~"k", ~"kiwi", groups::optflag("k", "kiwi",
~"This is a long description which won't be wrapped..+.."), // 54 "This is a long description which won't be wrapped..+.."), // 54
groups::optflag(~"a", ~"apple", groups::optflag("a", "apple",
~"This is a long description which _will_ be wrapped..+.."), // 55 "This is a long description which _will_ be wrapped..+.."), // 55
]; ];
let expected = let expected =
@ -1374,7 +1371,7 @@ Options:
"; ";
let usage = groups::usage(~"Usage: fruits", optgroups); let usage = groups::usage("Usage: fruits", optgroups);
debug!("expected: <<%s>>", expected); debug!("expected: <<%s>>", expected);
debug!("generated: <<%s>>", usage); debug!("generated: <<%s>>", usage);

View file

@ -1444,15 +1444,15 @@ mod tests {
#[test] #[test]
fn test_write_object() { fn test_write_object() {
assert_eq!(to_str(&mk_object(~[])), ~"{}"); assert_eq!(to_str(&mk_object([])), ~"{}");
assert_eq!(to_pretty_str(&mk_object(~[])), ~"{}"); assert_eq!(to_pretty_str(&mk_object([])), ~"{}");
assert_eq!( assert_eq!(
to_str(&mk_object(~[(~"a", Boolean(true))])), to_str(&mk_object([(~"a", Boolean(true))])),
~"{\"a\":true}" ~"{\"a\":true}"
); );
assert_eq!( assert_eq!(
to_pretty_str(&mk_object(~[(~"a", Boolean(true))])), to_pretty_str(&mk_object([(~"a", Boolean(true))])),
~"\ ~"\
{\n \ {\n \
\"a\": true\n\ \"a\": true\n\
@ -1460,10 +1460,10 @@ mod tests {
); );
assert_eq!( assert_eq!(
to_str(&mk_object(~[ to_str(&mk_object([
(~"b", List(~[ (~"b", List(~[
mk_object(~[(~"c", String(~"\x0c\r"))]), mk_object([(~"c", String(~"\x0c\r"))]),
mk_object(~[(~"d", String(~""))]) mk_object([(~"d", String(~""))])
])) ]))
])), ])),
~"{\ ~"{\
@ -1474,10 +1474,10 @@ mod tests {
}" }"
); );
assert_eq!( assert_eq!(
to_pretty_str(&mk_object(~[ to_pretty_str(&mk_object([
(~"b", List(~[ (~"b", List(~[
mk_object(~[(~"c", String(~"\x0c\r"))]), mk_object([(~"c", String(~"\x0c\r"))]),
mk_object(~[(~"d", String(~""))]) mk_object([(~"d", String(~""))])
])) ]))
])), ])),
~"\ ~"\
@ -1493,11 +1493,11 @@ mod tests {
}" }"
); );
let a = mk_object(~[ let a = mk_object([
(~"a", Boolean(true)), (~"a", Boolean(true)),
(~"b", List(~[ (~"b", List(~[
mk_object(~[(~"c", String(~"\x0c\r"))]), mk_object([(~"c", String(~"\x0c\r"))]),
mk_object(~[(~"d", String(~""))]) mk_object([(~"d", String(~""))])
])) ]))
]); ]);
@ -1582,299 +1582,299 @@ mod tests {
#[test] #[test]
fn test_trailing_characters() { fn test_trailing_characters() {
assert_eq!(from_str(~"nulla"), assert_eq!(from_str("nulla"),
Err(Error {line: 1u, col: 5u, msg: @~"trailing characters"})); Err(Error {line: 1u, col: 5u, msg: @~"trailing characters"}));
assert_eq!(from_str(~"truea"), assert_eq!(from_str("truea"),
Err(Error {line: 1u, col: 5u, msg: @~"trailing characters"})); Err(Error {line: 1u, col: 5u, msg: @~"trailing characters"}));
assert_eq!(from_str(~"falsea"), assert_eq!(from_str("falsea"),
Err(Error {line: 1u, col: 6u, msg: @~"trailing characters"})); Err(Error {line: 1u, col: 6u, msg: @~"trailing characters"}));
assert_eq!(from_str(~"1a"), assert_eq!(from_str("1a"),
Err(Error {line: 1u, col: 2u, msg: @~"trailing characters"})); Err(Error {line: 1u, col: 2u, msg: @~"trailing characters"}));
assert_eq!(from_str(~"[]a"), assert_eq!(from_str("[]a"),
Err(Error {line: 1u, col: 3u, msg: @~"trailing characters"})); Err(Error {line: 1u, col: 3u, msg: @~"trailing characters"}));
assert_eq!(from_str(~"{}a"), assert_eq!(from_str("{}a"),
Err(Error {line: 1u, col: 3u, msg: @~"trailing characters"})); Err(Error {line: 1u, col: 3u, msg: @~"trailing characters"}));
} }
#[test] #[test]
fn test_read_identifiers() { fn test_read_identifiers() {
assert_eq!(from_str(~"n"), assert_eq!(from_str("n"),
Err(Error {line: 1u, col: 2u, msg: @~"invalid syntax"})); Err(Error {line: 1u, col: 2u, msg: @~"invalid syntax"}));
assert_eq!(from_str(~"nul"), assert_eq!(from_str("nul"),
Err(Error {line: 1u, col: 4u, msg: @~"invalid syntax"})); Err(Error {line: 1u, col: 4u, msg: @~"invalid syntax"}));
assert_eq!(from_str(~"t"), assert_eq!(from_str("t"),
Err(Error {line: 1u, col: 2u, msg: @~"invalid syntax"})); Err(Error {line: 1u, col: 2u, msg: @~"invalid syntax"}));
assert_eq!(from_str(~"truz"), assert_eq!(from_str("truz"),
Err(Error {line: 1u, col: 4u, msg: @~"invalid syntax"})); Err(Error {line: 1u, col: 4u, msg: @~"invalid syntax"}));
assert_eq!(from_str(~"f"), assert_eq!(from_str("f"),
Err(Error {line: 1u, col: 2u, msg: @~"invalid syntax"})); Err(Error {line: 1u, col: 2u, msg: @~"invalid syntax"}));
assert_eq!(from_str(~"faz"), assert_eq!(from_str("faz"),
Err(Error {line: 1u, col: 3u, msg: @~"invalid syntax"})); Err(Error {line: 1u, col: 3u, msg: @~"invalid syntax"}));
assert_eq!(from_str(~"null"), Ok(Null)); assert_eq!(from_str("null"), Ok(Null));
assert_eq!(from_str(~"true"), Ok(Boolean(true))); assert_eq!(from_str("true"), Ok(Boolean(true)));
assert_eq!(from_str(~"false"), Ok(Boolean(false))); assert_eq!(from_str("false"), Ok(Boolean(false)));
assert_eq!(from_str(~" null "), Ok(Null)); assert_eq!(from_str(" null "), Ok(Null));
assert_eq!(from_str(~" true "), Ok(Boolean(true))); assert_eq!(from_str(" true "), Ok(Boolean(true)));
assert_eq!(from_str(~" false "), Ok(Boolean(false))); assert_eq!(from_str(" false "), Ok(Boolean(false)));
} }
#[test] #[test]
fn test_decode_identifiers() { fn test_decode_identifiers() {
let mut decoder = Decoder(from_str(~"null").unwrap()); let mut decoder = Decoder(from_str("null").unwrap());
let v: () = Decodable::decode(&mut decoder); let v: () = Decodable::decode(&mut decoder);
assert_eq!(v, ()); assert_eq!(v, ());
let mut decoder = Decoder(from_str(~"true").unwrap()); let mut decoder = Decoder(from_str("true").unwrap());
let v: bool = Decodable::decode(&mut decoder); let v: bool = Decodable::decode(&mut decoder);
assert_eq!(v, true); assert_eq!(v, true);
let mut decoder = Decoder(from_str(~"false").unwrap()); let mut decoder = Decoder(from_str("false").unwrap());
let v: bool = Decodable::decode(&mut decoder); let v: bool = Decodable::decode(&mut decoder);
assert_eq!(v, false); assert_eq!(v, false);
} }
#[test] #[test]
fn test_read_number() { fn test_read_number() {
assert_eq!(from_str(~"+"), assert_eq!(from_str("+"),
Err(Error {line: 1u, col: 1u, msg: @~"invalid syntax"})); Err(Error {line: 1u, col: 1u, msg: @~"invalid syntax"}));
assert_eq!(from_str(~"."), assert_eq!(from_str("."),
Err(Error {line: 1u, col: 1u, msg: @~"invalid syntax"})); Err(Error {line: 1u, col: 1u, msg: @~"invalid syntax"}));
assert_eq!(from_str(~"-"), assert_eq!(from_str("-"),
Err(Error {line: 1u, col: 2u, msg: @~"invalid number"})); Err(Error {line: 1u, col: 2u, msg: @~"invalid number"}));
assert_eq!(from_str(~"00"), assert_eq!(from_str("00"),
Err(Error {line: 1u, col: 2u, msg: @~"invalid number"})); Err(Error {line: 1u, col: 2u, msg: @~"invalid number"}));
assert_eq!(from_str(~"1."), assert_eq!(from_str("1."),
Err(Error {line: 1u, col: 3u, msg: @~"invalid number"})); Err(Error {line: 1u, col: 3u, msg: @~"invalid number"}));
assert_eq!(from_str(~"1e"), assert_eq!(from_str("1e"),
Err(Error {line: 1u, col: 3u, msg: @~"invalid number"})); Err(Error {line: 1u, col: 3u, msg: @~"invalid number"}));
assert_eq!(from_str(~"1e+"), assert_eq!(from_str("1e+"),
Err(Error {line: 1u, col: 4u, msg: @~"invalid number"})); Err(Error {line: 1u, col: 4u, msg: @~"invalid number"}));
assert_eq!(from_str(~"3"), Ok(Number(3f))); assert_eq!(from_str("3"), Ok(Number(3f)));
assert_eq!(from_str(~"3.1"), Ok(Number(3.1f))); assert_eq!(from_str("3.1"), Ok(Number(3.1f)));
assert_eq!(from_str(~"-1.2"), Ok(Number(-1.2f))); assert_eq!(from_str("-1.2"), Ok(Number(-1.2f)));
assert_eq!(from_str(~"0.4"), Ok(Number(0.4f))); assert_eq!(from_str("0.4"), Ok(Number(0.4f)));
assert_eq!(from_str(~"0.4e5"), Ok(Number(0.4e5f))); assert_eq!(from_str("0.4e5"), Ok(Number(0.4e5f)));
assert_eq!(from_str(~"0.4e+15"), Ok(Number(0.4e15f))); assert_eq!(from_str("0.4e+15"), Ok(Number(0.4e15f)));
assert_eq!(from_str(~"0.4e-01"), Ok(Number(0.4e-01f))); assert_eq!(from_str("0.4e-01"), Ok(Number(0.4e-01f)));
assert_eq!(from_str(~" 3 "), Ok(Number(3f))); assert_eq!(from_str(" 3 "), Ok(Number(3f)));
} }
#[test] #[test]
fn test_decode_numbers() { fn test_decode_numbers() {
let mut decoder = Decoder(from_str(~"3").unwrap()); let mut decoder = Decoder(from_str("3").unwrap());
let v: float = Decodable::decode(&mut decoder); let v: float = Decodable::decode(&mut decoder);
assert_eq!(v, 3f); assert_eq!(v, 3f);
let mut decoder = Decoder(from_str(~"3.1").unwrap()); let mut decoder = Decoder(from_str("3.1").unwrap());
let v: float = Decodable::decode(&mut decoder); let v: float = Decodable::decode(&mut decoder);
assert_eq!(v, 3.1f); assert_eq!(v, 3.1f);
let mut decoder = Decoder(from_str(~"-1.2").unwrap()); let mut decoder = Decoder(from_str("-1.2").unwrap());
let v: float = Decodable::decode(&mut decoder); let v: float = Decodable::decode(&mut decoder);
assert_eq!(v, -1.2f); assert_eq!(v, -1.2f);
let mut decoder = Decoder(from_str(~"0.4").unwrap()); let mut decoder = Decoder(from_str("0.4").unwrap());
let v: float = Decodable::decode(&mut decoder); let v: float = Decodable::decode(&mut decoder);
assert_eq!(v, 0.4f); assert_eq!(v, 0.4f);
let mut decoder = Decoder(from_str(~"0.4e5").unwrap()); let mut decoder = Decoder(from_str("0.4e5").unwrap());
let v: float = Decodable::decode(&mut decoder); let v: float = Decodable::decode(&mut decoder);
assert_eq!(v, 0.4e5f); assert_eq!(v, 0.4e5f);
let mut decoder = Decoder(from_str(~"0.4e15").unwrap()); let mut decoder = Decoder(from_str("0.4e15").unwrap());
let v: float = Decodable::decode(&mut decoder); let v: float = Decodable::decode(&mut decoder);
assert_eq!(v, 0.4e15f); assert_eq!(v, 0.4e15f);
let mut decoder = Decoder(from_str(~"0.4e-01").unwrap()); let mut decoder = Decoder(from_str("0.4e-01").unwrap());
let v: float = Decodable::decode(&mut decoder); let v: float = Decodable::decode(&mut decoder);
assert_eq!(v, 0.4e-01f); assert_eq!(v, 0.4e-01f);
} }
#[test] #[test]
fn test_read_str() { fn test_read_str() {
assert_eq!(from_str(~"\""), assert_eq!(from_str("\""),
Err(Error {line: 1u, col: 2u, msg: @~"EOF while parsing string" Err(Error {line: 1u, col: 2u, msg: @~"EOF while parsing string"
})); }));
assert_eq!(from_str(~"\"lol"), assert_eq!(from_str("\"lol"),
Err(Error {line: 1u, col: 5u, msg: @~"EOF while parsing string" Err(Error {line: 1u, col: 5u, msg: @~"EOF while parsing string"
})); }));
assert_eq!(from_str(~"\"\""), Ok(String(~""))); assert_eq!(from_str("\"\""), Ok(String(~"")));
assert_eq!(from_str(~"\"foo\""), Ok(String(~"foo"))); assert_eq!(from_str("\"foo\""), Ok(String(~"foo")));
assert_eq!(from_str(~"\"\\\"\""), Ok(String(~"\""))); assert_eq!(from_str("\"\\\"\""), Ok(String(~"\"")));
assert_eq!(from_str(~"\"\\b\""), Ok(String(~"\x08"))); assert_eq!(from_str("\"\\b\""), Ok(String(~"\x08")));
assert_eq!(from_str(~"\"\\n\""), Ok(String(~"\n"))); assert_eq!(from_str("\"\\n\""), Ok(String(~"\n")));
assert_eq!(from_str(~"\"\\r\""), Ok(String(~"\r"))); assert_eq!(from_str("\"\\r\""), Ok(String(~"\r")));
assert_eq!(from_str(~"\"\\t\""), Ok(String(~"\t"))); assert_eq!(from_str("\"\\t\""), Ok(String(~"\t")));
assert_eq!(from_str(~" \"foo\" "), Ok(String(~"foo"))); assert_eq!(from_str(" \"foo\" "), Ok(String(~"foo")));
assert_eq!(from_str(~"\"\\u12ab\""), Ok(String(~"\u12ab"))); assert_eq!(from_str("\"\\u12ab\""), Ok(String(~"\u12ab")));
assert_eq!(from_str(~"\"\\uAB12\""), Ok(String(~"\uAB12"))); assert_eq!(from_str("\"\\uAB12\""), Ok(String(~"\uAB12")));
} }
#[test] #[test]
fn test_decode_str() { fn test_decode_str() {
let mut decoder = Decoder(from_str(~"\"\"").unwrap()); let mut decoder = Decoder(from_str("\"\"").unwrap());
let v: ~str = Decodable::decode(&mut decoder); let v: ~str = Decodable::decode(&mut decoder);
assert_eq!(v, ~""); assert_eq!(v, ~"");
let mut decoder = Decoder(from_str(~"\"foo\"").unwrap()); let mut decoder = Decoder(from_str("\"foo\"").unwrap());
let v: ~str = Decodable::decode(&mut decoder); let v: ~str = Decodable::decode(&mut decoder);
assert_eq!(v, ~"foo"); assert_eq!(v, ~"foo");
let mut decoder = Decoder(from_str(~"\"\\\"\"").unwrap()); let mut decoder = Decoder(from_str("\"\\\"\"").unwrap());
let v: ~str = Decodable::decode(&mut decoder); let v: ~str = Decodable::decode(&mut decoder);
assert_eq!(v, ~"\""); assert_eq!(v, ~"\"");
let mut decoder = Decoder(from_str(~"\"\\b\"").unwrap()); let mut decoder = Decoder(from_str("\"\\b\"").unwrap());
let v: ~str = Decodable::decode(&mut decoder); let v: ~str = Decodable::decode(&mut decoder);
assert_eq!(v, ~"\x08"); assert_eq!(v, ~"\x08");
let mut decoder = Decoder(from_str(~"\"\\n\"").unwrap()); let mut decoder = Decoder(from_str("\"\\n\"").unwrap());
let v: ~str = Decodable::decode(&mut decoder); let v: ~str = Decodable::decode(&mut decoder);
assert_eq!(v, ~"\n"); assert_eq!(v, ~"\n");
let mut decoder = Decoder(from_str(~"\"\\r\"").unwrap()); let mut decoder = Decoder(from_str("\"\\r\"").unwrap());
let v: ~str = Decodable::decode(&mut decoder); let v: ~str = Decodable::decode(&mut decoder);
assert_eq!(v, ~"\r"); assert_eq!(v, ~"\r");
let mut decoder = Decoder(from_str(~"\"\\t\"").unwrap()); let mut decoder = Decoder(from_str("\"\\t\"").unwrap());
let v: ~str = Decodable::decode(&mut decoder); let v: ~str = Decodable::decode(&mut decoder);
assert_eq!(v, ~"\t"); assert_eq!(v, ~"\t");
let mut decoder = Decoder(from_str(~"\"\\u12ab\"").unwrap()); let mut decoder = Decoder(from_str("\"\\u12ab\"").unwrap());
let v: ~str = Decodable::decode(&mut decoder); let v: ~str = Decodable::decode(&mut decoder);
assert_eq!(v, ~"\u12ab"); assert_eq!(v, ~"\u12ab");
let mut decoder = Decoder(from_str(~"\"\\uAB12\"").unwrap()); let mut decoder = Decoder(from_str("\"\\uAB12\"").unwrap());
let v: ~str = Decodable::decode(&mut decoder); let v: ~str = Decodable::decode(&mut decoder);
assert_eq!(v, ~"\uAB12"); assert_eq!(v, ~"\uAB12");
} }
#[test] #[test]
fn test_read_list() { fn test_read_list() {
assert_eq!(from_str(~"["), assert_eq!(from_str("["),
Err(Error {line: 1u, col: 2u, msg: @~"EOF while parsing value"})); Err(Error {line: 1u, col: 2u, msg: @~"EOF while parsing value"}));
assert_eq!(from_str(~"[1"), assert_eq!(from_str("[1"),
Err(Error {line: 1u, col: 3u, msg: @~"EOF while parsing list"})); Err(Error {line: 1u, col: 3u, msg: @~"EOF while parsing list"}));
assert_eq!(from_str(~"[1,"), assert_eq!(from_str("[1,"),
Err(Error {line: 1u, col: 4u, msg: @~"EOF while parsing value"})); Err(Error {line: 1u, col: 4u, msg: @~"EOF while parsing value"}));
assert_eq!(from_str(~"[1,]"), assert_eq!(from_str("[1,]"),
Err(Error {line: 1u, col: 4u, msg: @~"invalid syntax"})); Err(Error {line: 1u, col: 4u, msg: @~"invalid syntax"}));
assert_eq!(from_str(~"[6 7]"), assert_eq!(from_str("[6 7]"),
Err(Error {line: 1u, col: 4u, msg: @~"expected `,` or `]`"})); Err(Error {line: 1u, col: 4u, msg: @~"expected `,` or `]`"}));
assert_eq!(from_str(~"[]"), Ok(List(~[]))); assert_eq!(from_str("[]"), Ok(List(~[])));
assert_eq!(from_str(~"[ ]"), Ok(List(~[]))); assert_eq!(from_str("[ ]"), Ok(List(~[])));
assert_eq!(from_str(~"[true]"), Ok(List(~[Boolean(true)]))); assert_eq!(from_str("[true]"), Ok(List(~[Boolean(true)])));
assert_eq!(from_str(~"[ false ]"), Ok(List(~[Boolean(false)]))); assert_eq!(from_str("[ false ]"), Ok(List(~[Boolean(false)])));
assert_eq!(from_str(~"[null]"), Ok(List(~[Null]))); assert_eq!(from_str("[null]"), Ok(List(~[Null])));
assert_eq!(from_str(~"[3, 1]"), assert_eq!(from_str("[3, 1]"),
Ok(List(~[Number(3f), Number(1f)]))); Ok(List(~[Number(3f), Number(1f)])));
assert_eq!(from_str(~"\n[3, 2]\n"), assert_eq!(from_str("\n[3, 2]\n"),
Ok(List(~[Number(3f), Number(2f)]))); Ok(List(~[Number(3f), Number(2f)])));
assert_eq!(from_str(~"[2, [4, 1]]"), assert_eq!(from_str("[2, [4, 1]]"),
Ok(List(~[Number(2f), List(~[Number(4f), Number(1f)])]))); Ok(List(~[Number(2f), List(~[Number(4f), Number(1f)])])));
} }
#[test] #[test]
fn test_decode_list() { fn test_decode_list() {
let mut decoder = Decoder(from_str(~"[]").unwrap()); let mut decoder = Decoder(from_str("[]").unwrap());
let v: ~[()] = Decodable::decode(&mut decoder); let v: ~[()] = Decodable::decode(&mut decoder);
assert_eq!(v, ~[]); assert_eq!(v, ~[]);
let mut decoder = Decoder(from_str(~"[null]").unwrap()); let mut decoder = Decoder(from_str("[null]").unwrap());
let v: ~[()] = Decodable::decode(&mut decoder); let v: ~[()] = Decodable::decode(&mut decoder);
assert_eq!(v, ~[()]); assert_eq!(v, ~[()]);
let mut decoder = Decoder(from_str(~"[true]").unwrap()); let mut decoder = Decoder(from_str("[true]").unwrap());
let v: ~[bool] = Decodable::decode(&mut decoder); let v: ~[bool] = Decodable::decode(&mut decoder);
assert_eq!(v, ~[true]); assert_eq!(v, ~[true]);
let mut decoder = Decoder(from_str(~"[true]").unwrap()); let mut decoder = Decoder(from_str("[true]").unwrap());
let v: ~[bool] = Decodable::decode(&mut decoder); let v: ~[bool] = Decodable::decode(&mut decoder);
assert_eq!(v, ~[true]); assert_eq!(v, ~[true]);
let mut decoder = Decoder(from_str(~"[3, 1]").unwrap()); let mut decoder = Decoder(from_str("[3, 1]").unwrap());
let v: ~[int] = Decodable::decode(&mut decoder); let v: ~[int] = Decodable::decode(&mut decoder);
assert_eq!(v, ~[3, 1]); assert_eq!(v, ~[3, 1]);
let mut decoder = Decoder(from_str(~"[[3], [1, 2]]").unwrap()); let mut decoder = Decoder(from_str("[[3], [1, 2]]").unwrap());
let v: ~[~[uint]] = Decodable::decode(&mut decoder); let v: ~[~[uint]] = Decodable::decode(&mut decoder);
assert_eq!(v, ~[~[3], ~[1, 2]]); assert_eq!(v, ~[~[3], ~[1, 2]]);
} }
#[test] #[test]
fn test_read_object() { fn test_read_object() {
assert_eq!(from_str(~"{"), assert_eq!(from_str("{"),
Err(Error { Err(Error {
line: 1u, line: 1u,
col: 2u, col: 2u,
msg: @~"EOF while parsing object"})); msg: @~"EOF while parsing object"}));
assert_eq!(from_str(~"{ "), assert_eq!(from_str("{ "),
Err(Error { Err(Error {
line: 1u, line: 1u,
col: 3u, col: 3u,
msg: @~"EOF while parsing object"})); msg: @~"EOF while parsing object"}));
assert_eq!(from_str(~"{1"), assert_eq!(from_str("{1"),
Err(Error { Err(Error {
line: 1u, line: 1u,
col: 2u, col: 2u,
msg: @~"key must be a string"})); msg: @~"key must be a string"}));
assert_eq!(from_str(~"{ \"a\""), assert_eq!(from_str("{ \"a\""),
Err(Error { Err(Error {
line: 1u, line: 1u,
col: 6u, col: 6u,
msg: @~"EOF while parsing object"})); msg: @~"EOF while parsing object"}));
assert_eq!(from_str(~"{\"a\""), assert_eq!(from_str("{\"a\""),
Err(Error { Err(Error {
line: 1u, line: 1u,
col: 5u, col: 5u,
msg: @~"EOF while parsing object"})); msg: @~"EOF while parsing object"}));
assert_eq!(from_str(~"{\"a\" "), assert_eq!(from_str("{\"a\" "),
Err(Error { Err(Error {
line: 1u, line: 1u,
col: 6u, col: 6u,
msg: @~"EOF while parsing object"})); msg: @~"EOF while parsing object"}));
assert_eq!(from_str(~"{\"a\" 1"), assert_eq!(from_str("{\"a\" 1"),
Err(Error {line: 1u, col: 6u, msg: @~"expected `:`"})); Err(Error {line: 1u, col: 6u, msg: @~"expected `:`"}));
assert_eq!(from_str(~"{\"a\":"), assert_eq!(from_str("{\"a\":"),
Err(Error {line: 1u, col: 6u, msg: @~"EOF while parsing value"})); Err(Error {line: 1u, col: 6u, msg: @~"EOF while parsing value"}));
assert_eq!(from_str(~"{\"a\":1"), assert_eq!(from_str("{\"a\":1"),
Err(Error { Err(Error {
line: 1u, line: 1u,
col: 7u, col: 7u,
msg: @~"EOF while parsing object"})); msg: @~"EOF while parsing object"}));
assert_eq!(from_str(~"{\"a\":1 1"), assert_eq!(from_str("{\"a\":1 1"),
Err(Error {line: 1u, col: 8u, msg: @~"expected `,` or `}`"})); Err(Error {line: 1u, col: 8u, msg: @~"expected `,` or `}`"}));
assert_eq!(from_str(~"{\"a\":1,"), assert_eq!(from_str("{\"a\":1,"),
Err(Error { Err(Error {
line: 1u, line: 1u,
col: 8u, col: 8u,
msg: @~"EOF while parsing object"})); msg: @~"EOF while parsing object"}));
assert_eq!(result::unwrap(from_str(~"{}")), mk_object(~[])); assert_eq!(result::unwrap(from_str("{}")), mk_object([]));
assert_eq!(result::unwrap(from_str(~"{\"a\": 3}")), assert_eq!(result::unwrap(from_str("{\"a\": 3}")),
mk_object(~[(~"a", Number(3.0f))])); mk_object([(~"a", Number(3.0f))]));
assert_eq!(result::unwrap(from_str( assert_eq!(result::unwrap(from_str(
~"{ \"a\": null, \"b\" : true }")), "{ \"a\": null, \"b\" : true }")),
mk_object(~[ mk_object([
(~"a", Null), (~"a", Null),
(~"b", Boolean(true))])); (~"b", Boolean(true))]));
assert_eq!(result::unwrap( assert_eq!(result::unwrap(
from_str(~"\n{ \"a\": null, \"b\" : true }\n")), from_str("\n{ \"a\": null, \"b\" : true }\n")),
mk_object(~[ mk_object([
(~"a", Null), (~"a", Null),
(~"b", Boolean(true))])); (~"b", Boolean(true))]));
assert_eq!(result::unwrap(from_str( assert_eq!(result::unwrap(from_str(
~"{\"a\" : 1.0 ,\"b\": [ true ]}")), "{\"a\" : 1.0 ,\"b\": [ true ]}")),
mk_object(~[ mk_object([
(~"a", Number(1.0)), (~"a", Number(1.0)),
(~"b", List(~[Boolean(true)])) (~"b", List(~[Boolean(true)]))
])); ]));
@ -1887,13 +1887,13 @@ mod tests {
~"{ \"c\": {\"d\": null} } " + ~"{ \"c\": {\"d\": null} } " +
~"]" + ~"]" +
~"}")), ~"}")),
mk_object(~[ mk_object([
(~"a", Number(1.0f)), (~"a", Number(1.0f)),
(~"b", List(~[ (~"b", List(~[
Boolean(true), Boolean(true),
String(~"foo\nbar"), String(~"foo\nbar"),
mk_object(~[ mk_object([
(~"c", mk_object(~[(~"d", Null)])) (~"c", mk_object([(~"d", Null)]))
]) ])
])) ]))
])); ]));
@ -1920,23 +1920,23 @@ mod tests {
#[test] #[test]
fn test_decode_option() { fn test_decode_option() {
let mut decoder = Decoder(from_str(~"null").unwrap()); let mut decoder = Decoder(from_str("null").unwrap());
let value: Option<~str> = Decodable::decode(&mut decoder); let value: Option<~str> = Decodable::decode(&mut decoder);
assert_eq!(value, None); assert_eq!(value, None);
let mut decoder = Decoder(from_str(~"\"jodhpurs\"").unwrap()); let mut decoder = Decoder(from_str("\"jodhpurs\"").unwrap());
let value: Option<~str> = Decodable::decode(&mut decoder); let value: Option<~str> = Decodable::decode(&mut decoder);
assert_eq!(value, Some(~"jodhpurs")); assert_eq!(value, Some(~"jodhpurs"));
} }
#[test] #[test]
fn test_decode_enum() { fn test_decode_enum() {
let mut decoder = Decoder(from_str(~"\"Dog\"").unwrap()); let mut decoder = Decoder(from_str("\"Dog\"").unwrap());
let value: Animal = Decodable::decode(&mut decoder); let value: Animal = Decodable::decode(&mut decoder);
assert_eq!(value, Dog); assert_eq!(value, Dog);
let mut decoder = let mut decoder =
Decoder(from_str(~"[\"Frog\",\"Henry\",349]").unwrap()); Decoder(from_str("[\"Frog\",\"Henry\",349]").unwrap());
let value: Animal = Decodable::decode(&mut decoder); let value: Animal = Decodable::decode(&mut decoder);
assert_eq!(value, Frog(~"Henry", 349)); assert_eq!(value, Frog(~"Henry", 349));
} }
@ -1953,7 +1953,7 @@ mod tests {
#[test] #[test]
fn test_multiline_errors() { fn test_multiline_errors() {
assert_eq!(from_str(~"{\n \"foo\":\n \"bar\""), assert_eq!(from_str("{\n \"foo\":\n \"bar\""),
Err(Error { Err(Error {
line: 3u, line: 3u,
col: 8u, col: 8u,

View file

@ -184,9 +184,9 @@ mod tests {
#[test] #[test]
fn test_is_empty() { fn test_is_empty() {
let empty : @list::List<int> = from_vec(~[]); let empty : @list::List<int> = from_vec([]);
let full1 = from_vec(~[1]); let full1 = from_vec([1]);
let full2 = from_vec(~['r', 'u']); let full2 = from_vec(['r', 'u']);
assert!(is_empty(empty)); assert!(is_empty(empty));
assert!(!is_empty(full1)); assert!(!is_empty(full1));
@ -195,7 +195,7 @@ mod tests {
#[test] #[test]
fn test_from_vec() { fn test_from_vec() {
let l = from_vec(~[0, 1, 2]); let l = from_vec([0, 1, 2]);
assert_eq!(head(l), 0); assert_eq!(head(l), 0);
@ -208,14 +208,14 @@ mod tests {
#[test] #[test]
fn test_from_vec_empty() { fn test_from_vec_empty() {
let empty : @list::List<int> = from_vec(~[]); let empty : @list::List<int> = from_vec([]);
assert_eq!(empty, @list::Nil::<int>); assert_eq!(empty, @list::Nil::<int>);
} }
#[test] #[test]
fn test_foldl() { fn test_foldl() {
fn add(a: &uint, b: &int) -> uint { return *a + (*b as uint); } fn add(a: &uint, b: &int) -> uint { return *a + (*b as uint); }
let l = from_vec(~[0, 1, 2, 3, 4]); let l = from_vec([0, 1, 2, 3, 4]);
let empty = @list::Nil::<int>; let empty = @list::Nil::<int>;
assert_eq!(list::foldl(0u, l, add), 10u); assert_eq!(list::foldl(0u, l, add), 10u);
assert_eq!(list::foldl(0u, empty, add), 0u); assert_eq!(list::foldl(0u, empty, add), 0u);
@ -226,21 +226,21 @@ mod tests {
fn sub(a: &int, b: &int) -> int { fn sub(a: &int, b: &int) -> int {
*a - *b *a - *b
} }
let l = from_vec(~[1, 2, 3, 4]); let l = from_vec([1, 2, 3, 4]);
assert_eq!(list::foldl(0, l, sub), -10); assert_eq!(list::foldl(0, l, sub), -10);
} }
#[test] #[test]
fn test_find_success() { fn test_find_success() {
fn match_(i: &int) -> bool { return *i == 2; } fn match_(i: &int) -> bool { return *i == 2; }
let l = from_vec(~[0, 1, 2]); let l = from_vec([0, 1, 2]);
assert_eq!(list::find(l, match_), option::Some(2)); assert_eq!(list::find(l, match_), option::Some(2));
} }
#[test] #[test]
fn test_find_fail() { fn test_find_fail() {
fn match_(_i: &int) -> bool { return false; } fn match_(_i: &int) -> bool { return false; }
let l = from_vec(~[0, 1, 2]); let l = from_vec([0, 1, 2]);
let empty = @list::Nil::<int>; let empty = @list::Nil::<int>;
assert_eq!(list::find(l, match_), option::None::<int>); assert_eq!(list::find(l, match_), option::None::<int>);
assert_eq!(list::find(empty, match_), option::None::<int>); assert_eq!(list::find(empty, match_), option::None::<int>);
@ -248,7 +248,7 @@ mod tests {
#[test] #[test]
fn test_has() { fn test_has() {
let l = from_vec(~[5, 8, 6]); let l = from_vec([5, 8, 6]);
let empty = @list::Nil::<int>; let empty = @list::Nil::<int>;
assert!((list::has(l, 5))); assert!((list::has(l, 5)));
assert!((!list::has(l, 7))); assert!((!list::has(l, 7)));
@ -258,7 +258,7 @@ mod tests {
#[test] #[test]
fn test_len() { fn test_len() {
let l = from_vec(~[0, 1, 2]); let l = from_vec([0, 1, 2]);
let empty = @list::Nil::<int>; let empty = @list::Nil::<int>;
assert_eq!(list::len(l), 3u); assert_eq!(list::len(l), 3u);
assert_eq!(list::len(empty), 0u); assert_eq!(list::len(empty), 0u);
@ -266,7 +266,7 @@ mod tests {
#[test] #[test]
fn test_append() { fn test_append() {
assert!(from_vec(~[1,2,3,4]) assert!(from_vec([1,2,3,4])
== list::append(list::from_vec(~[1,2]), list::from_vec(~[3,4]))); == list::append(list::from_vec([1,2]), list::from_vec([3,4])));
} }
} }

View file

@ -127,17 +127,17 @@ pub fn md4_text(msg: &str) -> ~str { md4_str(str::to_bytes(msg)) }
#[test] #[test]
fn test_md4() { fn test_md4() {
assert_eq!(md4_text(~""), ~"31d6cfe0d16ae931b73c59d7e0c089c0"); assert_eq!(md4_text(""), ~"31d6cfe0d16ae931b73c59d7e0c089c0");
assert_eq!(md4_text(~"a"), ~"bde52cb31de33e46245e05fbdbd6fb24"); assert_eq!(md4_text("a"), ~"bde52cb31de33e46245e05fbdbd6fb24");
assert_eq!(md4_text(~"abc"), ~"a448017aaf21d8525fc10ae87aa6729d"); assert_eq!(md4_text("abc"), ~"a448017aaf21d8525fc10ae87aa6729d");
assert!(md4_text(~"message digest") == assert!(md4_text("message digest") ==
~"d9130a8164549fe818874806e1c7014b"); ~"d9130a8164549fe818874806e1c7014b");
assert!(md4_text(~"abcdefghijklmnopqrstuvwxyz") == assert!(md4_text("abcdefghijklmnopqrstuvwxyz") ==
~"d79e1c308aa5bbcdeea8ed63df412da9"); ~"d79e1c308aa5bbcdeea8ed63df412da9");
assert!(md4_text( assert!(md4_text(
~"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\
0123456789") == ~"043f8582f241db351ce627e153e7f0e4"); 0123456789") == ~"043f8582f241db351ce627e153e7f0e4");
assert!(md4_text(~"1234567890123456789012345678901234567890123456789\ assert!(md4_text("1234567890123456789012345678901234567890123456789\
0123456789012345678901234567890") == 0123456789012345678901234567890") ==
~"e33b4ddc9c38f2199c3e7b164fcc0536"); ~"e33b4ddc9c38f2199c3e7b164fcc0536");
} }

View file

@ -393,7 +393,7 @@ mod test {
} }
#[test] #[test]
fn test_ip_ipv4_bad_parse() { fn test_ip_ipv4_bad_parse() {
match v4::try_parse_addr(~"b4df00d") { match v4::try_parse_addr("b4df00d") {
result::Err(ref err_info) => { result::Err(ref err_info) => {
debug!("got error as expected %?", err_info); debug!("got error as expected %?", err_info);
assert!(true); assert!(true);
@ -406,7 +406,7 @@ mod test {
#[test] #[test]
#[ignore(target_os="win32")] #[ignore(target_os="win32")]
fn test_ip_ipv6_bad_parse() { fn test_ip_ipv6_bad_parse() {
match v6::try_parse_addr(~"::,~2234k;") { match v6::try_parse_addr("::,~2234k;") {
result::Err(ref err_info) => { result::Err(ref err_info) => {
debug!("got error as expected %?", err_info); debug!("got error as expected %?", err_info);
assert!(true); assert!(true);

View file

@ -1630,7 +1630,7 @@ mod test {
assert_eq!(net::ip::get_port(&sock.get_peer_addr()), 8887); assert_eq!(net::ip::get_port(&sock.get_peer_addr()), 8887);
// Fulfill the protocol the test server expects // Fulfill the protocol the test server expects
let resp_bytes = str::to_bytes(~"ping"); let resp_bytes = str::to_bytes("ping");
tcp_write_single(&sock, resp_bytes); tcp_write_single(&sock, resp_bytes);
debug!("message sent"); debug!("message sent");
sock.read(0u); sock.read(0u);

View file

@ -716,11 +716,11 @@ impl IterBytes for Url {
#[test] #[test]
fn test_split_char_first() { fn test_split_char_first() {
let (u,v) = split_char_first(~"hello, sweet world", ','); let (u,v) = split_char_first("hello, sweet world", ',');
assert_eq!(u, ~"hello"); assert_eq!(u, ~"hello");
assert_eq!(v, ~" sweet world"); assert_eq!(v, ~" sweet world");
let (u,v) = split_char_first(~"hello sweet world", ','); let (u,v) = split_char_first("hello sweet world", ',');
assert_eq!(u, ~"hello sweet world"); assert_eq!(u, ~"hello sweet world");
assert_eq!(v, ~""); assert_eq!(v, ~"");
} }
@ -774,9 +774,9 @@ fn test_get_authority() {
"//2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000:00").is_err()); "//2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000:00").is_err());
// these parse as empty, because they don't start with '//' // these parse as empty, because they don't start with '//'
let (_, h, _, _) = get_authority(~"user:pass@rust-lang").unwrap(); let (_, h, _, _) = get_authority("user:pass@rust-lang").unwrap();
assert_eq!(h, ~""); assert_eq!(h, ~"");
let (_, h, _, _) = get_authority(~"rust-lang.org").unwrap(); let (_, h, _, _) = get_authority("rust-lang.org").unwrap();
assert_eq!(h, ~""); assert_eq!(h, ~"");
} }
@ -788,12 +788,12 @@ fn test_get_path() {
let (p, r) = get_path("test@email.com#fragment", false).unwrap(); let (p, r) = get_path("test@email.com#fragment", false).unwrap();
assert_eq!(p, ~"test@email.com"); assert_eq!(p, ~"test@email.com");
assert_eq!(r, ~"#fragment"); assert_eq!(r, ~"#fragment");
let (p, r) = get_path(~"/gen/:addr=?q=v", false).unwrap(); let (p, r) = get_path("/gen/:addr=?q=v", false).unwrap();
assert_eq!(p, ~"/gen/:addr="); assert_eq!(p, ~"/gen/:addr=");
assert_eq!(r, ~"?q=v"); assert_eq!(r, ~"?q=v");
//failure cases //failure cases
assert!(get_path(~"something?q", true).is_err()); assert!(get_path("something?q", true).is_err());
} }
#[cfg(test)] #[cfg(test)]
@ -1058,7 +1058,7 @@ mod tests {
// FIXME #4449: Commented out because this causes an ICE, but only // FIXME #4449: Commented out because this causes an ICE, but only
// on FreeBSD // on FreeBSD
/* /*
assert_eq!(decode_form_urlencoded(~[]).len(), 0); assert_eq!(decode_form_urlencoded([]).len(), 0);
let s = str::to_bytes("a=1&foo+bar=abc&foo+bar=12+%3D+34"); let s = str::to_bytes("a=1&foo+bar=abc&foo+bar=12+%3D+34");
let form = decode_form_urlencoded(s); let form = decode_form_urlencoded(s);

View file

@ -1156,12 +1156,12 @@ mod biguint_tests {
fn check(slice: &[BigDigit], data: &[BigDigit]) { fn check(slice: &[BigDigit], data: &[BigDigit]) {
assert!(data == BigUint::from_slice(slice).data); assert!(data == BigUint::from_slice(slice).data);
} }
check(~[1], ~[1]); check([1], [1]);
check(~[0, 0, 0], ~[]); check([0, 0, 0], []);
check(~[1, 2, 0, 0], ~[1, 2]); check([1, 2, 0, 0], [1, 2]);
check(~[0, 0, 1, 2], ~[0, 0, 1, 2]); check([0, 0, 1, 2], [0, 0, 1, 2]);
check(~[0, 0, 1, 2, 0, 0], ~[0, 0, 1, 2]); check([0, 0, 1, 2, 0, 0], [0, 0, 1, 2]);
check(~[-1], ~[-1]); check([-1], [-1]);
} }
#[test] #[test]
@ -1579,9 +1579,9 @@ mod biguint_tests {
} }
} }
assert_eq!(FromStrRadix::from_str_radix::<BigUint>(~"Z", 10), None); assert_eq!(FromStrRadix::from_str_radix::<BigUint>("Z", 10), None);
assert_eq!(FromStrRadix::from_str_radix::<BigUint>(~"_", 2), None); assert_eq!(FromStrRadix::from_str_radix::<BigUint>("_", 2), None);
assert_eq!(FromStrRadix::from_str_radix::<BigUint>(~"-1", 10), None); assert_eq!(FromStrRadix::from_str_radix::<BigUint>("-1", 10), None);
} }
#[test] #[test]

View file

@ -14,7 +14,6 @@ use core::prelude::*;
use core::old_iter::BaseIter; use core::old_iter::BaseIter;
use core::unstable::intrinsics::{move_val_init, init}; use core::unstable::intrinsics::{move_val_init, init};
use core::unstable::intrinsics::uninit;
use core::util::{replace, swap}; use core::util::{replace, swap};
pub struct PriorityQueue<T> { pub struct PriorityQueue<T> {

View file

@ -295,7 +295,7 @@ mod tests {
let mut i = 0; let mut i = 0;
let mut rs = ~""; let mut rs = ~"";
while i < 100000 { while i < 100000 {
str::push_str(&mut rs, ~"aaaaaaaaaa"); rs.push_str("aaaaaaaaaa");
i += 1; i += 1;
} }
return rs; return rs;

View file

@ -895,7 +895,7 @@ mod tests {
#[test] #[test]
fn test_merge_sort_mutable() { fn test_merge_sort_mutable() {
pub fn le(a: &int, b: &int) -> bool { *a <= *b } pub fn le(a: &int, b: &int) -> bool { *a <= *b }
let mut v1 = ~[3, 2, 1]; let v1 = ~[3, 2, 1];
let v2 = merge_sort(v1, le); let v2 = merge_sort(v1, le);
assert_eq!(v2, ~[1, 2, 3]); assert_eq!(v2, ~[1, 2, 3]);
} }

View file

@ -27,7 +27,6 @@ not required in or otherwise suitable for the core library.
#[crate_type = "lib"]; #[crate_type = "lib"];
#[deny(non_camel_case_types)]; #[deny(non_camel_case_types)];
#[allow(unnecessary_allocation)];
#[no_core]; #[no_core];
#[no_std]; #[no_std];

View file

@ -394,8 +394,8 @@ fn should_sort_failures_before_printing_them() {
print_failures(st); print_failures(st);
}; };
let apos = str::find_str(s, ~"a").get(); let apos = str::find_str(s, "a").get();
let bpos = str::find_str(s, ~"b").get(); let bpos = str::find_str(s, "b").get();
assert!(apos < bpos); assert!(apos < bpos);
} }

View file

@ -899,7 +899,7 @@ mod tests {
} }
fn test_at_utc() { fn test_at_utc() {
os::setenv(~"TZ", ~"America/Los_Angeles"); os::setenv("TZ", "America/Los_Angeles");
tzset(); tzset();
let time = ::time::Timespec::new(1234567890, 54321); let time = ::time::Timespec::new(1234567890, 54321);
@ -920,7 +920,7 @@ mod tests {
} }
fn test_at() { fn test_at() {
os::setenv(~"TZ", ~"America/Los_Angeles"); os::setenv("TZ", "America/Los_Angeles");
tzset(); tzset();
let time = ::time::Timespec::new(1234567890, 54321); let time = ::time::Timespec::new(1234567890, 54321);
@ -948,7 +948,7 @@ mod tests {
} }
fn test_to_timespec() { fn test_to_timespec() {
os::setenv(~"TZ", ~"America/Los_Angeles"); os::setenv("TZ", "America/Los_Angeles");
tzset(); tzset();
let time = ::time::Timespec::new(1234567890, 54321); let time = ::time::Timespec::new(1234567890, 54321);
@ -959,7 +959,7 @@ mod tests {
} }
fn test_conversions() { fn test_conversions() {
os::setenv(~"TZ", ~"America/Los_Angeles"); os::setenv("TZ", "America/Los_Angeles");
tzset(); tzset();
let time = ::time::Timespec::new(1234567890, 54321); let time = ::time::Timespec::new(1234567890, 54321);
@ -975,10 +975,10 @@ mod tests {
} }
fn test_strptime() { fn test_strptime() {
os::setenv(~"TZ", ~"America/Los_Angeles"); os::setenv("TZ", "America/Los_Angeles");
tzset(); tzset();
match strptime(~"", ~"") { match strptime("", "") {
Ok(ref tm) => { Ok(ref tm) => {
assert!(tm.tm_sec == 0_i32); assert!(tm.tm_sec == 0_i32);
assert!(tm.tm_min == 0_i32); assert!(tm.tm_min == 0_i32);
@ -995,12 +995,12 @@ mod tests {
Err(_) => () Err(_) => ()
} }
let format = ~"%a %b %e %T %Y"; let format = "%a %b %e %T %Y";
assert_eq!(strptime(~"", format), Err(~"Invalid time")); assert_eq!(strptime("", format), Err(~"Invalid time"));
assert!(strptime(~"Fri Feb 13 15:31:30", format) assert!(strptime("Fri Feb 13 15:31:30", format)
== Err(~"Invalid time")); == Err(~"Invalid time"));
match strptime(~"Fri Feb 13 15:31:30 2009", format) { match strptime("Fri Feb 13 15:31:30 2009", format) {
Err(copy e) => fail!(e), Err(copy e) => fail!(e),
Ok(ref tm) => { Ok(ref tm) => {
assert!(tm.tm_sec == 30_i32); assert!(tm.tm_sec == 30_i32);
@ -1034,7 +1034,7 @@ mod tests {
~"Friday", ~"Friday",
~"Saturday" ~"Saturday"
].each |day| { ].each |day| {
assert!(test(*day, ~"%A")); assert!(test(*day, "%A"));
} }
for [ for [
@ -1046,7 +1046,7 @@ mod tests {
~"Fri", ~"Fri",
~"Sat" ~"Sat"
].each |day| { ].each |day| {
assert!(test(*day, ~"%a")); assert!(test(*day, "%a"));
} }
for [ for [
@ -1063,7 +1063,7 @@ mod tests {
~"November", ~"November",
~"December" ~"December"
].each |day| { ].each |day| {
assert!(test(*day, ~"%B")); assert!(test(*day, "%B"));
} }
for [ for [
@ -1080,60 +1080,60 @@ mod tests {
~"Nov", ~"Nov",
~"Dec" ~"Dec"
].each |day| { ].each |day| {
assert!(test(*day, ~"%b")); assert!(test(*day, "%b"));
} }
assert!(test(~"19", ~"%C")); assert!(test("19", "%C"));
assert!(test(~"Fri Feb 13 23:31:30 2009", ~"%c")); assert!(test("Fri Feb 13 23:31:30 2009", "%c"));
assert!(test(~"02/13/09", ~"%D")); assert!(test("02/13/09", "%D"));
assert!(test(~"03", ~"%d")); assert!(test("03", "%d"));
assert!(test(~"13", ~"%d")); assert!(test("13", "%d"));
assert!(test(~" 3", ~"%e")); assert!(test(" 3", "%e"));
assert!(test(~"13", ~"%e")); assert!(test("13", "%e"));
assert!(test(~"2009-02-13", ~"%F")); assert!(test("2009-02-13", "%F"));
assert!(test(~"03", ~"%H")); assert!(test("03", "%H"));
assert!(test(~"13", ~"%H")); assert!(test("13", "%H"));
assert!(test(~"03", ~"%I")); // FIXME (#2350): flesh out assert!(test("03", "%I")); // FIXME (#2350): flesh out
assert!(test(~"11", ~"%I")); // FIXME (#2350): flesh out assert!(test("11", "%I")); // FIXME (#2350): flesh out
assert!(test(~"044", ~"%j")); assert!(test("044", "%j"));
assert!(test(~" 3", ~"%k")); assert!(test(" 3", "%k"));
assert!(test(~"13", ~"%k")); assert!(test("13", "%k"));
assert!(test(~" 1", ~"%l")); assert!(test(" 1", "%l"));
assert!(test(~"11", ~"%l")); assert!(test("11", "%l"));
assert!(test(~"03", ~"%M")); assert!(test("03", "%M"));
assert!(test(~"13", ~"%M")); assert!(test("13", "%M"));
assert!(test(~"\n", ~"%n")); assert!(test("\n", "%n"));
assert!(test(~"am", ~"%P")); assert!(test("am", "%P"));
assert!(test(~"pm", ~"%P")); assert!(test("pm", "%P"));
assert!(test(~"AM", ~"%p")); assert!(test("AM", "%p"));
assert!(test(~"PM", ~"%p")); assert!(test("PM", "%p"));
assert!(test(~"23:31", ~"%R")); assert!(test("23:31", "%R"));
assert!(test(~"11:31:30 AM", ~"%r")); assert!(test("11:31:30 AM", "%r"));
assert!(test(~"11:31:30 PM", ~"%r")); assert!(test("11:31:30 PM", "%r"));
assert!(test(~"03", ~"%S")); assert!(test("03", "%S"));
assert!(test(~"13", ~"%S")); assert!(test("13", "%S"));
assert!(test(~"15:31:30", ~"%T")); assert!(test("15:31:30", "%T"));
assert!(test(~"\t", ~"%t")); assert!(test("\t", "%t"));
assert!(test(~"1", ~"%u")); assert!(test("1", "%u"));
assert!(test(~"7", ~"%u")); assert!(test("7", "%u"));
assert!(test(~"13-Feb-2009", ~"%v")); assert!(test("13-Feb-2009", "%v"));
assert!(test(~"0", ~"%w")); assert!(test("0", "%w"));
assert!(test(~"6", ~"%w")); assert!(test("6", "%w"));
assert!(test(~"2009", ~"%Y")); assert!(test("2009", "%Y"));
assert!(test(~"09", ~"%y")); assert!(test("09", "%y"));
assert!(result::unwrap(strptime(~"UTC", ~"%Z")).tm_zone == assert!(result::unwrap(strptime("UTC", "%Z")).tm_zone ==
~"UTC"); ~"UTC");
assert!(result::unwrap(strptime(~"PST", ~"%Z")).tm_zone == assert!(result::unwrap(strptime("PST", "%Z")).tm_zone ==
~""); ~"");
assert!(result::unwrap(strptime(~"-0000", ~"%z")).tm_gmtoff == assert!(result::unwrap(strptime("-0000", "%z")).tm_gmtoff ==
0); 0);
assert!(result::unwrap(strptime(~"-0800", ~"%z")).tm_gmtoff == assert!(result::unwrap(strptime("-0800", "%z")).tm_gmtoff ==
0); 0);
assert!(test(~"%", ~"%%")); assert!(test("%", "%%"));
} }
fn test_ctime() { fn test_ctime() {
os::setenv(~"TZ", ~"America/Los_Angeles"); os::setenv("TZ", "America/Los_Angeles");
tzset(); tzset();
let time = ::time::Timespec::new(1234567890, 54321); let time = ::time::Timespec::new(1234567890, 54321);
@ -1147,60 +1147,60 @@ mod tests {
} }
fn test_strftime() { fn test_strftime() {
os::setenv(~"TZ", ~"America/Los_Angeles"); os::setenv("TZ", "America/Los_Angeles");
tzset(); tzset();
let time = ::time::Timespec::new(1234567890, 54321); let time = ::time::Timespec::new(1234567890, 54321);
let utc = at_utc(time); let utc = at_utc(time);
let local = at(time); let local = at(time);
assert_eq!(local.strftime(~""), ~""); assert_eq!(local.strftime(""), ~"");
assert_eq!(local.strftime(~"%A"), ~"Friday"); assert_eq!(local.strftime("%A"), ~"Friday");
assert_eq!(local.strftime(~"%a"), ~"Fri"); assert_eq!(local.strftime("%a"), ~"Fri");
assert_eq!(local.strftime(~"%B"), ~"February"); assert_eq!(local.strftime("%B"), ~"February");
assert_eq!(local.strftime(~"%b"), ~"Feb"); assert_eq!(local.strftime("%b"), ~"Feb");
assert_eq!(local.strftime(~"%C"), ~"20"); assert_eq!(local.strftime("%C"), ~"20");
assert_eq!(local.strftime(~"%c"), ~"Fri Feb 13 15:31:30 2009"); assert_eq!(local.strftime("%c"), ~"Fri Feb 13 15:31:30 2009");
assert_eq!(local.strftime(~"%D"), ~"02/13/09"); assert_eq!(local.strftime("%D"), ~"02/13/09");
assert_eq!(local.strftime(~"%d"), ~"13"); assert_eq!(local.strftime("%d"), ~"13");
assert_eq!(local.strftime(~"%e"), ~"13"); assert_eq!(local.strftime("%e"), ~"13");
assert_eq!(local.strftime(~"%F"), ~"2009-02-13"); assert_eq!(local.strftime("%F"), ~"2009-02-13");
// assert!(local.strftime("%G") == "2009"); // assert!(local.strftime("%G") == "2009");
// assert!(local.strftime("%g") == "09"); // assert!(local.strftime("%g") == "09");
assert_eq!(local.strftime(~"%H"), ~"15"); assert_eq!(local.strftime("%H"), ~"15");
assert_eq!(local.strftime(~"%I"), ~"03"); assert_eq!(local.strftime("%I"), ~"03");
assert_eq!(local.strftime(~"%j"), ~"044"); assert_eq!(local.strftime("%j"), ~"044");
assert_eq!(local.strftime(~"%k"), ~"15"); assert_eq!(local.strftime("%k"), ~"15");
assert_eq!(local.strftime(~"%l"), ~" 3"); assert_eq!(local.strftime("%l"), ~" 3");
assert_eq!(local.strftime(~"%M"), ~"31"); assert_eq!(local.strftime("%M"), ~"31");
assert_eq!(local.strftime(~"%m"), ~"02"); assert_eq!(local.strftime("%m"), ~"02");
assert_eq!(local.strftime(~"%n"), ~"\n"); assert_eq!(local.strftime("%n"), ~"\n");
assert_eq!(local.strftime(~"%P"), ~"pm"); assert_eq!(local.strftime("%P"), ~"pm");
assert_eq!(local.strftime(~"%p"), ~"PM"); assert_eq!(local.strftime("%p"), ~"PM");
assert_eq!(local.strftime(~"%R"), ~"15:31"); assert_eq!(local.strftime("%R"), ~"15:31");
assert_eq!(local.strftime(~"%r"), ~"03:31:30 PM"); assert_eq!(local.strftime("%r"), ~"03:31:30 PM");
assert_eq!(local.strftime(~"%S"), ~"30"); assert_eq!(local.strftime("%S"), ~"30");
assert_eq!(local.strftime(~"%s"), ~"1234567890"); assert_eq!(local.strftime("%s"), ~"1234567890");
assert_eq!(local.strftime(~"%T"), ~"15:31:30"); assert_eq!(local.strftime("%T"), ~"15:31:30");
assert_eq!(local.strftime(~"%t"), ~"\t"); assert_eq!(local.strftime("%t"), ~"\t");
// assert!(local.strftime("%U") == "06"); // assert!(local.strftime("%U") == "06");
assert_eq!(local.strftime(~"%u"), ~"5"); assert_eq!(local.strftime("%u"), ~"5");
// assert!(local.strftime("%V") == "07"); // assert!(local.strftime("%V") == "07");
assert_eq!(local.strftime(~"%v"), ~"13-Feb-2009"); assert_eq!(local.strftime("%v"), ~"13-Feb-2009");
// assert!(local.strftime("%W") == "06"); // assert!(local.strftime("%W") == "06");
assert_eq!(local.strftime(~"%w"), ~"5"); assert_eq!(local.strftime("%w"), ~"5");
// handle "%X" // handle "%X"
// handle "%x" // handle "%x"
assert_eq!(local.strftime(~"%Y"), ~"2009"); assert_eq!(local.strftime("%Y"), ~"2009");
assert_eq!(local.strftime(~"%y"), ~"09"); assert_eq!(local.strftime("%y"), ~"09");
// FIXME (#2350): We should probably standardize on the timezone // FIXME (#2350): We should probably standardize on the timezone
// abbreviation. // abbreviation.
let zone = local.strftime(~"%Z"); let zone = local.strftime("%Z");
assert!(zone == ~"PST" || zone == ~"Pacific Standard Time"); assert!(zone == ~"PST" || zone == ~"Pacific Standard Time");
assert_eq!(local.strftime(~"%z"), ~"-0800"); assert_eq!(local.strftime("%z"), ~"-0800");
assert_eq!(local.strftime(~"%%"), ~"%"); assert_eq!(local.strftime("%%"), ~"%");
// FIXME (#2350): We should probably standardize on the timezone // FIXME (#2350): We should probably standardize on the timezone
// abbreviation. // abbreviation.

View file

@ -759,10 +759,10 @@ mod test_treemap {
fn u8_map() { fn u8_map() {
let mut m = TreeMap::new(); let mut m = TreeMap::new();
let k1 = str::to_bytes(~"foo"); let k1 = str::to_bytes("foo");
let k2 = str::to_bytes(~"bar"); let k2 = str::to_bytes("bar");
let v1 = str::to_bytes(~"baz"); let v1 = str::to_bytes("baz");
let v2 = str::to_bytes(~"foobar"); let v2 = str::to_bytes("foobar");
m.insert(copy k1, copy v1); m.insert(copy k1, copy v1);
m.insert(copy k2, copy v2); m.insert(copy k2, copy v2);