Replace all ~"" with "".to_owned()
This commit is contained in:
parent
b75683cadf
commit
919889a1d6
383 changed files with 2906 additions and 2813 deletions
|
@ -93,7 +93,7 @@ pub fn parse_config(args: Vec<~str> ) -> config {
|
|||
assert!(!args.is_empty());
|
||||
let argv0 = (*args.get(0)).clone();
|
||||
let args_ = args.tail();
|
||||
if *args.get(1) == ~"-h" || *args.get(1) == ~"--help" {
|
||||
if *args.get(1) == "-h".to_owned() || *args.get(1) == "--help".to_owned() {
|
||||
let message = format!("Usage: {} [OPTIONS] [TESTNAME...]", argv0);
|
||||
println!("{}", getopts::usage(message, groups.as_slice()));
|
||||
println!("");
|
||||
|
@ -181,7 +181,7 @@ pub fn log_config(config: &config) {
|
|||
logv(c, format!("adb_test_dir: {}", config.adb_test_dir));
|
||||
logv(c, format!("adb_device_status: {}", config.adb_device_status));
|
||||
match config.test_shard {
|
||||
None => logv(c, ~"test_shard: (all)"),
|
||||
None => logv(c, "test_shard: (all)".to_owned()),
|
||||
Some((a,b)) => logv(c, format!("test_shard: {}.{}", a, b))
|
||||
}
|
||||
logv(c, format!("verbose: {}", config.verbose));
|
||||
|
@ -199,7 +199,7 @@ pub fn opt_str<'a>(maybestr: &'a Option<~str>) -> &'a str {
|
|||
}
|
||||
|
||||
pub fn opt_str2(maybestr: Option<~str>) -> ~str {
|
||||
match maybestr { None => ~"(none)", Some(s) => { s } }
|
||||
match maybestr { None => "(none)".to_owned(), Some(s) => { s } }
|
||||
}
|
||||
|
||||
pub fn str_mode(s: ~str) -> mode {
|
||||
|
@ -216,17 +216,17 @@ pub fn str_mode(s: ~str) -> mode {
|
|||
|
||||
pub fn mode_str(mode: mode) -> ~str {
|
||||
match mode {
|
||||
mode_compile_fail => ~"compile-fail",
|
||||
mode_run_fail => ~"run-fail",
|
||||
mode_run_pass => ~"run-pass",
|
||||
mode_pretty => ~"pretty",
|
||||
mode_debug_info => ~"debug-info",
|
||||
mode_codegen => ~"codegen",
|
||||
mode_compile_fail => "compile-fail".to_owned(),
|
||||
mode_run_fail => "run-fail".to_owned(),
|
||||
mode_run_pass => "run-pass".to_owned(),
|
||||
mode_pretty => "pretty".to_owned(),
|
||||
mode_debug_info => "debug-info".to_owned(),
|
||||
mode_codegen => "codegen".to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_tests(config: &config) {
|
||||
if config.target == ~"arm-linux-androideabi" {
|
||||
if config.target == "arm-linux-androideabi".to_owned() {
|
||||
match config.mode{
|
||||
mode_debug_info => {
|
||||
println!("arm-linux-androideabi debug-info \
|
||||
|
@ -296,10 +296,10 @@ pub fn is_test(config: &config, testfile: &Path) -> bool {
|
|||
// Pretty-printer does not work with .rc files yet
|
||||
let valid_extensions =
|
||||
match config.mode {
|
||||
mode_pretty => vec!(~".rs"),
|
||||
_ => vec!(~".rc", ~".rs")
|
||||
mode_pretty => vec!(".rs".to_owned()),
|
||||
_ => vec!(".rc".to_owned(), ".rs".to_owned())
|
||||
};
|
||||
let invalid_prefixes = vec!(~".", ~"#", ~"~");
|
||||
let invalid_prefixes = vec!(".".to_owned(), "#".to_owned(), "~".to_owned());
|
||||
let name = testfile.filename_str().unwrap();
|
||||
|
||||
let mut valid = false;
|
||||
|
|
|
@ -31,7 +31,7 @@ pub fn load_errors(testfile: &Path) -> Vec<ExpectedError> {
|
|||
|
||||
fn parse_expected(line_num: uint, line: ~str) -> Vec<ExpectedError> {
|
||||
let line = line.trim();
|
||||
let error_tag = ~"//~";
|
||||
let error_tag = "//~".to_owned();
|
||||
let mut idx;
|
||||
match line.find_str(error_tag) {
|
||||
None => return Vec::new(),
|
||||
|
|
|
@ -112,10 +112,10 @@ pub fn load_props(testfile: &Path) -> TestProps {
|
|||
|
||||
pub fn is_test_ignored(config: &config, testfile: &Path) -> bool {
|
||||
fn ignore_target(config: &config) -> ~str {
|
||||
~"ignore-" + util::get_os(config.target)
|
||||
"ignore-".to_owned() + util::get_os(config.target)
|
||||
}
|
||||
fn ignore_stage(config: &config) -> ~str {
|
||||
~"ignore-" + config.stage_id.split('-').next().unwrap()
|
||||
"ignore-".to_owned() + config.stage_id.split('-').next().unwrap()
|
||||
}
|
||||
|
||||
let val = iter_header(testfile, |ln| {
|
||||
|
@ -149,23 +149,23 @@ fn iter_header(testfile: &Path, it: |&str| -> bool) -> bool {
|
|||
}
|
||||
|
||||
fn parse_error_pattern(line: &str) -> Option<~str> {
|
||||
parse_name_value_directive(line, ~"error-pattern")
|
||||
parse_name_value_directive(line, "error-pattern".to_owned())
|
||||
}
|
||||
|
||||
fn parse_aux_build(line: &str) -> Option<~str> {
|
||||
parse_name_value_directive(line, ~"aux-build")
|
||||
parse_name_value_directive(line, "aux-build".to_owned())
|
||||
}
|
||||
|
||||
fn parse_compile_flags(line: &str) -> Option<~str> {
|
||||
parse_name_value_directive(line, ~"compile-flags")
|
||||
parse_name_value_directive(line, "compile-flags".to_owned())
|
||||
}
|
||||
|
||||
fn parse_debugger_cmd(line: &str) -> Option<~str> {
|
||||
parse_name_value_directive(line, ~"debugger")
|
||||
parse_name_value_directive(line, "debugger".to_owned())
|
||||
}
|
||||
|
||||
fn parse_check_line(line: &str) -> Option<~str> {
|
||||
parse_name_value_directive(line, ~"check")
|
||||
parse_name_value_directive(line, "check".to_owned())
|
||||
}
|
||||
|
||||
fn parse_force_host(line: &str) -> bool {
|
||||
|
@ -181,12 +181,12 @@ fn parse_no_prefer_dynamic(line: &str) -> bool {
|
|||
}
|
||||
|
||||
fn parse_exec_env(line: &str) -> Option<(~str, ~str)> {
|
||||
parse_name_value_directive(line, ~"exec-env").map(|nv| {
|
||||
parse_name_value_directive(line, "exec-env".to_owned()).map(|nv| {
|
||||
// nv is either FOO or FOO=BAR
|
||||
let mut strs: Vec<~str> = nv.splitn('=', 1).map(|s| s.to_owned()).collect();
|
||||
|
||||
match strs.len() {
|
||||
1u => (strs.pop().unwrap(), ~""),
|
||||
1u => (strs.pop().unwrap(), "".to_owned()),
|
||||
2u => {
|
||||
let end = strs.pop().unwrap();
|
||||
(strs.pop().unwrap(), end)
|
||||
|
@ -197,7 +197,7 @@ fn parse_exec_env(line: &str) -> Option<(~str, ~str)> {
|
|||
}
|
||||
|
||||
fn parse_pp_exact(line: &str, testfile: &Path) -> Option<Path> {
|
||||
match parse_name_value_directive(line, ~"pp-exact") {
|
||||
match parse_name_value_directive(line, "pp-exact".to_owned()) {
|
||||
Some(s) => Some(Path::new(s)),
|
||||
None => {
|
||||
if parse_name_directive(line, "pp-exact") {
|
||||
|
|
|
@ -29,7 +29,7 @@ fn target_env(lib_path: &str, prog: &str) -> Vec<(~str, ~str)> {
|
|||
(k, new_v)
|
||||
}).collect();
|
||||
if prog.ends_with("rustc.exe") {
|
||||
new_env.push((~"RUST_THREADS", ~"1"));
|
||||
new_env.push(("RUST_THREADS".to_owned(), "1".to_owned()));
|
||||
}
|
||||
return new_env;
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ fn target_env(lib_path: &str, prog: &str) -> Vec<(~str,~str)> {
|
|||
};
|
||||
let prev = match env.iter().position(|&(ref k, _)| k.as_slice() == var) {
|
||||
Some(i) => env.remove(i).unwrap().val1(),
|
||||
None => ~"",
|
||||
None => "".to_owned(),
|
||||
};
|
||||
env.push((var.to_owned(), if prev.is_empty() {
|
||||
lib_path + ":" + aux_path
|
||||
|
|
|
@ -75,7 +75,7 @@ fn run_cfail_test(config: &config, props: &TestProps, testfile: &Path) {
|
|||
let proc_res = compile_test(config, props, testfile);
|
||||
|
||||
if proc_res.status.success() {
|
||||
fatal_ProcRes(~"compile-fail test compiled successfully!", &proc_res);
|
||||
fatal_ProcRes("compile-fail test compiled successfully!".to_owned(), &proc_res);
|
||||
}
|
||||
|
||||
check_correct_failure_status(&proc_res);
|
||||
|
@ -83,7 +83,7 @@ fn run_cfail_test(config: &config, props: &TestProps, testfile: &Path) {
|
|||
let expected_errors = errors::load_errors(testfile);
|
||||
if !expected_errors.is_empty() {
|
||||
if !props.error_patterns.is_empty() {
|
||||
fatal(~"both error pattern and expected errors specified");
|
||||
fatal("both error pattern and expected errors specified".to_owned());
|
||||
}
|
||||
check_expected_errors(expected_errors, testfile, &proc_res);
|
||||
} else {
|
||||
|
@ -96,7 +96,7 @@ fn run_rfail_test(config: &config, props: &TestProps, testfile: &Path) {
|
|||
let proc_res = compile_test(config, props, testfile);
|
||||
|
||||
if !proc_res.status.success() {
|
||||
fatal_ProcRes(~"compilation failed!", &proc_res);
|
||||
fatal_ProcRes("compilation failed!".to_owned(), &proc_res);
|
||||
}
|
||||
|
||||
exec_compiled_test(config, props, testfile)
|
||||
|
@ -107,7 +107,7 @@ fn run_rfail_test(config: &config, props: &TestProps, testfile: &Path) {
|
|||
// The value our Makefile configures valgrind to return on failure
|
||||
static VALGRIND_ERR: int = 100;
|
||||
if proc_res.status.matches_exit_status(VALGRIND_ERR) {
|
||||
fatal_ProcRes(~"run-fail test isn't valgrind-clean!", &proc_res);
|
||||
fatal_ProcRes("run-fail test isn't valgrind-clean!".to_owned(), &proc_res);
|
||||
}
|
||||
|
||||
check_correct_failure_status(&proc_res);
|
||||
|
@ -129,25 +129,25 @@ fn run_rpass_test(config: &config, props: &TestProps, testfile: &Path) {
|
|||
let mut proc_res = compile_test(config, props, testfile);
|
||||
|
||||
if !proc_res.status.success() {
|
||||
fatal_ProcRes(~"compilation failed!", &proc_res);
|
||||
fatal_ProcRes("compilation failed!".to_owned(), &proc_res);
|
||||
}
|
||||
|
||||
proc_res = exec_compiled_test(config, props, testfile);
|
||||
|
||||
if !proc_res.status.success() {
|
||||
fatal_ProcRes(~"test run failed!", &proc_res);
|
||||
fatal_ProcRes("test run failed!".to_owned(), &proc_res);
|
||||
}
|
||||
} else {
|
||||
let proc_res = jit_test(config, props, testfile);
|
||||
|
||||
if !proc_res.status.success() { fatal_ProcRes(~"jit failed!", &proc_res); }
|
||||
if !proc_res.status.success() { fatal_ProcRes("jit failed!".to_owned(), &proc_res); }
|
||||
}
|
||||
}
|
||||
|
||||
fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
|
||||
if props.pp_exact.is_some() {
|
||||
logv(config, ~"testing for exact pretty-printing");
|
||||
} else { logv(config, ~"testing for converging pretty-printing"); }
|
||||
logv(config, "testing for exact pretty-printing".to_owned());
|
||||
} else { logv(config, "testing for converging pretty-printing".to_owned()); }
|
||||
|
||||
let rounds =
|
||||
match props.pp_exact { Some(_) => 1, None => 2 };
|
||||
|
@ -185,7 +185,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
|
|||
|
||||
if props.pp_exact.is_some() {
|
||||
// Now we have to care about line endings
|
||||
let cr = ~"\r";
|
||||
let cr = "\r".to_owned();
|
||||
actual = actual.replace(cr, "");
|
||||
expected = expected.replace(cr, "");
|
||||
}
|
||||
|
@ -196,7 +196,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
|
|||
let proc_res = typecheck_source(config, props, testfile, actual);
|
||||
|
||||
if !proc_res.status.success() {
|
||||
fatal_ProcRes(~"pretty-printed source does not typecheck", &proc_res);
|
||||
fatal_ProcRes("pretty-printed source does not typecheck".to_owned(), &proc_res);
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -207,15 +207,15 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
|
|||
}
|
||||
|
||||
fn make_pp_args(config: &config, _testfile: &Path) -> ProcArgs {
|
||||
let args = vec!(~"-", ~"--pretty", ~"normal",
|
||||
~"--target=" + config.target);
|
||||
let args = vec!("-".to_owned(), "--pretty".to_owned(), "normal".to_owned(),
|
||||
"--target=".to_owned() + config.target);
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
return ProcArgs {prog: config.rustc_path.as_str().unwrap().to_owned(), args: args};
|
||||
}
|
||||
|
||||
fn compare_source(expected: &str, actual: &str) {
|
||||
if expected != actual {
|
||||
error(~"pretty-printed source does not match expected source");
|
||||
error("pretty-printed source does not match expected source".to_owned());
|
||||
println!("\n\
|
||||
expected:\n\
|
||||
------------------------------------------\n\
|
||||
|
@ -245,11 +245,11 @@ actual:\n\
|
|||
config.target.as_slice()
|
||||
};
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
let mut args = vec!(~"-",
|
||||
~"--no-trans", ~"--crate-type=lib",
|
||||
~"--target=" + target,
|
||||
~"-L", config.build_base.as_str().unwrap().to_owned(),
|
||||
~"-L",
|
||||
let mut args = vec!("-".to_owned(),
|
||||
"--no-trans".to_owned(), "--crate-type=lib".to_owned(),
|
||||
"--target=".to_owned() + target,
|
||||
"-L".to_owned(), config.build_base.as_str().unwrap().to_owned(),
|
||||
"-L".to_owned(),
|
||||
aux_dir.as_str().unwrap().to_owned());
|
||||
args.push_all_move(split_maybe_args(&config.target_rustcflags));
|
||||
args.push_all_move(split_maybe_args(&props.compile_flags));
|
||||
|
@ -272,7 +272,7 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {
|
|||
// compile test file (it shoud have 'compile-flags:-g' in the header)
|
||||
let mut proc_res = compile_test(config, props, testfile);
|
||||
if !proc_res.status.success() {
|
||||
fatal_ProcRes(~"compilation failed!", &proc_res);
|
||||
fatal_ProcRes("compilation failed!".to_owned(), &proc_res);
|
||||
}
|
||||
|
||||
let exe_file = make_exe_name(config, testfile);
|
||||
|
@ -284,24 +284,24 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {
|
|||
cmds = cmds.replace("run","continue");
|
||||
|
||||
// write debugger script
|
||||
let script_str = [~"set charset UTF-8",
|
||||
let script_str = ["set charset UTF-8".to_owned(),
|
||||
format!("file {}",exe_file.as_str().unwrap().to_owned()),
|
||||
~"target remote :5039",
|
||||
"target remote :5039".to_owned(),
|
||||
cmds,
|
||||
~"quit"].connect("\n");
|
||||
"quit".to_owned()].connect("\n");
|
||||
debug!("script_str = {}", script_str);
|
||||
dump_output_file(config, testfile, script_str, "debugger.script");
|
||||
|
||||
|
||||
procsrv::run("", config.adb_path,
|
||||
[~"push", exe_file.as_str().unwrap().to_owned(),
|
||||
["push".to_owned(), exe_file.as_str().unwrap().to_owned(),
|
||||
config.adb_test_dir.clone()],
|
||||
vec!((~"",~"")), Some(~""))
|
||||
vec!(("".to_owned(),"".to_owned())), Some("".to_owned()))
|
||||
.expect(format!("failed to exec `{}`", config.adb_path));
|
||||
|
||||
procsrv::run("", config.adb_path,
|
||||
[~"forward", ~"tcp:5039", ~"tcp:5039"],
|
||||
vec!((~"",~"")), Some(~""))
|
||||
["forward".to_owned(), "tcp:5039".to_owned(), "tcp:5039".to_owned()],
|
||||
vec!(("".to_owned(),"".to_owned())), Some("".to_owned()))
|
||||
.expect(format!("failed to exec `{}`", config.adb_path));
|
||||
|
||||
let adb_arg = format!("export LD_LIBRARY_PATH={}; gdbserver :5039 {}/{}",
|
||||
|
@ -309,8 +309,9 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {
|
|||
str::from_utf8(exe_file.filename().unwrap()).unwrap());
|
||||
|
||||
let mut process = procsrv::run_background("", config.adb_path,
|
||||
[~"shell",adb_arg.clone()],
|
||||
vec!((~"",~"")), Some(~""))
|
||||
["shell".to_owned(),adb_arg.clone()],
|
||||
vec!(("".to_owned(),"".to_owned())),
|
||||
Some("".to_owned()))
|
||||
.expect(format!("failed to exec `{}`", config.adb_path));
|
||||
loop {
|
||||
//waiting 1 second for gdbserver start
|
||||
|
@ -337,12 +338,12 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {
|
|||
}
|
||||
|
||||
if tool_path.is_empty() {
|
||||
fatal(~"cannot found android cross path");
|
||||
fatal("cannot found android cross path".to_owned());
|
||||
}
|
||||
|
||||
let debugger_script = make_out_name(config, testfile, "debugger.script");
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
let debugger_opts = vec!(~"-quiet", ~"-batch", ~"-nx",
|
||||
let debugger_opts = vec!("-quiet".to_owned(), "-batch".to_owned(), "-nx".to_owned(),
|
||||
"-command=" + debugger_script.as_str().unwrap().to_owned());
|
||||
|
||||
let gdb_path = tool_path.append("/bin/arm-linux-androideabi-gdb");
|
||||
|
@ -350,7 +351,7 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {
|
|||
procsrv::run("",
|
||||
gdb_path.as_slice(),
|
||||
debugger_opts.as_slice(),
|
||||
vec!((~"",~"")),
|
||||
vec!(("".to_owned(),"".to_owned())),
|
||||
None)
|
||||
.expect(format!("failed to exec `{}`", gdb_path));
|
||||
let cmdline = {
|
||||
|
@ -370,22 +371,22 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {
|
|||
|
||||
_=> {
|
||||
// write debugger script
|
||||
let script_str = [~"set charset UTF-8",
|
||||
let script_str = ["set charset UTF-8".to_owned(),
|
||||
cmds,
|
||||
~"quit\n"].connect("\n");
|
||||
"quit\n".to_owned()].connect("\n");
|
||||
debug!("script_str = {}", script_str);
|
||||
dump_output_file(config, testfile, script_str, "debugger.script");
|
||||
|
||||
// run debugger script with gdb
|
||||
#[cfg(windows)]
|
||||
fn debugger() -> ~str { ~"gdb.exe" }
|
||||
fn debugger() -> ~str { "gdb.exe".to_owned() }
|
||||
#[cfg(unix)]
|
||||
fn debugger() -> ~str { ~"gdb" }
|
||||
fn debugger() -> ~str { "gdb".to_owned() }
|
||||
|
||||
let debugger_script = make_out_name(config, testfile, "debugger.script");
|
||||
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
let debugger_opts = vec!(~"-quiet", ~"-batch", ~"-nx",
|
||||
let debugger_opts = vec!("-quiet".to_owned(), "-batch".to_owned(), "-nx".to_owned(),
|
||||
"-command=" + debugger_script.as_str().unwrap().to_owned(),
|
||||
exe_file.as_str().unwrap().to_owned());
|
||||
proc_args = ProcArgs {prog: debugger(), args: debugger_opts};
|
||||
|
@ -394,7 +395,7 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {
|
|||
}
|
||||
|
||||
if !proc_res.status.success() {
|
||||
fatal(~"gdb failed to execute");
|
||||
fatal("gdb failed to execute".to_owned());
|
||||
}
|
||||
let num_check_lines = check_lines.len();
|
||||
if num_check_lines > 0 {
|
||||
|
@ -448,7 +449,7 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {
|
|||
}
|
||||
|
||||
// Remove options that are either unwanted (-O) or may lead to duplicates due to RUSTFLAGS.
|
||||
let options_to_remove = [~"-O", ~"-g", ~"--debuginfo"];
|
||||
let options_to_remove = ["-O".to_owned(), "-g".to_owned(), "--debuginfo".to_owned()];
|
||||
let new_options = split_maybe_args(options).move_iter()
|
||||
.filter(|x| !options_to_remove.contains(x))
|
||||
.collect::<Vec<~str>>()
|
||||
|
@ -461,11 +462,12 @@ fn check_error_patterns(props: &TestProps,
|
|||
testfile: &Path,
|
||||
proc_res: &ProcRes) {
|
||||
if props.error_patterns.is_empty() {
|
||||
fatal(~"no error pattern specified in " + testfile.display().as_maybe_owned().as_slice());
|
||||
fatal("no error pattern specified in ".to_owned() +
|
||||
testfile.display().as_maybe_owned().as_slice());
|
||||
}
|
||||
|
||||
if proc_res.status.success() {
|
||||
fatal(~"process did not return an error status");
|
||||
fatal("process did not return an error status".to_owned());
|
||||
}
|
||||
|
||||
let mut next_err_idx = 0u;
|
||||
|
@ -499,7 +501,7 @@ fn check_error_patterns(props: &TestProps,
|
|||
for pattern in missing_patterns.iter() {
|
||||
error(format!("error pattern '{}' not found!", *pattern));
|
||||
}
|
||||
fatal_ProcRes(~"multiple error patterns not found", proc_res);
|
||||
fatal_ProcRes("multiple error patterns not found".to_owned(), proc_res);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -512,7 +514,7 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError> ,
|
|||
expected_errors.len(), false);
|
||||
|
||||
if proc_res.status.success() {
|
||||
fatal(~"process did not return an error status");
|
||||
fatal("process did not return an error status".to_owned());
|
||||
}
|
||||
|
||||
let prefixes = expected_errors.iter().map(|ee| {
|
||||
|
@ -672,14 +674,14 @@ fn compile_test(config: &config, props: &TestProps,
|
|||
}
|
||||
|
||||
fn jit_test(config: &config, props: &TestProps, testfile: &Path) -> ProcRes {
|
||||
compile_test_(config, props, testfile, [~"--jit"])
|
||||
compile_test_(config, props, testfile, ["--jit".to_owned()])
|
||||
}
|
||||
|
||||
fn compile_test_(config: &config, props: &TestProps,
|
||||
testfile: &Path, extra_args: &[~str]) -> ProcRes {
|
||||
let aux_dir = aux_output_dir_name(config, testfile);
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
let link_args = vec!(~"-L", aux_dir.as_str().unwrap().to_owned());
|
||||
let link_args = vec!("-L".to_owned(), aux_dir.as_str().unwrap().to_owned());
|
||||
let args = make_compile_args(config,
|
||||
props,
|
||||
link_args.append(extra_args),
|
||||
|
@ -720,7 +722,7 @@ fn compose_and_run_compiler(
|
|||
|
||||
let aux_dir = aux_output_dir_name(config, testfile);
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
let extra_link_args = vec!(~"-L", aux_dir.as_str().unwrap().to_owned());
|
||||
let extra_link_args = vec!("-L".to_owned(), aux_dir.as_str().unwrap().to_owned());
|
||||
|
||||
for rel_ab in props.aux_builds.iter() {
|
||||
let abs_ab = config.aux_base.join(rel_ab.as_slice());
|
||||
|
@ -728,7 +730,7 @@ fn compose_and_run_compiler(
|
|||
let crate_type = if aux_props.no_prefer_dynamic {
|
||||
Vec::new()
|
||||
} else {
|
||||
vec!(~"--crate-type=dylib")
|
||||
vec!("--crate-type=dylib".to_owned())
|
||||
};
|
||||
let aux_args =
|
||||
make_compile_args(config,
|
||||
|
@ -794,16 +796,16 @@ fn make_compile_args(config: &config,
|
|||
};
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
let mut args = vec!(testfile.as_str().unwrap().to_owned(),
|
||||
~"-L", config.build_base.as_str().unwrap().to_owned(),
|
||||
~"--target=" + target);
|
||||
"-L".to_owned(), config.build_base.as_str().unwrap().to_owned(),
|
||||
"--target=".to_owned() + target);
|
||||
args.push_all(extras.as_slice());
|
||||
if !props.no_prefer_dynamic {
|
||||
args.push(~"-C");
|
||||
args.push(~"prefer-dynamic");
|
||||
args.push("-C".to_owned());
|
||||
args.push("prefer-dynamic".to_owned());
|
||||
}
|
||||
let path = match xform_file {
|
||||
ThisFile(path) => { args.push(~"-o"); path }
|
||||
ThisDirectory(path) => { args.push(~"--out-dir"); path }
|
||||
ThisFile(path) => { args.push("-o".to_owned()); path }
|
||||
ThisDirectory(path) => { args.push("--out-dir".to_owned()); path }
|
||||
};
|
||||
args.push(path.as_str().unwrap().to_owned());
|
||||
if props.force_host {
|
||||
|
@ -974,8 +976,8 @@ fn _arm_exec_compiled_test(config: &config, props: &TestProps,
|
|||
|
||||
// copy to target
|
||||
let copy_result = procsrv::run("", config.adb_path,
|
||||
[~"push", args.prog.clone(), config.adb_test_dir.clone()],
|
||||
vec!((~"",~"")), Some(~""))
|
||||
["push".to_owned(), args.prog.clone(), config.adb_test_dir.clone()],
|
||||
vec!(("".to_owned(),"".to_owned())), Some("".to_owned()))
|
||||
.expect(format!("failed to exec `{}`", config.adb_path));
|
||||
|
||||
if config.verbose {
|
||||
|
@ -989,7 +991,7 @@ fn _arm_exec_compiled_test(config: &config, props: &TestProps,
|
|||
let mut runargs = Vec::new();
|
||||
|
||||
// run test via adb_run_wrapper
|
||||
runargs.push(~"shell");
|
||||
runargs.push("shell".to_owned());
|
||||
for (key, val) in env.move_iter() {
|
||||
runargs.push(format!("{}={}", key, val));
|
||||
}
|
||||
|
@ -1003,18 +1005,18 @@ fn _arm_exec_compiled_test(config: &config, props: &TestProps,
|
|||
procsrv::run("",
|
||||
config.adb_path,
|
||||
runargs.as_slice(),
|
||||
vec!((~"",~"")), Some(~""))
|
||||
vec!(("".to_owned(),"".to_owned())), Some("".to_owned()))
|
||||
.expect(format!("failed to exec `{}`", config.adb_path));
|
||||
|
||||
// get exitcode of result
|
||||
runargs = Vec::new();
|
||||
runargs.push(~"shell");
|
||||
runargs.push(~"cat");
|
||||
runargs.push("shell".to_owned());
|
||||
runargs.push("cat".to_owned());
|
||||
runargs.push(format!("{}/{}.exitcode", config.adb_test_dir, prog_short));
|
||||
|
||||
let procsrv::Result{ out: exitcode_out, err: _, status: _ } =
|
||||
procsrv::run("", config.adb_path, runargs.as_slice(), vec!((~"",~"")),
|
||||
Some(~""))
|
||||
procsrv::run("", config.adb_path, runargs.as_slice(), vec!(("".to_owned(),"".to_owned())),
|
||||
Some("".to_owned()))
|
||||
.expect(format!("failed to exec `{}`", config.adb_path));
|
||||
|
||||
let mut exitcode : int = 0;
|
||||
|
@ -1028,28 +1030,28 @@ fn _arm_exec_compiled_test(config: &config, props: &TestProps,
|
|||
|
||||
// get stdout of result
|
||||
runargs = Vec::new();
|
||||
runargs.push(~"shell");
|
||||
runargs.push(~"cat");
|
||||
runargs.push("shell".to_owned());
|
||||
runargs.push("cat".to_owned());
|
||||
runargs.push(format!("{}/{}.stdout", config.adb_test_dir, prog_short));
|
||||
|
||||
let procsrv::Result{ out: stdout_out, err: _, status: _ } =
|
||||
procsrv::run("",
|
||||
config.adb_path,
|
||||
runargs.as_slice(),
|
||||
vec!((~"",~"")), Some(~""))
|
||||
vec!(("".to_owned(),"".to_owned())), Some("".to_owned()))
|
||||
.expect(format!("failed to exec `{}`", config.adb_path));
|
||||
|
||||
// get stderr of result
|
||||
runargs = Vec::new();
|
||||
runargs.push(~"shell");
|
||||
runargs.push(~"cat");
|
||||
runargs.push("shell".to_owned());
|
||||
runargs.push("cat".to_owned());
|
||||
runargs.push(format!("{}/{}.stderr", config.adb_test_dir, prog_short));
|
||||
|
||||
let procsrv::Result{ out: stderr_out, err: _, status: _ } =
|
||||
procsrv::run("",
|
||||
config.adb_path,
|
||||
runargs.as_slice(),
|
||||
vec!((~"",~"")), Some(~""))
|
||||
vec!(("".to_owned(),"".to_owned())), Some("".to_owned()))
|
||||
.expect(format!("failed to exec `{}`", config.adb_path));
|
||||
|
||||
dump_output(config, testfile, stdout_out, stderr_out);
|
||||
|
@ -1070,8 +1072,8 @@ fn _arm_push_aux_shared_library(config: &config, testfile: &Path) {
|
|||
if file.extension_str() == Some("so") {
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
let copy_result = procsrv::run("", config.adb_path,
|
||||
[~"push", file.as_str().unwrap().to_owned(), config.adb_test_dir.clone()],
|
||||
vec!((~"",~"")), Some(~""))
|
||||
["push".to_owned(), file.as_str().unwrap().to_owned(), config.adb_test_dir.clone()],
|
||||
vec!(("".to_owned(),"".to_owned())), Some("".to_owned()))
|
||||
.expect(format!("failed to exec `{}`", config.adb_path));
|
||||
|
||||
if config.verbose {
|
||||
|
@ -1102,8 +1104,9 @@ fn compile_test_and_save_bitcode(config: &config, props: &TestProps,
|
|||
testfile: &Path) -> ProcRes {
|
||||
let aux_dir = aux_output_dir_name(config, testfile);
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
let link_args = vec!(~"-L", aux_dir.as_str().unwrap().to_owned());
|
||||
let llvm_args = vec!(~"--emit=obj", ~"--crate-type=lib", ~"-C", ~"save-temps");
|
||||
let link_args = vec!("-L".to_owned(), aux_dir.as_str().unwrap().to_owned());
|
||||
let llvm_args = vec!("--emit=obj".to_owned(), "--crate-type=lib".to_owned(),
|
||||
"-C".to_owned(), "save-temps".to_owned());
|
||||
let args = make_compile_args(config,
|
||||
props,
|
||||
link_args.append(llvm_args.as_slice()),
|
||||
|
@ -1119,9 +1122,9 @@ fn compile_cc_with_clang_and_save_bitcode(config: &config, _props: &TestProps,
|
|||
let proc_args = ProcArgs {
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
prog: config.clang_path.get_ref().as_str().unwrap().to_owned(),
|
||||
args: vec!(~"-c",
|
||||
~"-emit-llvm",
|
||||
~"-o", bitcodefile.as_str().unwrap().to_owned(),
|
||||
args: vec!("-c".to_owned(),
|
||||
"-emit-llvm".to_owned(),
|
||||
"-o".to_owned(), bitcodefile.as_str().unwrap().to_owned(),
|
||||
testcc.as_str().unwrap().to_owned() )
|
||||
};
|
||||
compose_and_run(config, testfile, proc_args, Vec::new(), "", None)
|
||||
|
@ -1172,42 +1175,42 @@ fn run_codegen_test(config: &config, props: &TestProps,
|
|||
testfile: &Path, mm: &mut MetricMap) {
|
||||
|
||||
if config.llvm_bin_path.is_none() {
|
||||
fatal(~"missing --llvm-bin-path");
|
||||
fatal("missing --llvm-bin-path".to_owned());
|
||||
}
|
||||
|
||||
if config.clang_path.is_none() {
|
||||
fatal(~"missing --clang-path");
|
||||
fatal("missing --clang-path".to_owned());
|
||||
}
|
||||
|
||||
let mut proc_res = compile_test_and_save_bitcode(config, props, testfile);
|
||||
if !proc_res.status.success() {
|
||||
fatal_ProcRes(~"compilation failed!", &proc_res);
|
||||
fatal_ProcRes("compilation failed!".to_owned(), &proc_res);
|
||||
}
|
||||
|
||||
proc_res = extract_function_from_bitcode(config, props, "test", testfile, "");
|
||||
if !proc_res.status.success() {
|
||||
fatal_ProcRes(~"extracting 'test' function failed", &proc_res);
|
||||
fatal_ProcRes("extracting 'test' function failed".to_owned(), &proc_res);
|
||||
}
|
||||
|
||||
proc_res = disassemble_extract(config, props, testfile, "");
|
||||
if !proc_res.status.success() {
|
||||
fatal_ProcRes(~"disassembling extract failed", &proc_res);
|
||||
fatal_ProcRes("disassembling extract failed".to_owned(), &proc_res);
|
||||
}
|
||||
|
||||
|
||||
let mut proc_res = compile_cc_with_clang_and_save_bitcode(config, props, testfile);
|
||||
if !proc_res.status.success() {
|
||||
fatal_ProcRes(~"compilation failed!", &proc_res);
|
||||
fatal_ProcRes("compilation failed!".to_owned(), &proc_res);
|
||||
}
|
||||
|
||||
proc_res = extract_function_from_bitcode(config, props, "test", testfile, "clang");
|
||||
if !proc_res.status.success() {
|
||||
fatal_ProcRes(~"extracting 'test' function failed", &proc_res);
|
||||
fatal_ProcRes("extracting 'test' function failed".to_owned(), &proc_res);
|
||||
}
|
||||
|
||||
proc_res = disassemble_extract(config, props, testfile, "clang");
|
||||
if !proc_res.status.success() {
|
||||
fatal_ProcRes(~"disassembling extract failed", &proc_res);
|
||||
fatal_ProcRes("disassembling extract failed".to_owned(), &proc_res);
|
||||
}
|
||||
|
||||
let base = output_base_name(config, testfile);
|
||||
|
|
|
@ -46,10 +46,10 @@ pub fn make_new_path(path: &str) -> ~str {
|
|||
}
|
||||
|
||||
#[cfg(target_os = "win32")]
|
||||
pub fn lib_path_env_var() -> ~str { ~"PATH" }
|
||||
pub fn lib_path_env_var() -> ~str { "PATH".to_owned() }
|
||||
|
||||
#[cfg(target_os = "win32")]
|
||||
pub fn path_div() -> ~str { ~";" }
|
||||
pub fn path_div() -> ~str { ";".to_owned() }
|
||||
|
||||
pub fn logv(config: &config, s: ~str) {
|
||||
debug!("{}", s);
|
||||
|
|
|
@ -194,13 +194,13 @@ fn open(Door(name): Door<Closed>) -> Door<Open> {
|
|||
Door::<Open>(name)
|
||||
}
|
||||
|
||||
let _ = close(Door::<Open>(~"front"));
|
||||
let _ = close(Door::<Open>("front".to_owned()));
|
||||
~~~
|
||||
|
||||
Attempting to close a closed door is prevented statically:
|
||||
|
||||
~~~ {.ignore}
|
||||
let _ = close(Door::<Closed>(~"front")); // error: mismatched types: expected `main::Door<main::Open>` but found `main::Door<main::Closed>`
|
||||
let _ = close(Door::<Closed>("front".to_owned())); // error: mismatched types: expected `main::Door<main::Open>` but found `main::Door<main::Closed>`
|
||||
~~~
|
||||
|
||||
# FFI (Foreign Function Interface)
|
||||
|
|
|
@ -529,13 +529,13 @@ spawn(proc() {
|
|||
});
|
||||
|
||||
from_child.send(22);
|
||||
assert!(from_child.recv() == ~"22");
|
||||
assert!(from_child.recv() == "22".to_owned());
|
||||
|
||||
from_child.send(23);
|
||||
from_child.send(0);
|
||||
|
||||
assert!(from_child.recv() == ~"23");
|
||||
assert!(from_child.recv() == ~"0");
|
||||
assert!(from_child.recv() == "23".to_owned());
|
||||
assert!(from_child.recv() == "0".to_owned());
|
||||
|
||||
# }
|
||||
~~~~
|
||||
|
|
|
@ -1241,8 +1241,8 @@ enum Animal {
|
|||
Cat { name: ~str, weight: f64 }
|
||||
}
|
||||
|
||||
let mut a: Animal = Dog(~"Cocoa", 37.2);
|
||||
a = Cat{ name: ~"Spotty", weight: 2.7 };
|
||||
let mut a: Animal = Dog("Cocoa".to_owned(), 37.2);
|
||||
a = Cat{ name: "Spotty".to_owned(), weight: 2.7 };
|
||||
~~~~
|
||||
|
||||
In this example, `Cat` is a _struct-like enum variant_,
|
||||
|
@ -3510,7 +3510,7 @@ allocated on the heap (unlike closures). An example of creating and calling a
|
|||
procedure:
|
||||
|
||||
```rust
|
||||
let string = ~"Hello";
|
||||
let string = "Hello".to_owned();
|
||||
|
||||
// Creates a new procedure, passing it to the `spawn` function.
|
||||
spawn(proc() {
|
||||
|
|
|
@ -2166,7 +2166,7 @@ impl Printable for ~str {
|
|||
}
|
||||
|
||||
# 1.print();
|
||||
# (~"foo").print();
|
||||
# ("foo".to_owned()).print();
|
||||
~~~~
|
||||
|
||||
Methods defined in an impl for a trait may be called just like
|
||||
|
@ -2216,7 +2216,7 @@ impl Printable for bool {}
|
|||
impl Printable for f32 {}
|
||||
|
||||
# 1.print();
|
||||
# (~"foo").print();
|
||||
# ("foo".to_owned()).print();
|
||||
# true.print();
|
||||
# 3.14159.print();
|
||||
~~~~
|
||||
|
|
|
@ -549,7 +549,7 @@ mod tests {
|
|||
let arena = TypedArena::new();
|
||||
for _ in range(0, 100000) {
|
||||
arena.alloc(Noncopy {
|
||||
string: ~"hello world",
|
||||
string: "hello world".to_owned(),
|
||||
array: vec!( 1, 2, 3, 4, 5 ),
|
||||
});
|
||||
}
|
||||
|
@ -560,7 +560,7 @@ mod tests {
|
|||
let arena = TypedArena::new();
|
||||
b.iter(|| {
|
||||
arena.alloc(Noncopy {
|
||||
string: ~"hello world",
|
||||
string: "hello world".to_owned(),
|
||||
array: vec!( 1, 2, 3, 4, 5 ),
|
||||
})
|
||||
})
|
||||
|
@ -570,7 +570,7 @@ mod tests {
|
|||
pub fn bench_noncopy_nonarena(b: &mut Bencher) {
|
||||
b.iter(|| {
|
||||
~Noncopy {
|
||||
string: ~"hello world",
|
||||
string: "hello world".to_owned(),
|
||||
array: vec!( 1, 2, 3, 4, 5 ),
|
||||
}
|
||||
})
|
||||
|
@ -581,7 +581,7 @@ mod tests {
|
|||
let arena = Arena::new();
|
||||
b.iter(|| {
|
||||
arena.alloc(|| Noncopy {
|
||||
string: ~"hello world",
|
||||
string: "hello world".to_owned(),
|
||||
array: vec!( 1, 2, 3, 4, 5 ),
|
||||
})
|
||||
})
|
||||
|
|
|
@ -955,10 +955,10 @@ mod tests {
|
|||
#[test]
|
||||
fn test_to_str() {
|
||||
let zerolen = Bitv::new(0u, false);
|
||||
assert_eq!(zerolen.to_str(), ~"");
|
||||
assert_eq!(zerolen.to_str(), "".to_owned());
|
||||
|
||||
let eightbits = Bitv::new(8u, false);
|
||||
assert_eq!(eightbits.to_str(), ~"00000000");
|
||||
assert_eq!(eightbits.to_str(), "00000000".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -981,7 +981,7 @@ mod tests {
|
|||
let mut b = bitv::Bitv::new(2, false);
|
||||
b.set(0, true);
|
||||
b.set(1, false);
|
||||
assert_eq!(b.to_str(), ~"10");
|
||||
assert_eq!(b.to_str(), "10".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1291,7 +1291,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_from_bytes() {
|
||||
let bitv = from_bytes([0b10110110, 0b00000000, 0b11111111]);
|
||||
let str = ~"10110110" + "00000000" + "11111111";
|
||||
let str = "10110110".to_owned() + "00000000" + "11111111";
|
||||
assert_eq!(bitv.to_str(), str);
|
||||
}
|
||||
|
||||
|
@ -1310,7 +1310,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_from_bools() {
|
||||
assert!(from_bools([true, false, true, true]).to_str() ==
|
||||
~"1011");
|
||||
"1011".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -776,70 +776,70 @@ mod test_btree {
|
|||
//Tests the functionality of the insert methods (which are unfinished).
|
||||
#[test]
|
||||
fn insert_test_one() {
|
||||
let b = BTree::new(1, ~"abc", 2);
|
||||
let is_insert = b.insert(2, ~"xyz");
|
||||
let b = BTree::new(1, "abc".to_owned(), 2);
|
||||
let is_insert = b.insert(2, "xyz".to_owned());
|
||||
//println!("{}", is_insert.clone().to_str());
|
||||
assert!(is_insert.root.is_leaf());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn insert_test_two() {
|
||||
let leaf_elt_1 = LeafElt::new(1, ~"aaa");
|
||||
let leaf_elt_2 = LeafElt::new(2, ~"bbb");
|
||||
let leaf_elt_3 = LeafElt::new(3, ~"ccc");
|
||||
let leaf_elt_1 = LeafElt::new(1, "aaa".to_owned());
|
||||
let leaf_elt_2 = LeafElt::new(2, "bbb".to_owned());
|
||||
let leaf_elt_3 = LeafElt::new(3, "ccc".to_owned());
|
||||
let n = Node::new_leaf(vec!(leaf_elt_1, leaf_elt_2, leaf_elt_3));
|
||||
let b = BTree::new_with_node_len(n, 3, 2);
|
||||
//println!("{}", b.clone().insert(4, ~"ddd").to_str());
|
||||
assert!(b.insert(4, ~"ddd").root.is_leaf());
|
||||
//println!("{}", b.clone().insert(4, "ddd".to_owned()).to_str());
|
||||
assert!(b.insert(4, "ddd".to_owned()).root.is_leaf());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn insert_test_three() {
|
||||
let leaf_elt_1 = LeafElt::new(1, ~"aaa");
|
||||
let leaf_elt_2 = LeafElt::new(2, ~"bbb");
|
||||
let leaf_elt_3 = LeafElt::new(3, ~"ccc");
|
||||
let leaf_elt_4 = LeafElt::new(4, ~"ddd");
|
||||
let leaf_elt_1 = LeafElt::new(1, "aaa".to_owned());
|
||||
let leaf_elt_2 = LeafElt::new(2, "bbb".to_owned());
|
||||
let leaf_elt_3 = LeafElt::new(3, "ccc".to_owned());
|
||||
let leaf_elt_4 = LeafElt::new(4, "ddd".to_owned());
|
||||
let n = Node::new_leaf(vec!(leaf_elt_1, leaf_elt_2, leaf_elt_3, leaf_elt_4));
|
||||
let b = BTree::new_with_node_len(n, 3, 2);
|
||||
//println!("{}", b.clone().insert(5, ~"eee").to_str());
|
||||
assert!(!b.insert(5, ~"eee").root.is_leaf());
|
||||
//println!("{}", b.clone().insert(5, "eee".to_owned()).to_str());
|
||||
assert!(!b.insert(5, "eee".to_owned()).root.is_leaf());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn insert_test_four() {
|
||||
let leaf_elt_1 = LeafElt::new(1, ~"aaa");
|
||||
let leaf_elt_2 = LeafElt::new(2, ~"bbb");
|
||||
let leaf_elt_3 = LeafElt::new(3, ~"ccc");
|
||||
let leaf_elt_4 = LeafElt::new(4, ~"ddd");
|
||||
let leaf_elt_1 = LeafElt::new(1, "aaa".to_owned());
|
||||
let leaf_elt_2 = LeafElt::new(2, "bbb".to_owned());
|
||||
let leaf_elt_3 = LeafElt::new(3, "ccc".to_owned());
|
||||
let leaf_elt_4 = LeafElt::new(4, "ddd".to_owned());
|
||||
let n = Node::new_leaf(vec!(leaf_elt_1, leaf_elt_2, leaf_elt_3, leaf_elt_4));
|
||||
let mut b = BTree::new_with_node_len(n, 3, 2);
|
||||
b = b.clone().insert(5, ~"eee");
|
||||
b = b.clone().insert(6, ~"fff");
|
||||
b = b.clone().insert(7, ~"ggg");
|
||||
b = b.clone().insert(8, ~"hhh");
|
||||
b = b.clone().insert(0, ~"omg");
|
||||
b = b.clone().insert(5, "eee".to_owned());
|
||||
b = b.clone().insert(6, "fff".to_owned());
|
||||
b = b.clone().insert(7, "ggg".to_owned());
|
||||
b = b.clone().insert(8, "hhh".to_owned());
|
||||
b = b.clone().insert(0, "omg".to_owned());
|
||||
//println!("{}", b.clone().to_str());
|
||||
assert!(!b.root.is_leaf());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bsearch_test_one() {
|
||||
let b = BTree::new(1, ~"abc", 2);
|
||||
let b = BTree::new(1, "abc".to_owned(), 2);
|
||||
assert_eq!(Some(1), b.root.bsearch_node(2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bsearch_test_two() {
|
||||
let b = BTree::new(1, ~"abc", 2);
|
||||
let b = BTree::new(1, "abc".to_owned(), 2);
|
||||
assert_eq!(Some(0), b.root.bsearch_node(0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bsearch_test_three() {
|
||||
let leaf_elt_1 = LeafElt::new(1, ~"aaa");
|
||||
let leaf_elt_2 = LeafElt::new(2, ~"bbb");
|
||||
let leaf_elt_3 = LeafElt::new(4, ~"ccc");
|
||||
let leaf_elt_4 = LeafElt::new(5, ~"ddd");
|
||||
let leaf_elt_1 = LeafElt::new(1, "aaa".to_owned());
|
||||
let leaf_elt_2 = LeafElt::new(2, "bbb".to_owned());
|
||||
let leaf_elt_3 = LeafElt::new(4, "ccc".to_owned());
|
||||
let leaf_elt_4 = LeafElt::new(5, "ddd".to_owned());
|
||||
let n = Node::new_leaf(vec!(leaf_elt_1, leaf_elt_2, leaf_elt_3, leaf_elt_4));
|
||||
let b = BTree::new_with_node_len(n, 3, 2);
|
||||
assert_eq!(Some(2), b.root.bsearch_node(3));
|
||||
|
@ -847,10 +847,10 @@ mod test_btree {
|
|||
|
||||
#[test]
|
||||
fn bsearch_test_four() {
|
||||
let leaf_elt_1 = LeafElt::new(1, ~"aaa");
|
||||
let leaf_elt_2 = LeafElt::new(2, ~"bbb");
|
||||
let leaf_elt_3 = LeafElt::new(4, ~"ccc");
|
||||
let leaf_elt_4 = LeafElt::new(5, ~"ddd");
|
||||
let leaf_elt_1 = LeafElt::new(1, "aaa".to_owned());
|
||||
let leaf_elt_2 = LeafElt::new(2, "bbb".to_owned());
|
||||
let leaf_elt_3 = LeafElt::new(4, "ccc".to_owned());
|
||||
let leaf_elt_4 = LeafElt::new(5, "ddd".to_owned());
|
||||
let n = Node::new_leaf(vec!(leaf_elt_1, leaf_elt_2, leaf_elt_3, leaf_elt_4));
|
||||
let b = BTree::new_with_node_len(n, 3, 2);
|
||||
assert_eq!(Some(4), b.root.bsearch_node(800));
|
||||
|
@ -859,15 +859,15 @@ mod test_btree {
|
|||
//Tests the functionality of the get method.
|
||||
#[test]
|
||||
fn get_test() {
|
||||
let b = BTree::new(1, ~"abc", 2);
|
||||
let b = BTree::new(1, "abc".to_owned(), 2);
|
||||
let val = b.get(1);
|
||||
assert_eq!(val, Some(~"abc"));
|
||||
assert_eq!(val, Some("abc".to_owned()));
|
||||
}
|
||||
|
||||
//Tests the BTree's clone() method.
|
||||
#[test]
|
||||
fn btree_clone_test() {
|
||||
let b = BTree::new(1, ~"abc", 2);
|
||||
let b = BTree::new(1, "abc".to_owned(), 2);
|
||||
let b2 = b.clone();
|
||||
assert!(b.root == b2.root)
|
||||
}
|
||||
|
@ -875,32 +875,32 @@ mod test_btree {
|
|||
//Tests the BTree's cmp() method when one node is "less than" another.
|
||||
#[test]
|
||||
fn btree_cmp_test_less() {
|
||||
let b = BTree::new(1, ~"abc", 2);
|
||||
let b2 = BTree::new(2, ~"bcd", 2);
|
||||
let b = BTree::new(1, "abc".to_owned(), 2);
|
||||
let b2 = BTree::new(2, "bcd".to_owned(), 2);
|
||||
assert!(&b.cmp(&b2) == &Less)
|
||||
}
|
||||
|
||||
//Tests the BTree's cmp() method when two nodes are equal.
|
||||
#[test]
|
||||
fn btree_cmp_test_eq() {
|
||||
let b = BTree::new(1, ~"abc", 2);
|
||||
let b2 = BTree::new(1, ~"bcd", 2);
|
||||
let b = BTree::new(1, "abc".to_owned(), 2);
|
||||
let b2 = BTree::new(1, "bcd".to_owned(), 2);
|
||||
assert!(&b.cmp(&b2) == &Equal)
|
||||
}
|
||||
|
||||
//Tests the BTree's cmp() method when one node is "greater than" another.
|
||||
#[test]
|
||||
fn btree_cmp_test_greater() {
|
||||
let b = BTree::new(1, ~"abc", 2);
|
||||
let b2 = BTree::new(2, ~"bcd", 2);
|
||||
let b = BTree::new(1, "abc".to_owned(), 2);
|
||||
let b2 = BTree::new(2, "bcd".to_owned(), 2);
|
||||
assert!(&b2.cmp(&b) == &Greater)
|
||||
}
|
||||
|
||||
//Tests the BTree's to_str() method.
|
||||
#[test]
|
||||
fn btree_tostr_test() {
|
||||
let b = BTree::new(1, ~"abc", 2);
|
||||
assert_eq!(b.to_str(), ~"Key: 1, value: abc;")
|
||||
let b = BTree::new(1, "abc".to_owned(), 2);
|
||||
assert_eq!(b.to_str(), "Key: 1, value: abc;".to_owned())
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1962,9 +1962,9 @@ mod test_map {
|
|||
let mut m = HashMap::new();
|
||||
|
||||
let (foo, bar, baz) = (1,2,3);
|
||||
m.insert(~"foo", foo);
|
||||
m.insert(~"bar", bar);
|
||||
m.insert(~"baz", baz);
|
||||
m.insert("foo".to_owned(), foo);
|
||||
m.insert("bar".to_owned(), bar);
|
||||
m.insert("baz".to_owned(), baz);
|
||||
|
||||
|
||||
assert_eq!(m.find_equiv(&("foo")), Some(&foo));
|
||||
|
@ -2223,8 +2223,8 @@ mod test_set {
|
|||
|
||||
let set_str = format!("{}", set);
|
||||
|
||||
assert!(set_str == ~"{1, 2}" || set_str == ~"{2, 1}");
|
||||
assert_eq!(format!("{}", empty), ~"{}");
|
||||
assert!(set_str == "{1, 2}".to_owned() || set_str == "{2, 1}".to_owned());
|
||||
assert_eq!(format!("{}", empty), "{}".to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -295,22 +295,22 @@ mod tests {
|
|||
#[test]
|
||||
fn test_put_update() {
|
||||
let mut cache: LruCache<~str, Vec<u8>> = LruCache::new(1);
|
||||
cache.put(~"1", vec![10, 10]);
|
||||
cache.put(~"1", vec![10, 19]);
|
||||
assert_opt_eq(cache.get(&~"1"), vec![10, 19]);
|
||||
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]);
|
||||
assert_eq!(cache.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_expire_lru() {
|
||||
let mut cache: LruCache<~str, ~str> = LruCache::new(2);
|
||||
cache.put(~"foo1", ~"bar1");
|
||||
cache.put(~"foo2", ~"bar2");
|
||||
cache.put(~"foo3", ~"bar3");
|
||||
assert!(cache.get(&~"foo1").is_none());
|
||||
cache.put(~"foo2", ~"bar2update");
|
||||
cache.put(~"foo4", ~"bar4");
|
||||
assert!(cache.get(&~"foo3").is_none());
|
||||
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());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -343,15 +343,15 @@ mod tests {
|
|||
cache.put(1, 10);
|
||||
cache.put(2, 20);
|
||||
cache.put(3, 30);
|
||||
assert_eq!(cache.to_str(), ~"{3: 30, 2: 20, 1: 10}");
|
||||
assert_eq!(cache.to_str(), "{3: 30, 2: 20, 1: 10}".to_owned());
|
||||
cache.put(2, 22);
|
||||
assert_eq!(cache.to_str(), ~"{2: 22, 3: 30, 1: 10}");
|
||||
assert_eq!(cache.to_str(), "{2: 22, 3: 30, 1: 10}".to_owned());
|
||||
cache.put(6, 60);
|
||||
assert_eq!(cache.to_str(), ~"{6: 60, 2: 22, 3: 30}");
|
||||
assert_eq!(cache.to_str(), "{6: 60, 2: 22, 3: 30}".to_owned());
|
||||
cache.get(&3);
|
||||
assert_eq!(cache.to_str(), ~"{3: 30, 6: 60, 2: 22}");
|
||||
assert_eq!(cache.to_str(), "{3: 30, 6: 60, 2: 22}".to_owned());
|
||||
cache.change_capacity(2);
|
||||
assert_eq!(cache.to_str(), ~"{3: 30, 6: 60}");
|
||||
assert_eq!(cache.to_str(), "{3: 30, 6: 60}".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -362,6 +362,6 @@ mod tests {
|
|||
cache.clear();
|
||||
assert!(cache.get(&1).is_none());
|
||||
assert!(cache.get(&2).is_none());
|
||||
assert_eq!(cache.to_str(), ~"{}");
|
||||
assert_eq!(cache.to_str(), "{}".to_owned());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -419,7 +419,7 @@ pub fn optflag(short_name: &str, long_name: &str, desc: &str) -> OptGroup {
|
|||
OptGroup {
|
||||
short_name: short_name.to_owned(),
|
||||
long_name: long_name.to_owned(),
|
||||
hint: ~"",
|
||||
hint: "".to_owned(),
|
||||
desc: desc.to_owned(),
|
||||
hasarg: No,
|
||||
occur: Optional
|
||||
|
@ -434,7 +434,7 @@ pub fn optflagmulti(short_name: &str, long_name: &str, desc: &str) -> OptGroup {
|
|||
OptGroup {
|
||||
short_name: short_name.to_owned(),
|
||||
long_name: long_name.to_owned(),
|
||||
hint: ~"",
|
||||
hint: "".to_owned(),
|
||||
desc: desc.to_owned(),
|
||||
hasarg: No,
|
||||
occur: Multi
|
||||
|
@ -532,7 +532,7 @@ pub fn getopts(args: &[~str], optgrps: &[OptGroup]) -> Result {
|
|||
let curlen = cur.len();
|
||||
if !is_arg(cur) {
|
||||
free.push(cur);
|
||||
} else if cur == ~"--" {
|
||||
} else if cur == "--".to_owned() {
|
||||
let mut j = i + 1;
|
||||
while j < l { free.push(args[j].clone()); j += 1; }
|
||||
break;
|
||||
|
@ -893,11 +893,11 @@ fn test_split_within() {
|
|||
}
|
||||
t("", 0, []);
|
||||
t("", 15, []);
|
||||
t("hello", 15, [~"hello"]);
|
||||
t("hello", 15, ["hello".to_owned()]);
|
||||
t("\nMary had a little lamb\nLittle lamb\n", 15,
|
||||
[~"Mary had a", ~"little lamb", ~"Little lamb"]);
|
||||
["Mary had a".to_owned(), "little lamb".to_owned(), "Little lamb".to_owned()]);
|
||||
t("\nMary had a little lamb\nLittle lamb\n", ::std::uint::MAX,
|
||||
[~"Mary had a little lamb\nLittle lamb"]);
|
||||
["Mary had a little lamb\nLittle lamb".to_owned()]);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -920,25 +920,25 @@ mod tests {
|
|||
// Tests for reqopt
|
||||
#[test]
|
||||
fn test_reqopt() {
|
||||
let long_args = vec!(~"--test=20");
|
||||
let long_args = vec!("--test=20".to_owned());
|
||||
let opts = vec!(reqopt("t", "test", "testing", "TEST"));
|
||||
let rs = getopts(long_args.as_slice(), opts.as_slice());
|
||||
match rs {
|
||||
Ok(ref m) => {
|
||||
assert!(m.opt_present("test"));
|
||||
assert_eq!(m.opt_str("test").unwrap(), ~"20");
|
||||
assert_eq!(m.opt_str("test").unwrap(), "20".to_owned());
|
||||
assert!(m.opt_present("t"));
|
||||
assert_eq!(m.opt_str("t").unwrap(), ~"20");
|
||||
assert_eq!(m.opt_str("t").unwrap(), "20".to_owned());
|
||||
}
|
||||
_ => { fail!("test_reqopt failed (long arg)"); }
|
||||
}
|
||||
let short_args = vec!(~"-t", ~"20");
|
||||
let short_args = vec!("-t".to_owned(), "20".to_owned());
|
||||
match getopts(short_args.as_slice(), opts.as_slice()) {
|
||||
Ok(ref m) => {
|
||||
assert!((m.opt_present("test")));
|
||||
assert_eq!(m.opt_str("test").unwrap(), ~"20");
|
||||
assert_eq!(m.opt_str("test").unwrap(), "20".to_owned());
|
||||
assert!((m.opt_present("t")));
|
||||
assert_eq!(m.opt_str("t").unwrap(), ~"20");
|
||||
assert_eq!(m.opt_str("t").unwrap(), "20".to_owned());
|
||||
}
|
||||
_ => { fail!("test_reqopt failed (short arg)"); }
|
||||
}
|
||||
|
@ -946,7 +946,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_reqopt_missing() {
|
||||
let args = vec!(~"blah");
|
||||
let args = vec!("blah".to_owned());
|
||||
let opts = vec!(reqopt("t", "test", "testing", "TEST"));
|
||||
let rs = getopts(args.as_slice(), opts.as_slice());
|
||||
match rs {
|
||||
|
@ -957,14 +957,14 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_reqopt_no_arg() {
|
||||
let long_args = vec!(~"--test");
|
||||
let long_args = vec!("--test".to_owned());
|
||||
let opts = vec!(reqopt("t", "test", "testing", "TEST"));
|
||||
let rs = getopts(long_args.as_slice(), opts.as_slice());
|
||||
match rs {
|
||||
Err(f) => check_fail_type(f, ArgumentMissing_),
|
||||
_ => fail!()
|
||||
}
|
||||
let short_args = vec!(~"-t");
|
||||
let short_args = vec!("-t".to_owned());
|
||||
match getopts(short_args.as_slice(), opts.as_slice()) {
|
||||
Err(f) => check_fail_type(f, ArgumentMissing_),
|
||||
_ => fail!()
|
||||
|
@ -973,7 +973,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_reqopt_multi() {
|
||||
let args = vec!(~"--test=20", ~"-t", ~"30");
|
||||
let args = vec!("--test=20".to_owned(), "-t".to_owned(), "30".to_owned());
|
||||
let opts = vec!(reqopt("t", "test", "testing", "TEST"));
|
||||
let rs = getopts(args.as_slice(), opts.as_slice());
|
||||
match rs {
|
||||
|
@ -985,25 +985,25 @@ mod tests {
|
|||
// Tests for optopt
|
||||
#[test]
|
||||
fn test_optopt() {
|
||||
let long_args = vec!(~"--test=20");
|
||||
let long_args = vec!("--test=20".to_owned());
|
||||
let opts = vec!(optopt("t", "test", "testing", "TEST"));
|
||||
let rs = getopts(long_args.as_slice(), opts.as_slice());
|
||||
match rs {
|
||||
Ok(ref m) => {
|
||||
assert!(m.opt_present("test"));
|
||||
assert_eq!(m.opt_str("test").unwrap(), ~"20");
|
||||
assert_eq!(m.opt_str("test").unwrap(), "20".to_owned());
|
||||
assert!((m.opt_present("t")));
|
||||
assert_eq!(m.opt_str("t").unwrap(), ~"20");
|
||||
assert_eq!(m.opt_str("t").unwrap(), "20".to_owned());
|
||||
}
|
||||
_ => fail!()
|
||||
}
|
||||
let short_args = vec!(~"-t", ~"20");
|
||||
let short_args = vec!("-t".to_owned(), "20".to_owned());
|
||||
match getopts(short_args.as_slice(), opts.as_slice()) {
|
||||
Ok(ref m) => {
|
||||
assert!((m.opt_present("test")));
|
||||
assert_eq!(m.opt_str("test").unwrap(), ~"20");
|
||||
assert_eq!(m.opt_str("test").unwrap(), "20".to_owned());
|
||||
assert!((m.opt_present("t")));
|
||||
assert_eq!(m.opt_str("t").unwrap(), ~"20");
|
||||
assert_eq!(m.opt_str("t").unwrap(), "20".to_owned());
|
||||
}
|
||||
_ => fail!()
|
||||
}
|
||||
|
@ -1011,7 +1011,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_optopt_missing() {
|
||||
let args = vec!(~"blah");
|
||||
let args = vec!("blah".to_owned());
|
||||
let opts = vec!(optopt("t", "test", "testing", "TEST"));
|
||||
let rs = getopts(args.as_slice(), opts.as_slice());
|
||||
match rs {
|
||||
|
@ -1025,14 +1025,14 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_optopt_no_arg() {
|
||||
let long_args = vec!(~"--test");
|
||||
let long_args = vec!("--test".to_owned());
|
||||
let opts = vec!(optopt("t", "test", "testing", "TEST"));
|
||||
let rs = getopts(long_args.as_slice(), opts.as_slice());
|
||||
match rs {
|
||||
Err(f) => check_fail_type(f, ArgumentMissing_),
|
||||
_ => fail!()
|
||||
}
|
||||
let short_args = vec!(~"-t");
|
||||
let short_args = vec!("-t".to_owned());
|
||||
match getopts(short_args.as_slice(), opts.as_slice()) {
|
||||
Err(f) => check_fail_type(f, ArgumentMissing_),
|
||||
_ => fail!()
|
||||
|
@ -1041,7 +1041,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_optopt_multi() {
|
||||
let args = vec!(~"--test=20", ~"-t", ~"30");
|
||||
let args = vec!("--test=20".to_owned(), "-t".to_owned(), "30".to_owned());
|
||||
let opts = vec!(optopt("t", "test", "testing", "TEST"));
|
||||
let rs = getopts(args.as_slice(), opts.as_slice());
|
||||
match rs {
|
||||
|
@ -1053,7 +1053,7 @@ mod tests {
|
|||
// Tests for optflag
|
||||
#[test]
|
||||
fn test_optflag() {
|
||||
let long_args = vec!(~"--test");
|
||||
let long_args = vec!("--test".to_owned());
|
||||
let opts = vec!(optflag("t", "test", "testing"));
|
||||
let rs = getopts(long_args.as_slice(), opts.as_slice());
|
||||
match rs {
|
||||
|
@ -1063,7 +1063,7 @@ mod tests {
|
|||
}
|
||||
_ => fail!()
|
||||
}
|
||||
let short_args = vec!(~"-t");
|
||||
let short_args = vec!("-t".to_owned());
|
||||
match getopts(short_args.as_slice(), opts.as_slice()) {
|
||||
Ok(ref m) => {
|
||||
assert!(m.opt_present("test"));
|
||||
|
@ -1075,7 +1075,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_optflag_missing() {
|
||||
let args = vec!(~"blah");
|
||||
let args = vec!("blah".to_owned());
|
||||
let opts = vec!(optflag("t", "test", "testing"));
|
||||
let rs = getopts(args.as_slice(), opts.as_slice());
|
||||
match rs {
|
||||
|
@ -1089,7 +1089,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_optflag_long_arg() {
|
||||
let args = vec!(~"--test=20");
|
||||
let args = vec!("--test=20".to_owned());
|
||||
let opts = vec!(optflag("t", "test", "testing"));
|
||||
let rs = getopts(args.as_slice(), opts.as_slice());
|
||||
match rs {
|
||||
|
@ -1103,7 +1103,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_optflag_multi() {
|
||||
let args = vec!(~"--test", ~"-t");
|
||||
let args = vec!("--test".to_owned(), "-t".to_owned());
|
||||
let opts = vec!(optflag("t", "test", "testing"));
|
||||
let rs = getopts(args.as_slice(), opts.as_slice());
|
||||
match rs {
|
||||
|
@ -1114,14 +1114,14 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_optflag_short_arg() {
|
||||
let args = vec!(~"-t", ~"20");
|
||||
let args = vec!("-t".to_owned(), "20".to_owned());
|
||||
let opts = vec!(optflag("t", "test", "testing"));
|
||||
let rs = getopts(args.as_slice(), opts.as_slice());
|
||||
match rs {
|
||||
Ok(ref m) => {
|
||||
// The next variable after the flag is just a free argument
|
||||
|
||||
assert!(*m.free.get(0) == ~"20");
|
||||
assert!(*m.free.get(0) == "20".to_owned());
|
||||
}
|
||||
_ => fail!()
|
||||
}
|
||||
|
@ -1130,7 +1130,7 @@ mod tests {
|
|||
// Tests for optflagmulti
|
||||
#[test]
|
||||
fn test_optflagmulti_short1() {
|
||||
let args = vec!(~"-v");
|
||||
let args = vec!("-v".to_owned());
|
||||
let opts = vec!(optflagmulti("v", "verbose", "verbosity"));
|
||||
let rs = getopts(args.as_slice(), opts.as_slice());
|
||||
match rs {
|
||||
|
@ -1143,7 +1143,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_optflagmulti_short2a() {
|
||||
let args = vec!(~"-v", ~"-v");
|
||||
let args = vec!("-v".to_owned(), "-v".to_owned());
|
||||
let opts = vec!(optflagmulti("v", "verbose", "verbosity"));
|
||||
let rs = getopts(args.as_slice(), opts.as_slice());
|
||||
match rs {
|
||||
|
@ -1156,7 +1156,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_optflagmulti_short2b() {
|
||||
let args = vec!(~"-vv");
|
||||
let args = vec!("-vv".to_owned());
|
||||
let opts = vec!(optflagmulti("v", "verbose", "verbosity"));
|
||||
let rs = getopts(args.as_slice(), opts.as_slice());
|
||||
match rs {
|
||||
|
@ -1169,7 +1169,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_optflagmulti_long1() {
|
||||
let args = vec!(~"--verbose");
|
||||
let args = vec!("--verbose".to_owned());
|
||||
let opts = vec!(optflagmulti("v", "verbose", "verbosity"));
|
||||
let rs = getopts(args.as_slice(), opts.as_slice());
|
||||
match rs {
|
||||
|
@ -1182,7 +1182,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_optflagmulti_long2() {
|
||||
let args = vec!(~"--verbose", ~"--verbose");
|
||||
let args = vec!("--verbose".to_owned(), "--verbose".to_owned());
|
||||
let opts = vec!(optflagmulti("v", "verbose", "verbosity"));
|
||||
let rs = getopts(args.as_slice(), opts.as_slice());
|
||||
match rs {
|
||||
|
@ -1195,7 +1195,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_optflagmulti_mix() {
|
||||
let args = vec!(~"--verbose", ~"-v", ~"-vv", ~"verbose");
|
||||
let args = vec!("--verbose".to_owned(), "-v".to_owned(),
|
||||
"-vv".to_owned(), "verbose".to_owned());
|
||||
let opts = vec!(optflagmulti("v", "verbose", "verbosity"));
|
||||
let rs = getopts(args.as_slice(), opts.as_slice());
|
||||
match rs {
|
||||
|
@ -1210,25 +1211,25 @@ mod tests {
|
|||
// Tests for optmulti
|
||||
#[test]
|
||||
fn test_optmulti() {
|
||||
let long_args = vec!(~"--test=20");
|
||||
let long_args = vec!("--test=20".to_owned());
|
||||
let opts = vec!(optmulti("t", "test", "testing", "TEST"));
|
||||
let rs = getopts(long_args.as_slice(), opts.as_slice());
|
||||
match rs {
|
||||
Ok(ref m) => {
|
||||
assert!((m.opt_present("test")));
|
||||
assert_eq!(m.opt_str("test").unwrap(), ~"20");
|
||||
assert_eq!(m.opt_str("test").unwrap(), "20".to_owned());
|
||||
assert!((m.opt_present("t")));
|
||||
assert_eq!(m.opt_str("t").unwrap(), ~"20");
|
||||
assert_eq!(m.opt_str("t").unwrap(), "20".to_owned());
|
||||
}
|
||||
_ => fail!()
|
||||
}
|
||||
let short_args = vec!(~"-t", ~"20");
|
||||
let short_args = vec!("-t".to_owned(), "20".to_owned());
|
||||
match getopts(short_args.as_slice(), opts.as_slice()) {
|
||||
Ok(ref m) => {
|
||||
assert!((m.opt_present("test")));
|
||||
assert_eq!(m.opt_str("test").unwrap(), ~"20");
|
||||
assert_eq!(m.opt_str("test").unwrap(), "20".to_owned());
|
||||
assert!((m.opt_present("t")));
|
||||
assert_eq!(m.opt_str("t").unwrap(), ~"20");
|
||||
assert_eq!(m.opt_str("t").unwrap(), "20".to_owned());
|
||||
}
|
||||
_ => fail!()
|
||||
}
|
||||
|
@ -1236,7 +1237,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_optmulti_missing() {
|
||||
let args = vec!(~"blah");
|
||||
let args = vec!("blah".to_owned());
|
||||
let opts = vec!(optmulti("t", "test", "testing", "TEST"));
|
||||
let rs = getopts(args.as_slice(), opts.as_slice());
|
||||
match rs {
|
||||
|
@ -1250,14 +1251,14 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_optmulti_no_arg() {
|
||||
let long_args = vec!(~"--test");
|
||||
let long_args = vec!("--test".to_owned());
|
||||
let opts = vec!(optmulti("t", "test", "testing", "TEST"));
|
||||
let rs = getopts(long_args.as_slice(), opts.as_slice());
|
||||
match rs {
|
||||
Err(f) => check_fail_type(f, ArgumentMissing_),
|
||||
_ => fail!()
|
||||
}
|
||||
let short_args = vec!(~"-t");
|
||||
let short_args = vec!("-t".to_owned());
|
||||
match getopts(short_args.as_slice(), opts.as_slice()) {
|
||||
Err(f) => check_fail_type(f, ArgumentMissing_),
|
||||
_ => fail!()
|
||||
|
@ -1266,18 +1267,18 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_optmulti_multi() {
|
||||
let args = vec!(~"--test=20", ~"-t", ~"30");
|
||||
let args = vec!("--test=20".to_owned(), "-t".to_owned(), "30".to_owned());
|
||||
let opts = vec!(optmulti("t", "test", "testing", "TEST"));
|
||||
let rs = getopts(args.as_slice(), opts.as_slice());
|
||||
match rs {
|
||||
Ok(ref m) => {
|
||||
assert!(m.opt_present("test"));
|
||||
assert_eq!(m.opt_str("test").unwrap(), ~"20");
|
||||
assert_eq!(m.opt_str("test").unwrap(), "20".to_owned());
|
||||
assert!(m.opt_present("t"));
|
||||
assert_eq!(m.opt_str("t").unwrap(), ~"20");
|
||||
assert_eq!(m.opt_str("t").unwrap(), "20".to_owned());
|
||||
let pair = m.opt_strs("test");
|
||||
assert!(*pair.get(0) == ~"20");
|
||||
assert!(*pair.get(1) == ~"30");
|
||||
assert!(*pair.get(0) == "20".to_owned());
|
||||
assert!(*pair.get(1) == "30".to_owned());
|
||||
}
|
||||
_ => fail!()
|
||||
}
|
||||
|
@ -1285,14 +1286,14 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_unrecognized_option() {
|
||||
let long_args = vec!(~"--untest");
|
||||
let long_args = vec!("--untest".to_owned());
|
||||
let opts = vec!(optmulti("t", "test", "testing", "TEST"));
|
||||
let rs = getopts(long_args.as_slice(), opts.as_slice());
|
||||
match rs {
|
||||
Err(f) => check_fail_type(f, UnrecognizedOption_),
|
||||
_ => fail!()
|
||||
}
|
||||
let short_args = vec!(~"-u");
|
||||
let short_args = vec!("-u".to_owned());
|
||||
match getopts(short_args.as_slice(), opts.as_slice()) {
|
||||
Err(f) => check_fail_type(f, UnrecognizedOption_),
|
||||
_ => fail!()
|
||||
|
@ -1302,9 +1303,10 @@ mod tests {
|
|||
#[test]
|
||||
fn test_combined() {
|
||||
let args =
|
||||
vec!(~"prog", ~"free1", ~"-s", ~"20", ~"free2",
|
||||
~"--flag", ~"--long=30", ~"-f", ~"-m", ~"40",
|
||||
~"-m", ~"50", ~"-n", ~"-A B", ~"-n", ~"-60 70");
|
||||
vec!("prog".to_owned(), "free1".to_owned(), "-s".to_owned(), "20".to_owned(),
|
||||
"free2".to_owned(), "--flag".to_owned(), "--long=30".to_owned(), "-f".to_owned(),
|
||||
"-m".to_owned(), "40".to_owned(), "-m".to_owned(), "50".to_owned(), "-n".to_owned(),
|
||||
"-A B".to_owned(), "-n".to_owned(), "-60 70".to_owned());
|
||||
let opts =
|
||||
vec!(optopt("s", "something", "something", "SOMETHING"),
|
||||
optflag("", "flag", "a flag"),
|
||||
|
@ -1316,19 +1318,19 @@ mod tests {
|
|||
let rs = getopts(args.as_slice(), opts.as_slice());
|
||||
match rs {
|
||||
Ok(ref m) => {
|
||||
assert!(*m.free.get(0) == ~"prog");
|
||||
assert!(*m.free.get(1) == ~"free1");
|
||||
assert_eq!(m.opt_str("s").unwrap(), ~"20");
|
||||
assert!(*m.free.get(2) == ~"free2");
|
||||
assert!(*m.free.get(0) == "prog".to_owned());
|
||||
assert!(*m.free.get(1) == "free1".to_owned());
|
||||
assert_eq!(m.opt_str("s").unwrap(), "20".to_owned());
|
||||
assert!(*m.free.get(2) == "free2".to_owned());
|
||||
assert!((m.opt_present("flag")));
|
||||
assert_eq!(m.opt_str("long").unwrap(), ~"30");
|
||||
assert_eq!(m.opt_str("long").unwrap(), "30".to_owned());
|
||||
assert!((m.opt_present("f")));
|
||||
let pair = m.opt_strs("m");
|
||||
assert!(*pair.get(0) == ~"40");
|
||||
assert!(*pair.get(1) == ~"50");
|
||||
assert!(*pair.get(0) == "40".to_owned());
|
||||
assert!(*pair.get(1) == "50".to_owned());
|
||||
let pair = m.opt_strs("n");
|
||||
assert!(*pair.get(0) == ~"-A B");
|
||||
assert!(*pair.get(1) == ~"-60 70");
|
||||
assert!(*pair.get(0) == "-A B".to_owned());
|
||||
assert!(*pair.get(1) == "-60 70".to_owned());
|
||||
assert!((!m.opt_present("notpresent")));
|
||||
}
|
||||
_ => fail!()
|
||||
|
@ -1341,63 +1343,68 @@ mod tests {
|
|||
optopt("", "encrypt", "encrypt", "ENCRYPT"),
|
||||
optopt("f", "", "flag", "FLAG"));
|
||||
|
||||
let args_single = vec!(~"-e", ~"foo");
|
||||
let args_single = vec!("-e".to_owned(), "foo".to_owned());
|
||||
let matches_single = &match getopts(args_single.as_slice(),
|
||||
opts.as_slice()) {
|
||||
result::Ok(m) => m,
|
||||
result::Err(_) => fail!()
|
||||
};
|
||||
assert!(matches_single.opts_present([~"e"]));
|
||||
assert!(matches_single.opts_present([~"encrypt", ~"e"]));
|
||||
assert!(matches_single.opts_present([~"e", ~"encrypt"]));
|
||||
assert!(!matches_single.opts_present([~"encrypt"]));
|
||||
assert!(!matches_single.opts_present([~"thing"]));
|
||||
assert!(matches_single.opts_present(["e".to_owned()]));
|
||||
assert!(matches_single.opts_present(["encrypt".to_owned(), "e".to_owned()]));
|
||||
assert!(matches_single.opts_present(["e".to_owned(), "encrypt".to_owned()]));
|
||||
assert!(!matches_single.opts_present(["encrypt".to_owned()]));
|
||||
assert!(!matches_single.opts_present(["thing".to_owned()]));
|
||||
assert!(!matches_single.opts_present([]));
|
||||
|
||||
assert_eq!(matches_single.opts_str([~"e"]).unwrap(), ~"foo");
|
||||
assert_eq!(matches_single.opts_str([~"e", ~"encrypt"]).unwrap(), ~"foo");
|
||||
assert_eq!(matches_single.opts_str([~"encrypt", ~"e"]).unwrap(), ~"foo");
|
||||
assert_eq!(matches_single.opts_str(["e".to_owned()]).unwrap(), "foo".to_owned());
|
||||
assert_eq!(matches_single.opts_str(["e".to_owned(), "encrypt".to_owned()]).unwrap(),
|
||||
"foo".to_owned());
|
||||
assert_eq!(matches_single.opts_str(["encrypt".to_owned(), "e".to_owned()]).unwrap(),
|
||||
"foo".to_owned());
|
||||
|
||||
let args_both = vec!(~"-e", ~"foo", ~"--encrypt", ~"foo");
|
||||
let args_both = vec!("-e".to_owned(), "foo".to_owned(), "--encrypt".to_owned(),
|
||||
"foo".to_owned());
|
||||
let matches_both = &match getopts(args_both.as_slice(),
|
||||
opts.as_slice()) {
|
||||
result::Ok(m) => m,
|
||||
result::Err(_) => fail!()
|
||||
};
|
||||
assert!(matches_both.opts_present([~"e"]));
|
||||
assert!(matches_both.opts_present([~"encrypt"]));
|
||||
assert!(matches_both.opts_present([~"encrypt", ~"e"]));
|
||||
assert!(matches_both.opts_present([~"e", ~"encrypt"]));
|
||||
assert!(!matches_both.opts_present([~"f"]));
|
||||
assert!(!matches_both.opts_present([~"thing"]));
|
||||
assert!(matches_both.opts_present(["e".to_owned()]));
|
||||
assert!(matches_both.opts_present(["encrypt".to_owned()]));
|
||||
assert!(matches_both.opts_present(["encrypt".to_owned(), "e".to_owned()]));
|
||||
assert!(matches_both.opts_present(["e".to_owned(), "encrypt".to_owned()]));
|
||||
assert!(!matches_both.opts_present(["f".to_owned()]));
|
||||
assert!(!matches_both.opts_present(["thing".to_owned()]));
|
||||
assert!(!matches_both.opts_present([]));
|
||||
|
||||
assert_eq!(matches_both.opts_str([~"e"]).unwrap(), ~"foo");
|
||||
assert_eq!(matches_both.opts_str([~"encrypt"]).unwrap(), ~"foo");
|
||||
assert_eq!(matches_both.opts_str([~"e", ~"encrypt"]).unwrap(), ~"foo");
|
||||
assert_eq!(matches_both.opts_str([~"encrypt", ~"e"]).unwrap(), ~"foo");
|
||||
assert_eq!(matches_both.opts_str(["e".to_owned()]).unwrap(), "foo".to_owned());
|
||||
assert_eq!(matches_both.opts_str(["encrypt".to_owned()]).unwrap(), "foo".to_owned());
|
||||
assert_eq!(matches_both.opts_str(["e".to_owned(), "encrypt".to_owned()]).unwrap(),
|
||||
"foo".to_owned());
|
||||
assert_eq!(matches_both.opts_str(["encrypt".to_owned(), "e".to_owned()]).unwrap(),
|
||||
"foo".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_nospace() {
|
||||
let args = vec!(~"-Lfoo", ~"-M.");
|
||||
let args = vec!("-Lfoo".to_owned(), "-M.".to_owned());
|
||||
let opts = vec!(optmulti("L", "", "library directory", "LIB"),
|
||||
optmulti("M", "", "something", "MMMM"));
|
||||
let matches = &match getopts(args.as_slice(), opts.as_slice()) {
|
||||
result::Ok(m) => m,
|
||||
result::Err(_) => fail!()
|
||||
};
|
||||
assert!(matches.opts_present([~"L"]));
|
||||
assert_eq!(matches.opts_str([~"L"]).unwrap(), ~"foo");
|
||||
assert!(matches.opts_present([~"M"]));
|
||||
assert_eq!(matches.opts_str([~"M"]).unwrap(), ~".");
|
||||
assert!(matches.opts_present(["L".to_owned()]));
|
||||
assert_eq!(matches.opts_str(["L".to_owned()]).unwrap(), "foo".to_owned());
|
||||
assert!(matches.opts_present(["M".to_owned()]));
|
||||
assert_eq!(matches.opts_str(["M".to_owned()]).unwrap(), ".".to_owned());
|
||||
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_long_to_short() {
|
||||
let mut short = Opt {
|
||||
name: Long(~"banana"),
|
||||
name: Long("banana".to_owned()),
|
||||
hasarg: Yes,
|
||||
occur: Req,
|
||||
aliases: Vec::new(),
|
||||
|
@ -1416,7 +1423,7 @@ mod tests {
|
|||
let opts = vec!(
|
||||
optflagmulti("a", "apple", "Desc"));
|
||||
|
||||
let args = vec!(~"-a", ~"--apple", ~"-a");
|
||||
let args = vec!("-a".to_owned(), "--apple".to_owned(), "-a".to_owned());
|
||||
|
||||
let matches = getopts(args.as_slice(), opts.as_slice()).unwrap();
|
||||
assert_eq!(3, matches.opt_count("a"));
|
||||
|
@ -1515,7 +1522,7 @@ Options:
|
|||
optflagopt("p", "", "Desc", "VAL"),
|
||||
optmulti("l", "", "Desc", "VAL"));
|
||||
|
||||
let expected = ~"Usage: fruits -b VAL [-a VAL] [-k] [-p [VAL]] [-l VAL]..";
|
||||
let expected = "Usage: fruits -b VAL [-a VAL] [-k] [-p [VAL]] [-l VAL]..".to_owned();
|
||||
let generated_usage = short_usage("fruits", optgroups.as_slice());
|
||||
|
||||
debug!("expected: <<{}>>", expected);
|
||||
|
|
|
@ -767,7 +767,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_pattern_escape() {
|
||||
let s = "_[_]_?_*_!_";
|
||||
assert_eq!(Pattern::escape(s), ~"_[[]_[]]_[?]_[*]_!_");
|
||||
assert_eq!(Pattern::escape(s), "_[[]_[]]_[?]_[*]_!_".to_owned());
|
||||
assert!(Pattern::new(Pattern::escape(s)).matches(s));
|
||||
}
|
||||
|
||||
|
|
|
@ -74,26 +74,26 @@ fn hex_float_lit_err(s: &str) -> Option<(uint, ~str)> {
|
|||
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'")); } i+=1;
|
||||
if chars.next() != Some('x') { return Some((i, ~"Expected 'x'")); } 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;
|
||||
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 '.'")); } i+=1;
|
||||
if chars.next() != Some('.') { return Some((i, "Expected '.'".to_owned())); } 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"));
|
||||
return Some((i, "Expected digits before or after decimal point".to_owned()));
|
||||
}
|
||||
if chars.next() != Some('p') { return Some((i, ~"Expected 'p'")); } i+=1;
|
||||
if chars.next() != Some('p') { return Some((i, "Expected 'p'".to_owned())); } 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"));
|
||||
return Some((i, "Expected exponent digits".to_owned()));
|
||||
}
|
||||
match chars.next() {
|
||||
None => None,
|
||||
Some(_) => Some((i, ~"Expected end of string"))
|
||||
Some(_) => Some((i, "Expected end of string".to_owned()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -79,13 +79,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"));
|
||||
assert_eq!(dirs[0].name, Some("crate1::mod1".to_owned()));
|
||||
assert_eq!(dirs[0].level, 1);
|
||||
|
||||
assert_eq!(dirs[1].name, Some(~"crate1::mod2"));
|
||||
assert_eq!(dirs[1].name, Some("crate1::mod2".to_owned()));
|
||||
assert_eq!(dirs[1].level, ::MAX_LOG_LEVEL);
|
||||
|
||||
assert_eq!(dirs[2].name, Some(~"crate2"));
|
||||
assert_eq!(dirs[2].name, Some("crate2".to_owned()));
|
||||
assert_eq!(dirs[2].level, 4);
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,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"));
|
||||
assert_eq!(dirs[0].name, Some("crate2".to_owned()));
|
||||
assert_eq!(dirs[0].level, 4);
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,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"));
|
||||
assert_eq!(dirs[0].name, Some("crate2".to_owned()));
|
||||
assert_eq!(dirs[0].level, 4);
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,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"));
|
||||
assert_eq!(dirs[0].name, Some("crate2".to_owned()));
|
||||
assert_eq!(dirs[0].level, ::WARN);
|
||||
}
|
||||
|
||||
|
@ -127,7 +127,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"));
|
||||
assert_eq!(dirs[1].name, Some("crate2".to_owned()));
|
||||
assert_eq!(dirs[1].level, 4);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -305,8 +305,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn match_full_path() {
|
||||
let dirs = [LogDirective { name: Some(~"crate2"), level: 3 },
|
||||
LogDirective { name: Some(~"crate1::mod1"), level: 2 }];
|
||||
let dirs = [LogDirective { name: Some("crate2".to_owned()), level: 3 },
|
||||
LogDirective { name: Some("crate1::mod1".to_owned()), level: 2 }];
|
||||
assert!(enabled(2, "crate1::mod1", dirs.iter()));
|
||||
assert!(!enabled(3, "crate1::mod1", dirs.iter()));
|
||||
assert!(enabled(3, "crate2", dirs.iter()));
|
||||
|
@ -315,23 +315,23 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn no_match() {
|
||||
let dirs = [LogDirective { name: Some(~"crate2"), level: 3 },
|
||||
LogDirective { name: Some(~"crate1::mod1"), level: 2 }];
|
||||
let dirs = [LogDirective { name: Some("crate2".to_owned()), level: 3 },
|
||||
LogDirective { name: Some("crate1::mod1".to_owned()), level: 2 }];
|
||||
assert!(!enabled(2, "crate3", dirs.iter()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn match_beginning() {
|
||||
let dirs = [LogDirective { name: Some(~"crate2"), level: 3 },
|
||||
LogDirective { name: Some(~"crate1::mod1"), level: 2 }];
|
||||
let dirs = [LogDirective { name: Some("crate2".to_owned()), level: 3 },
|
||||
LogDirective { name: Some("crate1::mod1".to_owned()), level: 2 }];
|
||||
assert!(enabled(3, "crate2::mod1", dirs.iter()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn match_beginning_longest_match() {
|
||||
let dirs = [LogDirective { name: Some(~"crate2"), level: 3 },
|
||||
LogDirective { name: Some(~"crate2::mod"), level: 4 },
|
||||
LogDirective { name: Some(~"crate1::mod1"), level: 2 }];
|
||||
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 }];
|
||||
assert!(enabled(4, "crate2::mod1", dirs.iter()));
|
||||
assert!(!enabled(4, "crate2", dirs.iter()));
|
||||
}
|
||||
|
@ -339,7 +339,7 @@ mod tests {
|
|||
#[test]
|
||||
fn match_default() {
|
||||
let dirs = [LogDirective { name: None, level: 3 },
|
||||
LogDirective { name: Some(~"crate1::mod1"), level: 2 }];
|
||||
LogDirective { name: Some("crate1::mod1".to_owned()), level: 2 }];
|
||||
assert!(enabled(2, "crate1::mod1", dirs.iter()));
|
||||
assert!(enabled(3, "crate2::mod2", dirs.iter()));
|
||||
}
|
||||
|
@ -347,7 +347,7 @@ mod tests {
|
|||
#[test]
|
||||
fn zero_level() {
|
||||
let dirs = [LogDirective { name: None, level: 3 },
|
||||
LogDirective { name: Some(~"crate1::mod1"), level: 0 }];
|
||||
LogDirective { name: Some("crate1::mod1".to_owned()), level: 0 }];
|
||||
assert!(!enabled(1, "crate1::mod1", dirs.iter()));
|
||||
assert!(enabled(3, "crate2::mod2", dirs.iter()));
|
||||
}
|
||||
|
|
|
@ -854,20 +854,20 @@ mod tests {
|
|||
fn test_make_command_line() {
|
||||
use super::make_command_line;
|
||||
assert_eq!(
|
||||
make_command_line("prog", [~"aaa", ~"bbb", ~"ccc"]),
|
||||
~"prog aaa bbb ccc"
|
||||
make_command_line("prog", ["aaa".to_owned(), "bbb".to_owned(), "ccc".to_owned()]),
|
||||
"prog aaa bbb ccc".to_owned()
|
||||
);
|
||||
assert_eq!(
|
||||
make_command_line("C:\\Program Files\\blah\\blah.exe", [~"aaa"]),
|
||||
~"\"C:\\Program Files\\blah\\blah.exe\" aaa"
|
||||
make_command_line("C:\\Program Files\\blah\\blah.exe", ["aaa".to_owned()]),
|
||||
"\"C:\\Program Files\\blah\\blah.exe\" aaa".to_owned()
|
||||
);
|
||||
assert_eq!(
|
||||
make_command_line("C:\\Program Files\\test", [~"aa\"bb"]),
|
||||
~"\"C:\\Program Files\\test\" aa\\\"bb"
|
||||
make_command_line("C:\\Program Files\\test", ["aa\"bb".to_owned()]),
|
||||
"\"C:\\Program Files\\test\" aa\\\"bb".to_owned()
|
||||
);
|
||||
assert_eq!(
|
||||
make_command_line("echo", [~"a b c"]),
|
||||
~"echo \"a b c\""
|
||||
make_command_line("echo", ["a b c".to_owned()]),
|
||||
"echo \"a b c\"".to_owned()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -665,7 +665,7 @@ impl ToStrRadix for BigUint {
|
|||
}
|
||||
|
||||
fn fill_concat(v: &[BigDigit], radix: uint, l: uint) -> ~str {
|
||||
if v.is_empty() { return ~"0" }
|
||||
if v.is_empty() { return "0".to_owned() }
|
||||
let mut s = StrBuf::with_capacity(v.len() * l);
|
||||
for n in v.rev_iter() {
|
||||
let ss = (*n as uint).to_str_radix(radix);
|
||||
|
@ -1268,8 +1268,8 @@ impl ToStrRadix for BigInt {
|
|||
fn to_str_radix(&self, radix: uint) -> ~str {
|
||||
match self.sign {
|
||||
Plus => self.data.to_str_radix(radix),
|
||||
Zero => ~"0",
|
||||
Minus => ~"-" + self.data.to_str_radix(radix)
|
||||
Zero => "0".to_owned(),
|
||||
Minus => "-".to_owned() + self.data.to_str_radix(radix)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1974,55 +1974,55 @@ mod biguint_tests {
|
|||
fn to_str_pairs() -> Vec<(BigUint, Vec<(uint, ~str)>)> {
|
||||
let bits = BigDigit::bits;
|
||||
vec!(( Zero::zero(), vec!(
|
||||
(2, ~"0"), (3, ~"0")
|
||||
(2, "0".to_owned()), (3, "0".to_owned())
|
||||
)), ( BigUint::from_slice([ 0xff ]), vec!(
|
||||
(2, ~"11111111"),
|
||||
(3, ~"100110"),
|
||||
(4, ~"3333"),
|
||||
(5, ~"2010"),
|
||||
(6, ~"1103"),
|
||||
(7, ~"513"),
|
||||
(8, ~"377"),
|
||||
(9, ~"313"),
|
||||
(10, ~"255"),
|
||||
(11, ~"212"),
|
||||
(12, ~"193"),
|
||||
(13, ~"168"),
|
||||
(14, ~"143"),
|
||||
(15, ~"120"),
|
||||
(16, ~"ff")
|
||||
(2, "11111111".to_owned()),
|
||||
(3, "100110".to_owned()),
|
||||
(4, "3333".to_owned()),
|
||||
(5, "2010".to_owned()),
|
||||
(6, "1103".to_owned()),
|
||||
(7, "513".to_owned()),
|
||||
(8, "377".to_owned()),
|
||||
(9, "313".to_owned()),
|
||||
(10, "255".to_owned()),
|
||||
(11, "212".to_owned()),
|
||||
(12, "193".to_owned()),
|
||||
(13, "168".to_owned()),
|
||||
(14, "143".to_owned()),
|
||||
(15, "120".to_owned()),
|
||||
(16, "ff".to_owned())
|
||||
)), ( BigUint::from_slice([ 0xfff ]), vec!(
|
||||
(2, ~"111111111111"),
|
||||
(4, ~"333333"),
|
||||
(16, ~"fff")
|
||||
(2, "111111111111".to_owned()),
|
||||
(4, "333333".to_owned()),
|
||||
(16, "fff".to_owned())
|
||||
)), ( BigUint::from_slice([ 1, 2 ]), vec!(
|
||||
(2,
|
||||
~"10" +
|
||||
"10".to_owned() +
|
||||
"0".repeat(bits - 1) + "1"),
|
||||
(4,
|
||||
~"2" +
|
||||
"2".to_owned() +
|
||||
"0".repeat(bits / 2 - 1) + "1"),
|
||||
(10, match bits {
|
||||
32 => ~"8589934593", 16 => ~"131073", _ => fail!()
|
||||
32 => "8589934593".to_owned(), 16 => "131073".to_owned(), _ => fail!()
|
||||
}),
|
||||
(16,
|
||||
~"2" +
|
||||
"2".to_owned() +
|
||||
"0".repeat(bits / 4 - 1) + "1")
|
||||
)), ( BigUint::from_slice([ 1, 2, 3 ]), vec!(
|
||||
(2,
|
||||
~"11" +
|
||||
"11".to_owned() +
|
||||
"0".repeat(bits - 2) + "10" +
|
||||
"0".repeat(bits - 1) + "1"),
|
||||
(4,
|
||||
~"3" +
|
||||
"3".to_owned() +
|
||||
"0".repeat(bits / 2 - 1) + "2" +
|
||||
"0".repeat(bits / 2 - 1) + "1"),
|
||||
(10, match bits {
|
||||
32 => ~"55340232229718589441",
|
||||
16 => ~"12885032961",
|
||||
32 => "55340232229718589441".to_owned(),
|
||||
16 => "12885032961".to_owned(),
|
||||
_ => fail!()
|
||||
}),
|
||||
(16, ~"3" +
|
||||
(16, "3".to_owned() +
|
||||
"0".repeat(bits / 4 - 1) + "2" +
|
||||
"0".repeat(bits / 4 - 1) + "1")
|
||||
)) )
|
||||
|
|
|
@ -351,12 +351,12 @@ mod test {
|
|||
fn test(c : Complex64, s: ~str) {
|
||||
assert_eq!(c.to_str(), s);
|
||||
}
|
||||
test(_0_0i, ~"0+0i");
|
||||
test(_1_0i, ~"1+0i");
|
||||
test(_0_1i, ~"0+1i");
|
||||
test(_1_1i, ~"1+1i");
|
||||
test(_neg1_1i, ~"-1+1i");
|
||||
test(-_neg1_1i, ~"1-1i");
|
||||
test(_05_05i, ~"0.5+0.5i");
|
||||
test(_0_0i, "0+0i".to_owned());
|
||||
test(_1_0i, "1+0i".to_owned());
|
||||
test(_0_1i, "0+1i".to_owned());
|
||||
test(_1_1i, "1+1i".to_owned());
|
||||
test(_neg1_1i, "-1+1i".to_owned());
|
||||
test(-_neg1_1i, "1-1i".to_owned());
|
||||
test(_05_05i, "0.5+0.5i".to_owned());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -564,12 +564,12 @@ mod test {
|
|||
assert_eq!(FromStr::from_str(s), Some(r));
|
||||
assert_eq!(r.to_str(), s);
|
||||
}
|
||||
test(_1, ~"1/1");
|
||||
test(_0, ~"0/1");
|
||||
test(_1_2, ~"1/2");
|
||||
test(_3_2, ~"3/2");
|
||||
test(_2, ~"2/1");
|
||||
test(_neg1_2, ~"-1/2");
|
||||
test(_1, "1/1".to_owned());
|
||||
test(_0, "0/1".to_owned());
|
||||
test(_1_2, "1/2".to_owned());
|
||||
test(_3_2, "3/2".to_owned());
|
||||
test(_2, "2/1".to_owned());
|
||||
test(_neg1_2, "-1/2".to_owned());
|
||||
}
|
||||
#[test]
|
||||
fn test_from_str_fail() {
|
||||
|
@ -593,23 +593,23 @@ mod test {
|
|||
fn test3(r: Rational, s: ~str) { test(r, s, 3) }
|
||||
fn test16(r: Rational, s: ~str) { test(r, s, 16) }
|
||||
|
||||
test3(_1, ~"1/1");
|
||||
test3(_0, ~"0/1");
|
||||
test3(_1_2, ~"1/2");
|
||||
test3(_3_2, ~"10/2");
|
||||
test3(_2, ~"2/1");
|
||||
test3(_neg1_2, ~"-1/2");
|
||||
test3(_neg1_2 / _2, ~"-1/11");
|
||||
test3(_1, "1/1".to_owned());
|
||||
test3(_0, "0/1".to_owned());
|
||||
test3(_1_2, "1/2".to_owned());
|
||||
test3(_3_2, "10/2".to_owned());
|
||||
test3(_2, "2/1".to_owned());
|
||||
test3(_neg1_2, "-1/2".to_owned());
|
||||
test3(_neg1_2 / _2, "-1/11".to_owned());
|
||||
|
||||
test16(_1, ~"1/1");
|
||||
test16(_0, ~"0/1");
|
||||
test16(_1_2, ~"1/2");
|
||||
test16(_3_2, ~"3/2");
|
||||
test16(_2, ~"2/1");
|
||||
test16(_neg1_2, ~"-1/2");
|
||||
test16(_neg1_2 / _2, ~"-1/4");
|
||||
test16(Ratio::new(13,15), ~"d/f");
|
||||
test16(_1_2*_1_2*_1_2*_1_2, ~"1/10");
|
||||
test16(_1, "1/1".to_owned());
|
||||
test16(_0, "0/1".to_owned());
|
||||
test16(_1_2, "1/2".to_owned());
|
||||
test16(_3_2, "3/2".to_owned());
|
||||
test16(_2, "2/1".to_owned());
|
||||
test16(_neg1_2, "-1/2".to_owned());
|
||||
test16(_neg1_2 / _2, "-1/4".to_owned());
|
||||
test16(Ratio::new(13,15), "d/f".to_owned());
|
||||
test16(_1_2*_1_2*_1_2*_1_2, "1/10".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -15,18 +15,18 @@ use syntax::abi;
|
|||
|
||||
pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::t {
|
||||
let cc_args = if target_triple.contains("thumb") {
|
||||
vec!(~"-mthumb")
|
||||
vec!("-mthumb".to_owned())
|
||||
} else {
|
||||
vec!(~"-marm")
|
||||
vec!("-marm".to_owned())
|
||||
};
|
||||
return target_strs::t {
|
||||
module_asm: ~"",
|
||||
module_asm: "".to_owned(),
|
||||
|
||||
meta_sect_name: meta_section_name(sess_os_to_meta_os(target_os)).to_owned(),
|
||||
|
||||
data_layout: match target_os {
|
||||
abi::OsMacos => {
|
||||
~"e-p:32:32:32" +
|
||||
"e-p:32:32:32".to_owned() +
|
||||
"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
|
||||
"-f32:32:32-f64:64:64" +
|
||||
"-v64:64:64-v128:64:128" +
|
||||
|
@ -34,7 +34,7 @@ pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::
|
|||
}
|
||||
|
||||
abi::OsWin32 => {
|
||||
~"e-p:32:32:32" +
|
||||
"e-p:32:32:32".to_owned() +
|
||||
"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
|
||||
"-f32:32:32-f64:64:64" +
|
||||
"-v64:64:64-v128:64:128" +
|
||||
|
@ -42,7 +42,7 @@ pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::
|
|||
}
|
||||
|
||||
abi::OsLinux => {
|
||||
~"e-p:32:32:32" +
|
||||
"e-p:32:32:32".to_owned() +
|
||||
"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
|
||||
"-f32:32:32-f64:64:64" +
|
||||
"-v64:64:64-v128:64:128" +
|
||||
|
@ -50,7 +50,7 @@ pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::
|
|||
}
|
||||
|
||||
abi::OsAndroid => {
|
||||
~"e-p:32:32:32" +
|
||||
"e-p:32:32:32".to_owned() +
|
||||
"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
|
||||
"-f32:32:32-f64:64:64" +
|
||||
"-v64:64:64-v128:64:128" +
|
||||
|
@ -58,7 +58,7 @@ pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::
|
|||
}
|
||||
|
||||
abi::OsFreebsd => {
|
||||
~"e-p:32:32:32" +
|
||||
"e-p:32:32:32".to_owned() +
|
||||
"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
|
||||
"-f32:32:32-f64:64:64" +
|
||||
"-v64:64:64-v128:64:128" +
|
||||
|
|
|
@ -79,7 +79,7 @@ pub fn WriteOutputFile(
|
|||
let result = llvm::LLVMRustWriteOutputFile(
|
||||
target, pm, m, output, file_type);
|
||||
if !result {
|
||||
llvm_err(sess, ~"could not write output");
|
||||
llvm_err(sess, "could not write output".to_owned());
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -341,8 +341,8 @@ pub mod write {
|
|||
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
let args = [
|
||||
~"-c",
|
||||
~"-o", object.as_str().unwrap().to_owned(),
|
||||
"-c".to_owned(),
|
||||
"-o".to_owned(), object.as_str().unwrap().to_owned(),
|
||||
assembly.as_str().unwrap().to_owned()];
|
||||
|
||||
debug!("{} '{}'", cc, args.connect("' '"));
|
||||
|
@ -622,7 +622,7 @@ pub fn sanitize(s: &str) -> ~str {
|
|||
if result.len() > 0u &&
|
||||
result[0] != '_' as u8 &&
|
||||
! char::is_XID_start(result[0] as char) {
|
||||
return ~"_" + result;
|
||||
return "_".to_owned() + result;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -738,7 +738,7 @@ pub fn get_cc_prog(sess: &Session) -> ~str {
|
|||
// instead of hard-coded gcc.
|
||||
// For win32, there is no cc command, so we add a condition to make it use gcc.
|
||||
match sess.targ_cfg.os {
|
||||
abi::OsWin32 => return ~"gcc",
|
||||
abi::OsWin32 => return "gcc".to_owned(),
|
||||
_ => {},
|
||||
}
|
||||
|
||||
|
@ -1089,13 +1089,13 @@ fn link_args(sess: &Session,
|
|||
// The location of crates will be determined as needed.
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
let lib_path = sess.filesearch().get_target_lib_path();
|
||||
let stage: ~str = ~"-L" + lib_path.as_str().unwrap();
|
||||
let stage: ~str = "-L".to_owned() + lib_path.as_str().unwrap();
|
||||
|
||||
let mut args = vec!(stage);
|
||||
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
args.push_all([
|
||||
~"-o", out_filename.as_str().unwrap().to_owned(),
|
||||
"-o".to_owned(), out_filename.as_str().unwrap().to_owned(),
|
||||
obj_filename.as_str().unwrap().to_owned()]);
|
||||
|
||||
// Stack growth requires statically linking a __morestack function. Note
|
||||
|
@ -1113,7 +1113,7 @@ fn link_args(sess: &Session,
|
|||
// line, but inserting this farther to the left makes the
|
||||
// "rust_stack_exhausted" symbol an outstanding undefined symbol, which
|
||||
// flags libstd as a required library (or whatever provides the symbol).
|
||||
args.push(~"-lmorestack");
|
||||
args.push("-lmorestack".to_owned());
|
||||
|
||||
// When linking a dynamic library, we put the metadata into a section of the
|
||||
// executable. This metadata is in a separate object file from the main
|
||||
|
@ -1131,14 +1131,14 @@ fn link_args(sess: &Session,
|
|||
//
|
||||
// FIXME(#11937) we should invoke the system linker directly
|
||||
if sess.targ_cfg.os != abi::OsWin32 {
|
||||
args.push(~"-nodefaultlibs");
|
||||
args.push("-nodefaultlibs".to_owned());
|
||||
}
|
||||
|
||||
if sess.targ_cfg.os == abi::OsLinux {
|
||||
// GNU-style linkers will use this to omit linking to libraries which
|
||||
// don't actually fulfill any relocations, but only for libraries which
|
||||
// follow this flag. Thus, use it before specifying libraries to link to.
|
||||
args.push(~"-Wl,--as-needed");
|
||||
args.push("-Wl,--as-needed".to_owned());
|
||||
|
||||
// GNU-style linkers support optimization with -O. --gc-sections
|
||||
// removes metadata and potentially other useful things, so don't
|
||||
|
@ -1146,7 +1146,7 @@ fn link_args(sess: &Session,
|
|||
// do.
|
||||
if sess.opts.optimize == session::Default ||
|
||||
sess.opts.optimize == session::Aggressive {
|
||||
args.push(~"-Wl,-O1");
|
||||
args.push("-Wl,-O1".to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1154,7 +1154,7 @@ fn link_args(sess: &Session,
|
|||
// Make sure that we link to the dynamic libgcc, otherwise cross-module
|
||||
// DWARF stack unwinding will not work.
|
||||
// This behavior may be overridden by --link-args "-static-libgcc"
|
||||
args.push(~"-shared-libgcc");
|
||||
args.push("-shared-libgcc".to_owned());
|
||||
|
||||
// And here, we see obscure linker flags #45. On windows, it has been
|
||||
// found to be necessary to have this flag to compile liblibc.
|
||||
|
@ -1181,13 +1181,13 @@ fn link_args(sess: &Session,
|
|||
//
|
||||
// [1] - https://sourceware.org/bugzilla/show_bug.cgi?id=13130
|
||||
// [2] - https://code.google.com/p/go/issues/detail?id=2139
|
||||
args.push(~"-Wl,--enable-long-section-names");
|
||||
args.push("-Wl,--enable-long-section-names".to_owned());
|
||||
}
|
||||
|
||||
if sess.targ_cfg.os == abi::OsAndroid {
|
||||
// Many of the symbols defined in compiler-rt are also defined in libgcc.
|
||||
// Android linker doesn't like that by default.
|
||||
args.push(~"-Wl,--allow-multiple-definition");
|
||||
args.push("-Wl,--allow-multiple-definition".to_owned());
|
||||
}
|
||||
|
||||
// Take careful note of the ordering of the arguments we pass to the linker
|
||||
|
@ -1232,22 +1232,22 @@ fn link_args(sess: &Session,
|
|||
if dylib {
|
||||
// On mac we need to tell the linker to let this library be rpathed
|
||||
if sess.targ_cfg.os == abi::OsMacos {
|
||||
args.push(~"-dynamiclib");
|
||||
args.push(~"-Wl,-dylib");
|
||||
args.push("-dynamiclib".to_owned());
|
||||
args.push("-Wl,-dylib".to_owned());
|
||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
||||
if !sess.opts.cg.no_rpath {
|
||||
args.push(~"-Wl,-install_name,@rpath/" +
|
||||
args.push("-Wl,-install_name,@rpath/".to_owned() +
|
||||
out_filename.filename_str().unwrap());
|
||||
}
|
||||
} else {
|
||||
args.push(~"-shared")
|
||||
args.push("-shared".to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
if sess.targ_cfg.os == abi::OsFreebsd {
|
||||
args.push_all([~"-L/usr/local/lib",
|
||||
~"-L/usr/local/lib/gcc46",
|
||||
~"-L/usr/local/lib/gcc44"]);
|
||||
args.push_all(["-L/usr/local/lib".to_owned(),
|
||||
"-L/usr/local/lib/gcc46".to_owned(),
|
||||
"-L/usr/local/lib/gcc44".to_owned()]);
|
||||
}
|
||||
|
||||
// FIXME (#2397): At some point we want to rpath our guesses as to
|
||||
|
@ -1264,7 +1264,7 @@ fn link_args(sess: &Session,
|
|||
//
|
||||
// This is the end of the command line, so this library is used to resolve
|
||||
// *all* undefined symbols in all other libraries, and this is intentional.
|
||||
args.push(~"-lcompiler-rt");
|
||||
args.push("-lcompiler-rt".to_owned());
|
||||
|
||||
// Finally add all the linker arguments provided on the command line along
|
||||
// with any #[link_args] attributes found inside the crate
|
||||
|
@ -1304,7 +1304,7 @@ fn add_local_native_libraries(args: &mut Vec<~str>, sess: &Session) {
|
|||
args.push("-l" + *l);
|
||||
}
|
||||
cstore::NativeFramework => {
|
||||
args.push(~"-framework");
|
||||
args.push("-framework".to_owned());
|
||||
args.push(l.to_owned());
|
||||
}
|
||||
}
|
||||
|
@ -1509,7 +1509,7 @@ fn add_upstream_native_libraries(args: &mut Vec<~str>, sess: &Session) {
|
|||
match kind {
|
||||
cstore::NativeUnknown => args.push("-l" + *lib),
|
||||
cstore::NativeFramework => {
|
||||
args.push(~"-framework");
|
||||
args.push("-framework".to_owned());
|
||||
args.push(lib.to_owned());
|
||||
}
|
||||
cstore::NativeStatic => {
|
||||
|
|
|
@ -15,13 +15,13 @@ use syntax::abi;
|
|||
|
||||
pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::t {
|
||||
return target_strs::t {
|
||||
module_asm: ~"",
|
||||
module_asm: "".to_owned(),
|
||||
|
||||
meta_sect_name: meta_section_name(sess_os_to_meta_os(target_os)).to_owned(),
|
||||
|
||||
data_layout: match target_os {
|
||||
abi::OsMacos => {
|
||||
~"E-p:32:32:32" +
|
||||
"E-p:32:32:32".to_owned() +
|
||||
"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
|
||||
"-f32:32:32-f64:64:64" +
|
||||
"-v64:64:64-v128:64:128" +
|
||||
|
@ -29,7 +29,7 @@ pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::
|
|||
}
|
||||
|
||||
abi::OsWin32 => {
|
||||
~"E-p:32:32:32" +
|
||||
"E-p:32:32:32".to_owned() +
|
||||
"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
|
||||
"-f32:32:32-f64:64:64" +
|
||||
"-v64:64:64-v128:64:128" +
|
||||
|
@ -37,7 +37,7 @@ pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::
|
|||
}
|
||||
|
||||
abi::OsLinux => {
|
||||
~"E-p:32:32:32" +
|
||||
"E-p:32:32:32".to_owned() +
|
||||
"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
|
||||
"-f32:32:32-f64:64:64" +
|
||||
"-v64:64:64-v128:64:128" +
|
||||
|
@ -45,7 +45,7 @@ pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::
|
|||
}
|
||||
|
||||
abi::OsAndroid => {
|
||||
~"E-p:32:32:32" +
|
||||
"E-p:32:32:32".to_owned() +
|
||||
"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
|
||||
"-f32:32:32-f64:64:64" +
|
||||
"-v64:64:64-v128:64:128" +
|
||||
|
@ -53,7 +53,7 @@ pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::
|
|||
}
|
||||
|
||||
abi::OsFreebsd => {
|
||||
~"E-p:32:32:32" +
|
||||
"E-p:32:32:32".to_owned() +
|
||||
"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
|
||||
"-f32:32:32-f64:64:64" +
|
||||
"-v64:64:64-v128:64:128" +
|
||||
|
|
|
@ -33,9 +33,9 @@ pub fn get_rpath_flags(sess: &Session, out_filename: &Path) -> Vec<~str> {
|
|||
let mut flags = Vec::new();
|
||||
|
||||
if sess.targ_cfg.os == abi::OsFreebsd {
|
||||
flags.push_all([~"-Wl,-rpath,/usr/local/lib/gcc46",
|
||||
~"-Wl,-rpath,/usr/local/lib/gcc44",
|
||||
~"-Wl,-z,origin"]);
|
||||
flags.push_all(["-Wl,-rpath,/usr/local/lib/gcc46".to_owned(),
|
||||
"-Wl,-rpath,/usr/local/lib/gcc44".to_owned(),
|
||||
"-Wl,-z,origin".to_owned()]);
|
||||
}
|
||||
|
||||
debug!("preparing the RPATH!");
|
||||
|
@ -163,8 +163,8 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_rpaths_to_flags() {
|
||||
let flags = rpaths_to_flags([~"path1", ~"path2"]);
|
||||
assert_eq!(flags, vec!(~"-Wl,-rpath,path1", ~"-Wl,-rpath,path2"));
|
||||
let flags = rpaths_to_flags(["path1".to_owned(), "path2".to_owned()]);
|
||||
assert_eq!(flags, vec!("-Wl,-rpath,path1".to_owned(), "-Wl,-rpath,path2".to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -190,17 +190,18 @@ mod test {
|
|||
|
||||
#[test]
|
||||
fn test_minimize1() {
|
||||
let res = minimize_rpaths([~"rpath1", ~"rpath2", ~"rpath1"]);
|
||||
assert!(res.as_slice() == [~"rpath1", ~"rpath2"]);
|
||||
let res = minimize_rpaths(["rpath1".to_owned(), "rpath2".to_owned(), "rpath1".to_owned()]);
|
||||
assert!(res.as_slice() == ["rpath1".to_owned(), "rpath2".to_owned()]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_minimize2() {
|
||||
let res = minimize_rpaths([~"1a", ~"2", ~"2",
|
||||
~"1a", ~"4a", ~"1a",
|
||||
~"2", ~"3", ~"4a",
|
||||
~"3"]);
|
||||
assert!(res.as_slice() == [~"1a", ~"2", ~"4a", ~"3"]);
|
||||
let res = minimize_rpaths(["1a".to_owned(), "2".to_owned(), "2".to_owned(),
|
||||
"1a".to_owned(), "4a".to_owned(), "1a".to_owned(),
|
||||
"2".to_owned(), "3".to_owned(), "4a".to_owned(),
|
||||
"3".to_owned()]);
|
||||
assert!(res.as_slice() == ["1a".to_owned(), "2".to_owned(), "4a".to_owned(),
|
||||
"3".to_owned()]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -16,36 +16,36 @@ use syntax::abi;
|
|||
|
||||
pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::t {
|
||||
return target_strs::t {
|
||||
module_asm: ~"",
|
||||
module_asm: "".to_owned(),
|
||||
|
||||
meta_sect_name: meta_section_name(sess_os_to_meta_os(target_os)).to_owned(),
|
||||
|
||||
data_layout: match target_os {
|
||||
abi::OsMacos => {
|
||||
~"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16" +
|
||||
"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16".to_owned() +
|
||||
"-i32:32:32-i64:32:64" +
|
||||
"-f32:32:32-f64:32:64-v64:64:64" +
|
||||
"-v128:128:128-a0:0:64-f80:128:128" + "-n8:16:32"
|
||||
}
|
||||
|
||||
abi::OsWin32 => {
|
||||
~"e-p:32:32-f64:64:64-i64:64:64-f80:32:32-n8:16:32"
|
||||
"e-p:32:32-f64:64:64-i64:64:64-f80:32:32-n8:16:32".to_owned()
|
||||
}
|
||||
|
||||
abi::OsLinux => {
|
||||
~"e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32"
|
||||
"e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32".to_owned()
|
||||
}
|
||||
abi::OsAndroid => {
|
||||
~"e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32"
|
||||
"e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32".to_owned()
|
||||
}
|
||||
|
||||
abi::OsFreebsd => {
|
||||
~"e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32"
|
||||
"e-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32".to_owned()
|
||||
}
|
||||
},
|
||||
|
||||
target_triple: target_triple,
|
||||
|
||||
cc_args: vec!(~"-m32"),
|
||||
cc_args: vec!("-m32".to_owned()),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -16,37 +16,37 @@ use syntax::abi;
|
|||
|
||||
pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::t {
|
||||
return target_strs::t {
|
||||
module_asm: ~"",
|
||||
module_asm: "".to_owned(),
|
||||
|
||||
meta_sect_name: meta_section_name(sess_os_to_meta_os(target_os)).to_owned(),
|
||||
|
||||
data_layout: match target_os {
|
||||
abi::OsMacos => {
|
||||
~"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"+
|
||||
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-".to_owned()+
|
||||
"f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-"+
|
||||
"s0:64:64-f80:128:128-n8:16:32:64"
|
||||
}
|
||||
|
||||
abi::OsWin32 => {
|
||||
// FIXME: Test this. Copied from linux (#2398)
|
||||
~"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"+
|
||||
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-".to_owned()+
|
||||
"f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-"+
|
||||
"s0:64:64-f80:128:128-n8:16:32:64-S128"
|
||||
}
|
||||
|
||||
abi::OsLinux => {
|
||||
~"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"+
|
||||
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-".to_owned()+
|
||||
"f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-"+
|
||||
"s0:64:64-f80:128:128-n8:16:32:64-S128"
|
||||
}
|
||||
abi::OsAndroid => {
|
||||
~"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"+
|
||||
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-".to_owned()+
|
||||
"f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-"+
|
||||
"s0:64:64-f80:128:128-n8:16:32:64-S128"
|
||||
}
|
||||
|
||||
abi::OsFreebsd => {
|
||||
~"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"+
|
||||
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-".to_owned()+
|
||||
"f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-"+
|
||||
"s0:64:64-f80:128:128-n8:16:32:64-S128"
|
||||
}
|
||||
|
@ -54,6 +54,6 @@ pub fn get_target_strs(target_triple: ~str, target_os: abi::Os) -> target_strs::
|
|||
|
||||
target_triple: target_triple,
|
||||
|
||||
cc_args: vec!(~"-m64"),
|
||||
cc_args: vec!("-m64".to_owned()),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -161,7 +161,7 @@ impl Input {
|
|||
fn filestem(&self) -> ~str {
|
||||
match *self {
|
||||
FileInput(ref ifile) => ifile.filestem_str().unwrap().to_str(),
|
||||
StrInput(_) => ~"rust_out",
|
||||
StrInput(_) => "rust_out".to_owned(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -615,7 +615,7 @@ impl pprust::PpAnn for IdentifiedAnnotation {
|
|||
}
|
||||
pprust::NodeBlock(blk) => {
|
||||
try!(pp::space(&mut s.s));
|
||||
s.synth_comment(~"block " + blk.id.to_str())
|
||||
s.synth_comment("block ".to_owned() + blk.id.to_str())
|
||||
}
|
||||
pprust::NodeExpr(expr) => {
|
||||
try!(pp::space(&mut s.s));
|
||||
|
@ -624,7 +624,7 @@ impl pprust::PpAnn for IdentifiedAnnotation {
|
|||
}
|
||||
pprust::NodePat(pat) => {
|
||||
try!(pp::space(&mut s.s));
|
||||
s.synth_comment(~"pat " + pat.id.to_str())
|
||||
s.synth_comment("pat ".to_owned() + pat.id.to_str())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1242,7 +1242,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_switch_implies_cfg_test() {
|
||||
let matches =
|
||||
&match getopts([~"--test"], optgroups().as_slice()) {
|
||||
&match getopts(["--test".to_owned()], optgroups().as_slice()) {
|
||||
Ok(m) => m,
|
||||
Err(f) => fail!("test_switch_implies_cfg_test: {}", f.to_err_msg())
|
||||
};
|
||||
|
@ -1257,7 +1257,7 @@ mod test {
|
|||
#[test]
|
||||
fn test_switch_implies_cfg_test_unless_cfg_test() {
|
||||
let matches =
|
||||
&match getopts([~"--test", ~"--cfg=test"],
|
||||
&match getopts(["--test".to_owned(), "--cfg=test".to_owned()],
|
||||
optgroups().as_slice()) {
|
||||
Ok(m) => m,
|
||||
Err(f) => {
|
||||
|
|
|
@ -434,9 +434,9 @@ cgoptions!(
|
|||
"system linker to link outputs with"),
|
||||
link_args: Vec<~str> = (Vec::new(), parse_list,
|
||||
"extra arguments to pass to the linker (space separated)"),
|
||||
target_cpu: ~str = (~"generic", parse_string,
|
||||
target_cpu: ~str = ("generic".to_owned(), parse_string,
|
||||
"select target processor (llc -mcpu=help for details)"),
|
||||
target_feature: ~str = (~"", parse_string,
|
||||
target_feature: ~str = ("".to_owned(), parse_string,
|
||||
"target specific attributes (llc -mattr=help for details)"),
|
||||
passes: Vec<~str> = (Vec::new(), parse_list,
|
||||
"a list of extra LLVM passes to run (space separated)"),
|
||||
|
@ -460,7 +460,7 @@ cgoptions!(
|
|||
"prefer dynamic linking to static linking"),
|
||||
no_integrated_as: bool = (false, parse_bool,
|
||||
"use an external assembler rather than LLVM's integrated one"),
|
||||
relocation_model: ~str = (~"pic", parse_string,
|
||||
relocation_model: ~str = ("pic".to_owned(), parse_string,
|
||||
"choose the relocation model to use (llc -relocation-model for details)"),
|
||||
)
|
||||
|
||||
|
@ -524,12 +524,12 @@ pub fn collect_crate_types(session: &Session,
|
|||
session.add_lint(lint::UnknownCrateType,
|
||||
ast::CRATE_NODE_ID,
|
||||
a.span,
|
||||
~"invalid `crate_type` value");
|
||||
"invalid `crate_type` value".to_owned());
|
||||
None
|
||||
}
|
||||
_ => {
|
||||
session.add_lint(lint::UnknownCrateType, ast::CRATE_NODE_ID,
|
||||
a.span, ~"`crate_type` requires a value");
|
||||
a.span, "`crate_type` requires a value".to_owned());
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
@ -339,7 +339,7 @@ pub fn check_crate(sess: &Session, krate: &ast::Crate) {
|
|||
sess.add_lint(lint::UnknownFeatures,
|
||||
ast::CRATE_NODE_ID,
|
||||
mi.span,
|
||||
~"unknown feature");
|
||||
"unknown feature".to_owned());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -171,7 +171,7 @@ fn generate_test_harness(sess: &Session, krate: ast::Crate)
|
|||
cx.ext_cx.bt_push(ExpnInfo {
|
||||
call_site: DUMMY_SP,
|
||||
callee: NameAndSpan {
|
||||
name: ~"test",
|
||||
name: "test".to_owned(),
|
||||
format: MacroAttribute,
|
||||
span: None
|
||||
}
|
||||
|
|
|
@ -243,24 +243,24 @@ pub fn run_compiler(args: &[~str]) {
|
|||
|
||||
let lint_flags = matches.opt_strs("W").move_iter().collect::<Vec<_>>().append(
|
||||
matches.opt_strs("warn").as_slice());
|
||||
if lint_flags.iter().any(|x| x == &~"help") {
|
||||
if lint_flags.iter().any(|x| x == &"help".to_owned()) {
|
||||
describe_warnings();
|
||||
return;
|
||||
}
|
||||
|
||||
let r = matches.opt_strs("Z");
|
||||
if r.iter().any(|x| x == &~"help") {
|
||||
if r.iter().any(|x| x == &"help".to_owned()) {
|
||||
describe_debug_flags();
|
||||
return;
|
||||
}
|
||||
|
||||
let cg_flags = matches.opt_strs("C");
|
||||
if cg_flags.iter().any(|x| x == &~"help") {
|
||||
if cg_flags.iter().any(|x| x == &"help".to_owned()) {
|
||||
describe_codegen_flags();
|
||||
return;
|
||||
}
|
||||
|
||||
if cg_flags.contains(&~"passes=list") {
|
||||
if cg_flags.contains(&"passes=list".to_owned()) {
|
||||
unsafe { lib::llvm::llvm::LLVMRustPrintPasses(); }
|
||||
return;
|
||||
}
|
||||
|
@ -406,9 +406,9 @@ pub fn monitor(f: proc():Send) {
|
|||
}
|
||||
|
||||
let xs = [
|
||||
~"the compiler hit an unexpected failure path. this is a bug.",
|
||||
"the compiler hit an unexpected failure path. this is a bug.".to_owned(),
|
||||
"we would appreciate a bug report: " + BUG_REPORT_URL,
|
||||
~"run with `RUST_BACKTRACE=1` for a backtrace",
|
||||
"run with `RUST_BACKTRACE=1` for a backtrace".to_owned(),
|
||||
];
|
||||
for note in xs.iter() {
|
||||
emitter.emit(None, *note, diagnostic::Note)
|
||||
|
|
|
@ -241,21 +241,21 @@ fn find_libdir(sysroot: &Path) -> ~str {
|
|||
}
|
||||
|
||||
#[cfg(target_word_size = "64")]
|
||||
fn primary_libdir_name() -> ~str { ~"lib64" }
|
||||
fn primary_libdir_name() -> ~str { "lib64".to_owned() }
|
||||
|
||||
#[cfg(target_word_size = "32")]
|
||||
fn primary_libdir_name() -> ~str { ~"lib32" }
|
||||
fn primary_libdir_name() -> ~str { "lib32".to_owned() }
|
||||
|
||||
fn secondary_libdir_name() -> ~str { ~"lib" }
|
||||
fn secondary_libdir_name() -> ~str { "lib".to_owned() }
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn find_libdir(_sysroot: &Path) -> ~str {
|
||||
~"bin"
|
||||
"bin".to_owned()
|
||||
}
|
||||
|
||||
// The name of rustc's own place to organize libraries.
|
||||
// Used to be "rustc", now the default is "rustlib"
|
||||
pub fn rustlibdir() -> ~str {
|
||||
~"rustlib"
|
||||
"rustlib".to_owned()
|
||||
}
|
||||
|
|
|
@ -240,7 +240,7 @@ impl<'a> CheckLoanCtxt<'a> {
|
|||
if restr.loan_path != loan2.loan_path { continue; }
|
||||
|
||||
let old_pronoun = if new_loan.loan_path == old_loan.loan_path {
|
||||
~"it"
|
||||
"it".to_owned()
|
||||
} else {
|
||||
format!("`{}`",
|
||||
self.bccx.loan_path_to_str(old_loan.loan_path))
|
||||
|
|
|
@ -112,7 +112,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr, is_const: bool) {
|
|||
ExprCast(_, _) => {
|
||||
let ety = ty::expr_ty(v.tcx, e);
|
||||
if !ty::type_is_numeric(ety) && !ty::type_is_unsafe_ptr(ety) {
|
||||
v.tcx.sess.span_err(e.span, ~"can not cast to `" +
|
||||
v.tcx.sess.span_err(e.span, "can not cast to `".to_owned() +
|
||||
ppaux::ty_to_str(v.tcx, ety) +
|
||||
"` in a constant expression");
|
||||
}
|
||||
|
|
|
@ -172,8 +172,8 @@ fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, pats: Vec<@Pat> ) {
|
|||
match ty::get(ty).sty {
|
||||
ty::ty_bool => {
|
||||
match *ctor {
|
||||
val(const_bool(true)) => Some(~"true"),
|
||||
val(const_bool(false)) => Some(~"false"),
|
||||
val(const_bool(true)) => Some("true".to_owned()),
|
||||
val(const_bool(false)) => Some("false".to_owned()),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
@ -201,9 +201,9 @@ fn check_exhaustive(cx: &MatchCheckCtxt, sp: Span, pats: Vec<@Pat> ) {
|
|||
}
|
||||
}
|
||||
};
|
||||
let msg = ~"non-exhaustive patterns" + match ext {
|
||||
let msg = "non-exhaustive patterns".to_owned() + match ext {
|
||||
Some(ref s) => format!(": {} not covered", *s),
|
||||
None => ~""
|
||||
None => "".to_owned()
|
||||
};
|
||||
cx.tcx.sess.span_err(sp, msg);
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ impl<'a> Visitor<bool> for CheckStaticVisitor<'a> {
|
|||
ty::ty_enum(did, _) => {
|
||||
if ty::has_dtor(self.tcx, did) {
|
||||
self.report_error(e.span,
|
||||
Some(~"static items are not allowed to have destructors"));
|
||||
Some("static items are not allowed to have destructors".to_owned()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -321,8 +321,8 @@ pub fn eval_const_expr_partial<T: ty::ExprTyProvider>(tcx: &T, e: &Expr)
|
|||
Ok(const_float(f)) => Ok(const_float(-f)),
|
||||
Ok(const_int(i)) => Ok(const_int(-i)),
|
||||
Ok(const_uint(i)) => Ok(const_uint(-i)),
|
||||
Ok(const_str(_)) => Err(~"negate on string"),
|
||||
Ok(const_bool(_)) => Err(~"negate on boolean"),
|
||||
Ok(const_str(_)) => Err("negate on string".to_owned()),
|
||||
Ok(const_bool(_)) => Err("negate on boolean".to_owned()),
|
||||
ref err => ((*err).clone())
|
||||
}
|
||||
}
|
||||
|
@ -331,7 +331,7 @@ pub fn eval_const_expr_partial<T: ty::ExprTyProvider>(tcx: &T, e: &Expr)
|
|||
Ok(const_int(i)) => Ok(const_int(!i)),
|
||||
Ok(const_uint(i)) => Ok(const_uint(!i)),
|
||||
Ok(const_bool(b)) => Ok(const_bool(!b)),
|
||||
_ => Err(~"not on float or string")
|
||||
_ => Err("not on float or string".to_owned())
|
||||
}
|
||||
}
|
||||
ExprBinary(op, a, b) => {
|
||||
|
@ -350,7 +350,7 @@ pub fn eval_const_expr_partial<T: ty::ExprTyProvider>(tcx: &T, e: &Expr)
|
|||
BiNe => fromb(a != b),
|
||||
BiGe => fromb(a >= b),
|
||||
BiGt => fromb(a > b),
|
||||
_ => Err(~"can't do this op on floats")
|
||||
_ => Err("can't do this op on floats".to_owned())
|
||||
}
|
||||
}
|
||||
(Ok(const_int(a)), Ok(const_int(b))) => {
|
||||
|
@ -358,9 +358,9 @@ pub fn eval_const_expr_partial<T: ty::ExprTyProvider>(tcx: &T, e: &Expr)
|
|||
BiAdd => Ok(const_int(a + b)),
|
||||
BiSub => Ok(const_int(a - b)),
|
||||
BiMul => Ok(const_int(a * b)),
|
||||
BiDiv if b == 0 => Err(~"attempted to divide by zero"),
|
||||
BiDiv if b == 0 => Err("attempted to divide by zero".to_owned()),
|
||||
BiDiv => Ok(const_int(a / b)),
|
||||
BiRem if b == 0 => Err(~"attempted remainder with a divisor of zero"),
|
||||
BiRem if b == 0 => Err("attempted remainder with a divisor of zero".to_owned()),
|
||||
BiRem => Ok(const_int(a % b)),
|
||||
BiAnd | BiBitAnd => Ok(const_int(a & b)),
|
||||
BiOr | BiBitOr => Ok(const_int(a | b)),
|
||||
|
@ -380,9 +380,9 @@ pub fn eval_const_expr_partial<T: ty::ExprTyProvider>(tcx: &T, e: &Expr)
|
|||
BiAdd => Ok(const_uint(a + b)),
|
||||
BiSub => Ok(const_uint(a - b)),
|
||||
BiMul => Ok(const_uint(a * b)),
|
||||
BiDiv if b == 0 => Err(~"attempted to divide by zero"),
|
||||
BiDiv if b == 0 => Err("attempted to divide by zero".to_owned()),
|
||||
BiDiv => Ok(const_uint(a / b)),
|
||||
BiRem if b == 0 => Err(~"attempted remainder with a divisor of zero"),
|
||||
BiRem if b == 0 => Err("attempted remainder with a divisor of zero".to_owned()),
|
||||
BiRem => Ok(const_uint(a % b)),
|
||||
BiAnd | BiBitAnd => Ok(const_uint(a & b)),
|
||||
BiOr | BiBitOr => Ok(const_uint(a | b)),
|
||||
|
@ -402,14 +402,14 @@ pub fn eval_const_expr_partial<T: ty::ExprTyProvider>(tcx: &T, e: &Expr)
|
|||
match op {
|
||||
BiShl => Ok(const_int(a << b)),
|
||||
BiShr => Ok(const_int(a >> b)),
|
||||
_ => Err(~"can't do this op on an int and uint")
|
||||
_ => Err("can't do this op on an int and uint".to_owned())
|
||||
}
|
||||
}
|
||||
(Ok(const_uint(a)), Ok(const_int(b))) => {
|
||||
match op {
|
||||
BiShl => Ok(const_uint(a << b)),
|
||||
BiShr => Ok(const_uint(a >> b)),
|
||||
_ => Err(~"can't do this op on a uint and int")
|
||||
_ => Err("can't do this op on a uint and int".to_owned())
|
||||
}
|
||||
}
|
||||
(Ok(const_bool(a)), Ok(const_bool(b))) => {
|
||||
|
@ -421,10 +421,10 @@ pub fn eval_const_expr_partial<T: ty::ExprTyProvider>(tcx: &T, e: &Expr)
|
|||
BiBitOr => a | b,
|
||||
BiEq => a == b,
|
||||
BiNe => a != b,
|
||||
_ => return Err(~"can't do this op on bools")
|
||||
_ => return Err("can't do this op on bools".to_owned())
|
||||
}))
|
||||
}
|
||||
_ => Err(~"bad operands for binary")
|
||||
_ => Err("bad operands for binary".to_owned())
|
||||
}
|
||||
}
|
||||
ExprCast(base, target_ty) => {
|
||||
|
@ -448,7 +448,7 @@ pub fn eval_const_expr_partial<T: ty::ExprTyProvider>(tcx: &T, e: &Expr)
|
|||
const_uint(u) => Ok(const_float(u as f64)),
|
||||
const_int(i) => Ok(const_float(i as f64)),
|
||||
const_float(f) => Ok(const_float(f)),
|
||||
_ => Err(~"can't cast float to str"),
|
||||
_ => Err("can't cast float to str".to_owned()),
|
||||
}
|
||||
}
|
||||
ty::ty_uint(_) => {
|
||||
|
@ -456,7 +456,7 @@ pub fn eval_const_expr_partial<T: ty::ExprTyProvider>(tcx: &T, e: &Expr)
|
|||
const_uint(u) => Ok(const_uint(u)),
|
||||
const_int(i) => Ok(const_uint(i as u64)),
|
||||
const_float(f) => Ok(const_uint(f as u64)),
|
||||
_ => Err(~"can't cast str to uint"),
|
||||
_ => Err("can't cast str to uint".to_owned()),
|
||||
}
|
||||
}
|
||||
ty::ty_int(_) | ty::ty_bool => {
|
||||
|
@ -464,10 +464,10 @@ pub fn eval_const_expr_partial<T: ty::ExprTyProvider>(tcx: &T, e: &Expr)
|
|||
const_uint(u) => Ok(const_int(u as i64)),
|
||||
const_int(i) => Ok(const_int(i)),
|
||||
const_float(f) => Ok(const_int(f as i64)),
|
||||
_ => Err(~"can't cast str to int"),
|
||||
_ => Err("can't cast str to int".to_owned()),
|
||||
}
|
||||
}
|
||||
_ => Err(~"can't cast this type")
|
||||
_ => Err("can't cast this type".to_owned())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -475,14 +475,14 @@ pub fn eval_const_expr_partial<T: ty::ExprTyProvider>(tcx: &T, e: &Expr)
|
|||
ExprPath(_) => {
|
||||
match lookup_const(tcx.ty_ctxt(), e) {
|
||||
Some(actual_e) => eval_const_expr_partial(tcx.ty_ctxt(), actual_e),
|
||||
None => Err(~"non-constant path in constant expr")
|
||||
None => Err("non-constant path in constant expr".to_owned())
|
||||
}
|
||||
}
|
||||
ExprLit(lit) => Ok(lit_to_const(lit)),
|
||||
// If we have a vstore, just keep going; it has to be a string
|
||||
ExprVstore(e, _) => eval_const_expr_partial(tcx, e),
|
||||
ExprParen(e) => eval_const_expr_partial(tcx, e),
|
||||
_ => Err(~"unsupported constant expr")
|
||||
_ => Err("unsupported constant expr".to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -103,14 +103,14 @@ impl<'a, O:DataFlowOperator> pprust::PpAnn for DataFlowContext<'a, O> {
|
|||
let gens_str = if gens.iter().any(|&u| u != 0) {
|
||||
format!(" gen: {}", bits_to_str(gens))
|
||||
} else {
|
||||
~""
|
||||
"".to_owned()
|
||||
};
|
||||
|
||||
let kills = self.kills.slice(start, end);
|
||||
let kills_str = if kills.iter().any(|&u| u != 0) {
|
||||
format!(" kill: {}", bits_to_str(kills))
|
||||
} else {
|
||||
~""
|
||||
"".to_owned()
|
||||
};
|
||||
|
||||
try!(ps.synth_comment(format!("id {}: {}{}{}", id, entry_str,
|
||||
|
|
|
@ -157,7 +157,7 @@ fn live_node_kind_to_str(lnk: LiveNodeKind, cx: &ty::ctxt) -> ~str {
|
|||
FreeVarNode(s) => format!("Free var node [{}]", cm.span_to_str(s)),
|
||||
ExprNode(s) => format!("Expr node [{}]", cm.span_to_str(s)),
|
||||
VarDefNode(s) => format!("Var def node [{}]", cm.span_to_str(s)),
|
||||
ExitNode => ~"Exit node"
|
||||
ExitNode => "Exit node".to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -328,7 +328,7 @@ impl<'a> IrMaps<'a> {
|
|||
&Local(LocalInfo { ident: nm, .. }) | &Arg(_, nm) => {
|
||||
token::get_ident(nm).get().to_str()
|
||||
},
|
||||
&ImplicitRet => ~"<implicit-ret>"
|
||||
&ImplicitRet => "<implicit-ret>".to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1089,19 +1089,19 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
|
|||
pub fn cmt_to_str(&self, cmt: cmt) -> ~str {
|
||||
match cmt.cat {
|
||||
cat_static_item => {
|
||||
~"static item"
|
||||
"static item".to_owned()
|
||||
}
|
||||
cat_copied_upvar(_) => {
|
||||
~"captured outer variable in a proc"
|
||||
"captured outer variable in a proc".to_owned()
|
||||
}
|
||||
cat_rvalue(..) => {
|
||||
~"non-lvalue"
|
||||
"non-lvalue".to_owned()
|
||||
}
|
||||
cat_local(_) => {
|
||||
~"local variable"
|
||||
"local variable".to_owned()
|
||||
}
|
||||
cat_arg(..) => {
|
||||
~"argument"
|
||||
"argument".to_owned()
|
||||
}
|
||||
cat_deref(base, _, pk) => {
|
||||
match base.cat {
|
||||
|
@ -1114,22 +1114,22 @@ impl<TYPER:Typer> MemCategorizationContext<TYPER> {
|
|||
}
|
||||
}
|
||||
cat_interior(_, InteriorField(NamedField(_))) => {
|
||||
~"field"
|
||||
"field".to_owned()
|
||||
}
|
||||
cat_interior(_, InteriorField(PositionalField(_))) => {
|
||||
~"anonymous field"
|
||||
"anonymous field".to_owned()
|
||||
}
|
||||
cat_interior(_, InteriorElement(VecElement)) => {
|
||||
~"vec content"
|
||||
"vec content".to_owned()
|
||||
}
|
||||
cat_interior(_, InteriorElement(StrElement)) => {
|
||||
~"str content"
|
||||
"str content".to_owned()
|
||||
}
|
||||
cat_interior(_, InteriorElement(OtherElement)) => {
|
||||
~"indexed content"
|
||||
"indexed content".to_owned()
|
||||
}
|
||||
cat_upvar(..) => {
|
||||
~"captured outer variable"
|
||||
"captured outer variable".to_owned()
|
||||
}
|
||||
cat_discr(cmt, _) => {
|
||||
self.cmt_to_str(cmt)
|
||||
|
@ -1300,7 +1300,7 @@ impl Repr for InteriorKind {
|
|||
token::get_name(fld).get().to_str()
|
||||
}
|
||||
InteriorField(PositionalField(i)) => format!("\\#{:?}", i),
|
||||
InteriorElement(_) => ~"[]",
|
||||
InteriorElement(_) => "[]".to_owned(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1340,7 +1340,7 @@ impl<'a> Visitor<()> for VisiblePrivateTypesVisitor<'a> {
|
|||
if self.path_is_private_type(path_id) {
|
||||
self.tcx.sess.add_lint(lint::VisiblePrivateTypes,
|
||||
path_id, p.span,
|
||||
~"private type in exported type signature");
|
||||
"private type in exported type signature".to_owned());
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
|
|
@ -2126,7 +2126,7 @@ impl<'a> Resolver<'a> {
|
|||
SingleImport(_, source) => {
|
||||
token::get_ident(source).get().to_str()
|
||||
}
|
||||
GlobImport => ~"*"
|
||||
GlobImport => "*".to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4617,7 +4617,7 @@ impl<'a> Resolver<'a> {
|
|||
self.session.add_lint(UnnecessaryQualification,
|
||||
id,
|
||||
path.span,
|
||||
~"unnecessary qualification");
|
||||
"unnecessary qualification".to_owned());
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
|
@ -5300,7 +5300,8 @@ impl<'a> Resolver<'a> {
|
|||
ViewPathGlob(_, id) => {
|
||||
if !self.used_imports.contains(&(id, TypeNS)) &&
|
||||
!self.used_imports.contains(&(id, ValueNS)) {
|
||||
self.session.add_lint(UnusedImports, id, p.span, ~"unused import");
|
||||
self.session.add_lint(UnusedImports, id, p.span,
|
||||
"unused import".to_owned());
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -5321,7 +5322,7 @@ impl<'a> Resolver<'a> {
|
|||
|
||||
if !self.used_imports.contains(&(id, TypeNS)) &&
|
||||
!self.used_imports.contains(&(id, ValueNS)) {
|
||||
self.session.add_lint(UnusedImports, id, span, ~"unused import");
|
||||
self.session.add_lint(UnusedImports, id, span, "unused import".to_owned());
|
||||
}
|
||||
|
||||
let (v_priv, t_priv) = match self.last_private.find(&id) {
|
||||
|
@ -5386,7 +5387,7 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
|
||||
if idents.len() == 0 {
|
||||
return ~"???";
|
||||
return "???".to_owned();
|
||||
}
|
||||
return self.idents_to_str(idents.move_iter()
|
||||
.rev()
|
||||
|
@ -5409,18 +5410,18 @@ impl<'a> Resolver<'a> {
|
|||
for (&name, import_resolution) in import_resolutions.iter() {
|
||||
let value_repr;
|
||||
match import_resolution.target_for_namespace(ValueNS) {
|
||||
None => { value_repr = ~""; }
|
||||
None => { value_repr = "".to_owned(); }
|
||||
Some(_) => {
|
||||
value_repr = ~" value:?";
|
||||
value_repr = " value:?".to_owned();
|
||||
// FIXME #4954
|
||||
}
|
||||
}
|
||||
|
||||
let type_repr;
|
||||
match import_resolution.target_for_namespace(TypeNS) {
|
||||
None => { type_repr = ~""; }
|
||||
None => { type_repr = "".to_owned(); }
|
||||
Some(_) => {
|
||||
type_repr = ~" type:?";
|
||||
type_repr = " type:?".to_owned();
|
||||
// FIXME #4954
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ impl<'a> TypeFolder for SubstFolder<'a> {
|
|||
let root_msg = match self.root_ty {
|
||||
Some(root) => format!(" in the substitution of `{}`",
|
||||
root.repr(self.tcx)),
|
||||
None => ~""
|
||||
None => "".to_owned()
|
||||
};
|
||||
let m = format!("can't use type parameters from outer \
|
||||
function{}; try using a local type \
|
||||
|
@ -112,7 +112,7 @@ impl<'a> TypeFolder for SubstFolder<'a> {
|
|||
let root_msg = match self.root_ty {
|
||||
Some(root) => format!(" in the substitution of `{}`",
|
||||
root.repr(self.tcx)),
|
||||
None => ~""
|
||||
None => "".to_owned()
|
||||
};
|
||||
let m = format!("missing `Self` type param{}", root_msg);
|
||||
match self.span {
|
||||
|
|
|
@ -137,11 +137,11 @@ pub fn trans_inline_asm<'a>(bcx: &'a Block<'a>, ia: &ast::InlineAsm)
|
|||
#[cfg(target_arch = "arm")]
|
||||
#[cfg(target_arch = "mips")]
|
||||
fn getClobbers() -> ~str {
|
||||
~""
|
||||
"".to_owned()
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "x86")]
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
fn getClobbers() -> ~str {
|
||||
~"~{dirflag},~{fpsr},~{flags}"
|
||||
"~{dirflag},~{fpsr},~{flags}".to_owned()
|
||||
}
|
||||
|
|
|
@ -468,7 +468,7 @@ pub fn set_no_split_stack(f: ValueRef) {
|
|||
// silently mangles such symbols, breaking our linkage model.
|
||||
pub fn note_unique_llvm_symbol(ccx: &CrateContext, sym: ~str) {
|
||||
if ccx.all_llvm_symbols.borrow().contains(&sym) {
|
||||
ccx.sess().bug(~"duplicate LLVM symbol: " + sym);
|
||||
ccx.sess().bug("duplicate LLVM symbol: ".to_owned() + sym);
|
||||
}
|
||||
ccx.all_llvm_symbols.borrow_mut().insert(sym);
|
||||
}
|
||||
|
@ -696,7 +696,7 @@ pub fn iter_structural_ty<'r,
|
|||
|
||||
for variant in (*variants).iter() {
|
||||
let variant_cx =
|
||||
fcx.new_temp_block(~"enum-iter-variant-" +
|
||||
fcx.new_temp_block("enum-iter-variant-".to_owned() +
|
||||
variant.disr_val.to_str());
|
||||
match adt::trans_case(cx, repr, variant.disr_val) {
|
||||
_match::single_result(r) => {
|
||||
|
@ -795,7 +795,7 @@ pub fn fail_if_zero<'a>(
|
|||
ICmp(cx, lib::llvm::IntEQ, rhs, zero)
|
||||
}
|
||||
_ => {
|
||||
cx.sess().bug(~"fail-if-zero on unexpected type: " +
|
||||
cx.sess().bug("fail-if-zero on unexpected type: ".to_owned() +
|
||||
ty_to_str(cx.tcx(), rhs_t));
|
||||
}
|
||||
};
|
||||
|
@ -1108,7 +1108,7 @@ pub fn new_fn_ctxt<'a>(ccx: &'a CrateContext,
|
|||
for p in param_substs.iter() { p.validate(); }
|
||||
|
||||
debug!("new_fn_ctxt(path={}, id={}, param_substs={})",
|
||||
if id == -1 { ~"" } else { ccx.tcx.map.path_to_str(id) },
|
||||
if id == -1 { "".to_owned() } else { ccx.tcx.map.path_to_str(id) },
|
||||
id, param_substs.repr(ccx.tcx()));
|
||||
|
||||
let substd_output_type = match param_substs {
|
||||
|
@ -2188,10 +2188,12 @@ pub fn trans_crate(krate: ast::Crate,
|
|||
// symbol. This symbol is required for use by the libmorestack library that
|
||||
// we link in, so we must ensure that this symbol is not internalized (if
|
||||
// defined in the crate).
|
||||
reachable.push(~"main");
|
||||
reachable.push(~"rust_stack_exhausted");
|
||||
reachable.push(~"rust_eh_personality"); // referenced from .eh_frame section on some platforms
|
||||
reachable.push(~"rust_eh_personality_catch"); // referenced from rt/rust_try.ll
|
||||
reachable.push("main".to_owned());
|
||||
reachable.push("rust_stack_exhausted".to_owned());
|
||||
|
||||
// referenced from .eh_frame section on some platforms
|
||||
reachable.push("rust_eh_personality".to_owned());
|
||||
reachable.push("rust_eh_personality_catch".to_owned()); // referenced from rt/rust_try.ll
|
||||
|
||||
let metadata_module = ccx.metadata_llmod;
|
||||
|
||||
|
|
|
@ -117,9 +117,9 @@ pub struct EnvValue {
|
|||
impl EnvAction {
|
||||
pub fn to_str(&self) -> ~str {
|
||||
match *self {
|
||||
EnvCopy => ~"EnvCopy",
|
||||
EnvMove => ~"EnvMove",
|
||||
EnvRef => ~"EnvRef"
|
||||
EnvCopy => "EnvCopy".to_owned(),
|
||||
EnvMove => "EnvMove".to_owned(),
|
||||
EnvRef => "EnvRef".to_owned()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1143,27 +1143,27 @@ fn basic_type_metadata(cx: &CrateContext, t: ty::t) -> DIType {
|
|||
debug!("basic_type_metadata: {:?}", ty::get(t));
|
||||
|
||||
let (name, encoding) = match ty::get(t).sty {
|
||||
ty::ty_nil => (~"()", DW_ATE_unsigned),
|
||||
ty::ty_bot => (~"!", DW_ATE_unsigned),
|
||||
ty::ty_bool => (~"bool", DW_ATE_boolean),
|
||||
ty::ty_char => (~"char", DW_ATE_unsigned_char),
|
||||
ty::ty_nil => ("()".to_owned(), DW_ATE_unsigned),
|
||||
ty::ty_bot => ("!".to_owned(), DW_ATE_unsigned),
|
||||
ty::ty_bool => ("bool".to_owned(), DW_ATE_boolean),
|
||||
ty::ty_char => ("char".to_owned(), DW_ATE_unsigned_char),
|
||||
ty::ty_int(int_ty) => match int_ty {
|
||||
ast::TyI => (~"int", DW_ATE_signed),
|
||||
ast::TyI8 => (~"i8", DW_ATE_signed),
|
||||
ast::TyI16 => (~"i16", DW_ATE_signed),
|
||||
ast::TyI32 => (~"i32", DW_ATE_signed),
|
||||
ast::TyI64 => (~"i64", DW_ATE_signed)
|
||||
ast::TyI => ("int".to_owned(), DW_ATE_signed),
|
||||
ast::TyI8 => ("i8".to_owned(), DW_ATE_signed),
|
||||
ast::TyI16 => ("i16".to_owned(), DW_ATE_signed),
|
||||
ast::TyI32 => ("i32".to_owned(), DW_ATE_signed),
|
||||
ast::TyI64 => ("i64".to_owned(), DW_ATE_signed)
|
||||
},
|
||||
ty::ty_uint(uint_ty) => match uint_ty {
|
||||
ast::TyU => (~"uint", DW_ATE_unsigned),
|
||||
ast::TyU8 => (~"u8", DW_ATE_unsigned),
|
||||
ast::TyU16 => (~"u16", DW_ATE_unsigned),
|
||||
ast::TyU32 => (~"u32", DW_ATE_unsigned),
|
||||
ast::TyU64 => (~"u64", DW_ATE_unsigned)
|
||||
ast::TyU => ("uint".to_owned(), DW_ATE_unsigned),
|
||||
ast::TyU8 => ("u8".to_owned(), DW_ATE_unsigned),
|
||||
ast::TyU16 => ("u16".to_owned(), DW_ATE_unsigned),
|
||||
ast::TyU32 => ("u32".to_owned(), DW_ATE_unsigned),
|
||||
ast::TyU64 => ("u64".to_owned(), DW_ATE_unsigned)
|
||||
},
|
||||
ty::ty_float(float_ty) => match float_ty {
|
||||
ast::TyF32 => (~"f32", DW_ATE_float),
|
||||
ast::TyF64 => (~"f64", DW_ATE_float)
|
||||
ast::TyF32 => ("f32".to_owned(), DW_ATE_float),
|
||||
ast::TyF64 => ("f64".to_owned(), DW_ATE_float)
|
||||
},
|
||||
_ => cx.sess().bug("debuginfo::basic_type_metadata - t is invalid type")
|
||||
};
|
||||
|
@ -1241,7 +1241,7 @@ impl StructMemberDescriptionFactory {
|
|||
-> Vec<MemberDescription> {
|
||||
self.fields.iter().map(|field| {
|
||||
let name = if field.ident.name == special_idents::unnamed_field.name {
|
||||
~""
|
||||
"".to_owned()
|
||||
} else {
|
||||
token::get_ident(field.ident).get().to_str()
|
||||
};
|
||||
|
@ -1344,7 +1344,7 @@ impl TupleMemberDescriptionFactory {
|
|||
-> Vec<MemberDescription> {
|
||||
self.component_types.iter().map(|&component_type| {
|
||||
MemberDescription {
|
||||
name: ~"",
|
||||
name: "".to_owned(),
|
||||
llvm_type: type_of::type_of(cx, component_type),
|
||||
type_metadata: type_metadata(cx, component_type, self.span),
|
||||
offset: ComputedMemberOffset,
|
||||
|
@ -1422,7 +1422,7 @@ impl GeneralMemberDescriptionFactory {
|
|||
self.file_metadata,
|
||||
codemap::DUMMY_SP);
|
||||
MemberDescription {
|
||||
name: ~"",
|
||||
name: "".to_owned(),
|
||||
llvm_type: variant_llvm_type,
|
||||
type_metadata: variant_type_metadata,
|
||||
offset: FixedMemberOffset { bytes: 0 },
|
||||
|
@ -1491,12 +1491,12 @@ fn describe_enum_variant(cx: &CrateContext,
|
|||
Some(ref names) => {
|
||||
names.iter().map(|ident| token::get_ident(*ident).get().to_str()).collect()
|
||||
}
|
||||
None => variant_info.args.iter().map(|_| ~"").collect()
|
||||
None => variant_info.args.iter().map(|_| "".to_owned()).collect()
|
||||
};
|
||||
|
||||
// If this is not a univariant enum, there is also the (unnamed) discriminant field
|
||||
if discriminant_type_metadata.is_some() {
|
||||
arg_names.insert(0, ~"");
|
||||
arg_names.insert(0, "".to_owned());
|
||||
}
|
||||
|
||||
// Build an array of (field name, field type) pairs to be captured in the factory closure.
|
||||
|
@ -1847,7 +1847,7 @@ fn boxed_type_metadata(cx: &CrateContext,
|
|||
-> DICompositeType {
|
||||
let box_type_name = match content_type_name {
|
||||
Some(content_type_name) => format!("Boxed<{}>", content_type_name),
|
||||
None => ~"BoxedType"
|
||||
None => "BoxedType".to_owned()
|
||||
};
|
||||
|
||||
let box_llvm_type = Type::at_box(cx, content_llvm_type);
|
||||
|
@ -1862,31 +1862,31 @@ fn boxed_type_metadata(cx: &CrateContext,
|
|||
|
||||
let member_descriptions = [
|
||||
MemberDescription {
|
||||
name: ~"refcnt",
|
||||
name: "refcnt".to_owned(),
|
||||
llvm_type: *member_llvm_types.get(0),
|
||||
type_metadata: type_metadata(cx, int_type, codemap::DUMMY_SP),
|
||||
offset: ComputedMemberOffset,
|
||||
},
|
||||
MemberDescription {
|
||||
name: ~"drop_glue",
|
||||
name: "drop_glue".to_owned(),
|
||||
llvm_type: *member_llvm_types.get(1),
|
||||
type_metadata: nil_pointer_type_metadata,
|
||||
offset: ComputedMemberOffset,
|
||||
},
|
||||
MemberDescription {
|
||||
name: ~"prev",
|
||||
name: "prev".to_owned(),
|
||||
llvm_type: *member_llvm_types.get(2),
|
||||
type_metadata: nil_pointer_type_metadata,
|
||||
offset: ComputedMemberOffset,
|
||||
},
|
||||
MemberDescription {
|
||||
name: ~"next",
|
||||
name: "next".to_owned(),
|
||||
llvm_type: *member_llvm_types.get(3),
|
||||
type_metadata: nil_pointer_type_metadata,
|
||||
offset: ComputedMemberOffset,
|
||||
},
|
||||
MemberDescription {
|
||||
name: ~"val",
|
||||
name: "val".to_owned(),
|
||||
llvm_type: *member_llvm_types.get(4),
|
||||
type_metadata: content_type_metadata,
|
||||
offset: ComputedMemberOffset,
|
||||
|
@ -1973,19 +1973,19 @@ fn vec_metadata(cx: &CrateContext,
|
|||
|
||||
let member_descriptions = [
|
||||
MemberDescription {
|
||||
name: ~"fill",
|
||||
name: "fill".to_owned(),
|
||||
llvm_type: *member_llvm_types.get(0),
|
||||
type_metadata: int_type_metadata,
|
||||
offset: ComputedMemberOffset,
|
||||
},
|
||||
MemberDescription {
|
||||
name: ~"alloc",
|
||||
name: "alloc".to_owned(),
|
||||
llvm_type: *member_llvm_types.get(1),
|
||||
type_metadata: int_type_metadata,
|
||||
offset: ComputedMemberOffset,
|
||||
},
|
||||
MemberDescription {
|
||||
name: ~"elements",
|
||||
name: "elements".to_owned(),
|
||||
llvm_type: *member_llvm_types.get(2),
|
||||
type_metadata: array_type_metadata,
|
||||
offset: ComputedMemberOffset,
|
||||
|
@ -2030,13 +2030,13 @@ fn vec_slice_metadata(cx: &CrateContext,
|
|||
|
||||
let member_descriptions = [
|
||||
MemberDescription {
|
||||
name: ~"data_ptr",
|
||||
name: "data_ptr".to_owned(),
|
||||
llvm_type: *member_llvm_types.get(0),
|
||||
type_metadata: type_metadata(cx, data_ptr_type, span),
|
||||
offset: ComputedMemberOffset,
|
||||
},
|
||||
MemberDescription {
|
||||
name: ~"length",
|
||||
name: "length".to_owned(),
|
||||
llvm_type: *member_llvm_types.get(1),
|
||||
type_metadata: type_metadata(cx, ty::mk_uint(), span),
|
||||
offset: ComputedMemberOffset,
|
||||
|
|
|
@ -90,7 +90,7 @@ impl Dest {
|
|||
pub fn to_str(&self, ccx: &CrateContext) -> ~str {
|
||||
match *self {
|
||||
SaveIn(v) => format!("SaveIn({})", ccx.tn.val_to_str(v)),
|
||||
Ignore => ~"Ignore"
|
||||
Ignore => "Ignore".to_owned()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -433,7 +433,7 @@ pub fn declare_tydesc(ccx: &CrateContext, t: ty::t) -> @tydesc_info {
|
|||
fn declare_generic_glue(ccx: &CrateContext, t: ty::t, llfnty: Type,
|
||||
name: &str) -> ValueRef {
|
||||
let _icx = push_ctxt("declare_generic_glue");
|
||||
let fn_nm = mangle_internal_name_by_type_and_seq(ccx, t, ~"glue_" + name);
|
||||
let fn_nm = mangle_internal_name_by_type_and_seq(ccx, t, "glue_".to_owned() + name);
|
||||
debug!("{} is for type {}", fn_nm, ppaux::ty_to_str(ccx.tcx(), t));
|
||||
let llfn = decl_cdecl_fn(ccx.llmod, fn_nm, llfnty, ty::mk_nil());
|
||||
note_unique_llvm_symbol(ccx, fn_nm);
|
||||
|
|
|
@ -87,7 +87,7 @@ impl<'a> Reflector<'a> {
|
|||
pub fn visit(&mut self, ty_name: &str, args: &[ValueRef]) {
|
||||
let fcx = self.bcx.fcx;
|
||||
let tcx = self.bcx.tcx();
|
||||
let mth_idx = ty::method_idx(token::str_to_ident(~"visit_" + ty_name),
|
||||
let mth_idx = ty::method_idx(token::str_to_ident("visit_".to_owned() + ty_name),
|
||||
self.visitor_methods.as_slice()).expect(
|
||||
format!("couldn't find visit method for {}", ty_name));
|
||||
let mth_ty =
|
||||
|
@ -128,10 +128,10 @@ impl<'a> Reflector<'a> {
|
|||
match vstore {
|
||||
ty::VstoreFixed(n) => {
|
||||
let extra = (vec!(self.c_uint(n))).append(self.c_size_and_align(t).as_slice());
|
||||
(~"fixed", extra)
|
||||
("fixed".to_owned(), extra)
|
||||
}
|
||||
ty::VstoreSlice(..) => (~"slice", Vec::new()),
|
||||
ty::VstoreUniq => (~"uniq", Vec::new()),
|
||||
ty::VstoreSlice(..) => ("slice".to_owned(), Vec::new()),
|
||||
ty::VstoreUniq => ("uniq".to_owned(), Vec::new()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,7 +166,7 @@ impl<'a> Reflector<'a> {
|
|||
// Should rename to str_*/vec_*.
|
||||
ty::ty_str(vst) => {
|
||||
let (name, extra) = self.vstore_name_and_extra(t, vst);
|
||||
self.visit(~"estr_" + name, extra.as_slice())
|
||||
self.visit("estr_".to_owned() + name, extra.as_slice())
|
||||
}
|
||||
ty::ty_vec(ty, vst) => {
|
||||
let (name, extra) = self.vstore_name_and_extra(t, vst);
|
||||
|
@ -177,7 +177,7 @@ impl<'a> Reflector<'a> {
|
|||
_ => ast::MutImmutable
|
||||
}
|
||||
}).as_slice());
|
||||
self.visit(~"evec_" + name, extra.as_slice())
|
||||
self.visit("evec_".to_owned() + name, extra.as_slice())
|
||||
}
|
||||
// Should remove mt from box and uniq.
|
||||
ty::ty_box(typ) => {
|
||||
|
|
|
@ -226,7 +226,7 @@ pub fn trans_uniq_vstore<'a>(bcx: &'a Block<'a>,
|
|||
content_expr: &ast::Expr)
|
||||
-> DatumBlock<'a, Expr> {
|
||||
/*!
|
||||
* ~[...] and ~"..." allocate boxes in the exchange heap and write
|
||||
* ~[...] and "...".to_owned() allocate boxes in the exchange heap and write
|
||||
* the array elements into them.
|
||||
*/
|
||||
|
||||
|
@ -234,7 +234,7 @@ pub fn trans_uniq_vstore<'a>(bcx: &'a Block<'a>,
|
|||
let fcx = bcx.fcx;
|
||||
let ccx = fcx.ccx;
|
||||
|
||||
// Handle ~"".
|
||||
// Handle "".to_owned().
|
||||
match content_expr.node {
|
||||
ast::ExprLit(lit) => {
|
||||
match lit.node {
|
||||
|
|
|
@ -3251,22 +3251,22 @@ pub fn ty_sort_str(cx: &ctxt, t: t) -> ~str {
|
|||
}
|
||||
|
||||
ty_enum(id, _) => format!("enum {}", item_path_str(cx, id)),
|
||||
ty_box(_) => ~"@-ptr",
|
||||
ty_uniq(_) => ~"~-ptr",
|
||||
ty_vec(_, _) => ~"vector",
|
||||
ty_ptr(_) => ~"*-ptr",
|
||||
ty_rptr(_, _) => ~"&-ptr",
|
||||
ty_bare_fn(_) => ~"extern fn",
|
||||
ty_closure(_) => ~"fn",
|
||||
ty_box(_) => "@-ptr".to_owned(),
|
||||
ty_uniq(_) => "~-ptr".to_owned(),
|
||||
ty_vec(_, _) => "vector".to_owned(),
|
||||
ty_ptr(_) => "*-ptr".to_owned(),
|
||||
ty_rptr(_, _) => "&-ptr".to_owned(),
|
||||
ty_bare_fn(_) => "extern fn".to_owned(),
|
||||
ty_closure(_) => "fn".to_owned(),
|
||||
ty_trait(ref inner) => format!("trait {}", item_path_str(cx, inner.def_id)),
|
||||
ty_struct(id, _) => format!("struct {}", item_path_str(cx, id)),
|
||||
ty_tup(_) => ~"tuple",
|
||||
ty_infer(TyVar(_)) => ~"inferred type",
|
||||
ty_infer(IntVar(_)) => ~"integral variable",
|
||||
ty_infer(FloatVar(_)) => ~"floating-point variable",
|
||||
ty_param(_) => ~"type parameter",
|
||||
ty_self(_) => ~"self",
|
||||
ty_err => ~"type error"
|
||||
ty_tup(_) => "tuple".to_owned(),
|
||||
ty_infer(TyVar(_)) => "inferred type".to_owned(),
|
||||
ty_infer(IntVar(_)) => "integral variable".to_owned(),
|
||||
ty_infer(FloatVar(_)) => "floating-point variable".to_owned(),
|
||||
ty_param(_) => "type parameter".to_owned(),
|
||||
ty_self(_) => "self".to_owned(),
|
||||
ty_err => "type error".to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3282,15 +3282,15 @@ pub fn type_err_to_str(cx: &ctxt, err: &type_err) -> ~str {
|
|||
|
||||
fn terr_vstore_kind_to_str(k: terr_vstore_kind) -> ~str {
|
||||
match k {
|
||||
terr_vec => ~"[]",
|
||||
terr_str => ~"str",
|
||||
terr_fn => ~"fn",
|
||||
terr_trait => ~"trait"
|
||||
terr_vec => "[]".to_owned(),
|
||||
terr_str => "str".to_owned(),
|
||||
terr_fn => "fn".to_owned(),
|
||||
terr_trait => "trait".to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
match *err {
|
||||
terr_mismatch => ~"types differ",
|
||||
terr_mismatch => "types differ".to_owned(),
|
||||
terr_fn_style_mismatch(values) => {
|
||||
format!("expected {} fn but found {} fn",
|
||||
values.expected.to_str(), values.found.to_str())
|
||||
|
@ -3308,11 +3308,11 @@ pub fn type_err_to_str(cx: &ctxt, err: &type_err) -> ~str {
|
|||
values.expected.to_str(),
|
||||
values.found.to_str())
|
||||
}
|
||||
terr_mutability => ~"values differ in mutability",
|
||||
terr_box_mutability => ~"boxed values differ in mutability",
|
||||
terr_vec_mutability => ~"vectors differ in mutability",
|
||||
terr_ptr_mutability => ~"pointers differ in mutability",
|
||||
terr_ref_mutability => ~"references differ in mutability",
|
||||
terr_mutability => "values differ in mutability".to_owned(),
|
||||
terr_box_mutability => "boxed values differ in mutability".to_owned(),
|
||||
terr_vec_mutability => "vectors differ in mutability".to_owned(),
|
||||
terr_ptr_mutability => "pointers differ in mutability".to_owned(),
|
||||
terr_ref_mutability => "references differ in mutability".to_owned(),
|
||||
terr_ty_param_size(values) => {
|
||||
format!("expected a type with {} type params \
|
||||
but found one with {} type params",
|
||||
|
@ -3329,7 +3329,7 @@ pub fn type_err_to_str(cx: &ctxt, err: &type_err) -> ~str {
|
|||
values.expected, values.found)
|
||||
}
|
||||
terr_record_mutability => {
|
||||
~"record elements differ in mutability"
|
||||
"record elements differ in mutability".to_owned()
|
||||
}
|
||||
terr_record_fields(values) => {
|
||||
format!("expected a record with field `{}` but found one with field \
|
||||
|
@ -3337,7 +3337,7 @@ pub fn type_err_to_str(cx: &ctxt, err: &type_err) -> ~str {
|
|||
token::get_ident(values.expected),
|
||||
token::get_ident(values.found))
|
||||
}
|
||||
terr_arg_count => ~"incorrect number of function parameters",
|
||||
terr_arg_count => "incorrect number of function parameters".to_owned(),
|
||||
terr_regions_does_not_outlive(..) => {
|
||||
format!("lifetime mismatch")
|
||||
}
|
||||
|
|
|
@ -166,10 +166,10 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: &ast::Pat, path: &ast::Path,
|
|||
// See [Note-Type-error-reporting] in middle/typeck/infer/mod.rs
|
||||
fcx.infcx().type_error_message_str_with_expected(pat.span,
|
||||
|expected, actual| {
|
||||
expected.map_or(~"", |e| {
|
||||
expected.map_or("".to_owned(), |e| {
|
||||
format!("mismatched types: expected `{}` but found {}",
|
||||
e, actual)})},
|
||||
Some(expected), ~"a structure pattern",
|
||||
Some(expected), "a structure pattern".to_owned(),
|
||||
None);
|
||||
fcx.write_error(pat.id);
|
||||
kind_name = "[error]";
|
||||
|
@ -217,10 +217,10 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: &ast::Pat, path: &ast::Path,
|
|||
// See [Note-Type-error-reporting] in middle/typeck/infer/mod.rs
|
||||
fcx.infcx().type_error_message_str_with_expected(pat.span,
|
||||
|expected, actual| {
|
||||
expected.map_or(~"", |e| {
|
||||
expected.map_or("".to_owned(), |e| {
|
||||
format!("mismatched types: expected `{}` but found {}",
|
||||
e, actual)})},
|
||||
Some(expected), ~"an enum or structure pattern",
|
||||
Some(expected), "an enum or structure pattern".to_owned(),
|
||||
None);
|
||||
fcx.write_error(pat.id);
|
||||
kind_name = "[error]";
|
||||
|
@ -446,7 +446,7 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
|
|||
debug!("pat_range ending type: {:?}", e_ty);
|
||||
if !require_same_types(
|
||||
tcx, Some(fcx.infcx()), false, pat.span, b_ty, e_ty,
|
||||
|| ~"mismatched types in range")
|
||||
|| "mismatched types in range".to_owned())
|
||||
{
|
||||
// no-op
|
||||
} else if !ty::type_is_numeric(b_ty) && !ty::type_is_char(b_ty) {
|
||||
|
@ -540,10 +540,10 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
|
|||
// See [Note-Type-error-reporting] in middle/typeck/infer/mod.rs
|
||||
fcx.infcx().type_error_message_str_with_expected(pat.span,
|
||||
|expected, actual| {
|
||||
expected.map_or(~"", |e| {
|
||||
expected.map_or("".to_owned(), |e| {
|
||||
format!("mismatched types: expected `{}` but found {}",
|
||||
e, actual)})},
|
||||
Some(expected), ~"a structure pattern",
|
||||
Some(expected), "a structure pattern".to_owned(),
|
||||
None);
|
||||
match tcx.def_map.borrow().find(&pat.id) {
|
||||
Some(&ast::DefStruct(supplied_def_id)) => {
|
||||
|
@ -597,9 +597,10 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
|
|||
};
|
||||
// See [Note-Type-error-reporting] in middle/typeck/infer/mod.rs
|
||||
fcx.infcx().type_error_message_str_with_expected(pat.span, |expected, actual| {
|
||||
expected.map_or(~"", |e| {
|
||||
format!("mismatched types: expected `{}` but found {}",
|
||||
e, actual)})}, Some(expected), ~"tuple", Some(&type_error));
|
||||
expected.map_or("".to_owned(), |e| {
|
||||
format!("mismatched types: expected `{}` but found {}",
|
||||
e, actual)})},
|
||||
Some(expected), "tuple".to_owned(), Some(&type_error));
|
||||
fcx.write_error(pat.id);
|
||||
}
|
||||
}
|
||||
|
@ -650,11 +651,11 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
|
|||
fcx.infcx().type_error_message_str_with_expected(
|
||||
pat.span,
|
||||
|expected, actual| {
|
||||
expected.map_or(~"", |e| {
|
||||
expected.map_or("".to_owned(), |e| {
|
||||
format!("mismatched types: expected `{}` but found {}",
|
||||
e, actual)})},
|
||||
Some(expected),
|
||||
~"a vector pattern",
|
||||
"a vector pattern".to_owned(),
|
||||
None);
|
||||
fcx.write_error(pat.id);
|
||||
return;
|
||||
|
@ -706,7 +707,7 @@ pub fn check_pointer_pat(pcx: &pat_ctxt,
|
|||
fcx.infcx().type_error_message_str_with_expected(
|
||||
span,
|
||||
|expected, actual| {
|
||||
expected.map_or(~"", |e| {
|
||||
expected.map_or("".to_owned(), |e| {
|
||||
format!("mismatched types: expected `{}` but found {}",
|
||||
e, actual)})},
|
||||
Some(expected),
|
||||
|
|
|
@ -2339,7 +2339,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
|
|||
let name = class_field.name;
|
||||
let (_, seen) = *class_field_map.get(&name);
|
||||
if !seen {
|
||||
missing_fields.push(~"`" + token::get_name(name).get() + "`");
|
||||
missing_fields.push("`".to_owned() + token::get_name(name).get() + "`");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3128,7 +3128,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
|
|||
ppaux::ty_to_str(tcx, fcx.expr_ty(expr)),
|
||||
match expected {
|
||||
Some(t) => ppaux::ty_to_str(tcx, t),
|
||||
_ => ~"empty"
|
||||
_ => "empty".to_owned()
|
||||
});
|
||||
|
||||
unifier();
|
||||
|
@ -3277,7 +3277,7 @@ pub fn check_block_with_expected(fcx: &FnCtxt,
|
|||
_ => false
|
||||
} {
|
||||
fcx.ccx.tcx.sess.add_lint(UnreachableCode, s_id, s.span,
|
||||
~"unreachable statement");
|
||||
"unreachable statement".to_owned());
|
||||
warned = true;
|
||||
}
|
||||
if ty::type_is_bot(s_ty) {
|
||||
|
@ -3299,7 +3299,7 @@ pub fn check_block_with_expected(fcx: &FnCtxt,
|
|||
Some(e) => {
|
||||
if any_bot && !warned {
|
||||
fcx.ccx.tcx.sess.add_lint(UnreachableCode, e.id, e.span,
|
||||
~"unreachable expression");
|
||||
"unreachable expression".to_owned());
|
||||
}
|
||||
check_expr_with_opt_hint(fcx, e, expected);
|
||||
let ety = fcx.expr_ty(e);
|
||||
|
@ -3779,7 +3779,7 @@ pub fn structurally_resolved_type(fcx: &FnCtxt, sp: Span, tp: ty::t) -> ty::t {
|
|||
Ok(t_s) if !ty::type_is_ty_var(t_s) => t_s,
|
||||
_ => {
|
||||
fcx.type_error_message(sp, |_actual| {
|
||||
~"the type of this value must be known in this context"
|
||||
"the type of this value must be known in this context".to_owned()
|
||||
}, tp, None);
|
||||
demand::suptype(fcx, sp, ty::mk_err(), tp);
|
||||
tp
|
||||
|
|
|
@ -1209,12 +1209,12 @@ impl<'a> ErrorReportingHelpers for InferCtxt<'a> {
|
|||
fn report_inference_failure(&self,
|
||||
var_origin: RegionVariableOrigin) {
|
||||
let var_description = match var_origin {
|
||||
infer::MiscVariable(_) => ~"",
|
||||
infer::PatternRegion(_) => ~" for pattern",
|
||||
infer::AddrOfRegion(_) => ~" for borrow expression",
|
||||
infer::AddrOfSlice(_) => ~" for slice expression",
|
||||
infer::Autoref(_) => ~" for autoref",
|
||||
infer::Coercion(_) => ~" for automatic coercion",
|
||||
infer::MiscVariable(_) => "".to_owned(),
|
||||
infer::PatternRegion(_) => " for pattern".to_owned(),
|
||||
infer::AddrOfRegion(_) => " for borrow expression".to_owned(),
|
||||
infer::AddrOfSlice(_) => " for slice expression".to_owned(),
|
||||
infer::Autoref(_) => " for autoref".to_owned(),
|
||||
infer::Coercion(_) => " for automatic coercion".to_owned(),
|
||||
infer::LateBoundRegion(_, br) => {
|
||||
format!(" for {}in function call",
|
||||
bound_region_to_str(self.tcx, "lifetime parameter ", true, br))
|
||||
|
|
|
@ -36,7 +36,7 @@ impl<'f> Glb<'f> {
|
|||
|
||||
impl<'f> Combine for Glb<'f> {
|
||||
fn infcx<'a>(&'a self) -> &'a InferCtxt<'a> { self.get_ref().infcx }
|
||||
fn tag(&self) -> ~str { ~"glb" }
|
||||
fn tag(&self) -> ~str { "glb".to_owned() }
|
||||
fn a_is_expected(&self) -> bool { self.get_ref().a_is_expected }
|
||||
fn trace(&self) -> TypeTrace { self.get_ref().trace }
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ impl<'f> Lub<'f> {
|
|||
|
||||
impl<'f> Combine for Lub<'f> {
|
||||
fn infcx<'a>(&'a self) -> &'a InferCtxt<'a> { self.get_ref().infcx }
|
||||
fn tag(&self) -> ~str { ~"lub" }
|
||||
fn tag(&self) -> ~str { "lub".to_owned() }
|
||||
fn a_is_expected(&self) -> bool { self.get_ref().a_is_expected }
|
||||
fn trace(&self) -> TypeTrace { self.get_ref().trace }
|
||||
|
||||
|
|
|
@ -248,10 +248,10 @@ pub enum fixup_err {
|
|||
|
||||
pub fn fixup_err_to_str(f: fixup_err) -> ~str {
|
||||
match f {
|
||||
unresolved_int_ty(_) => ~"unconstrained integral type",
|
||||
unresolved_ty(_) => ~"unconstrained type",
|
||||
cyclic_ty(_) => ~"cyclic type of infinite size",
|
||||
unresolved_region(_) => ~"unconstrained region",
|
||||
unresolved_int_ty(_) => "unconstrained integral type".to_owned(),
|
||||
unresolved_ty(_) => "unconstrained type".to_owned(),
|
||||
cyclic_ty(_) => "cyclic type of infinite size".to_owned(),
|
||||
unresolved_region(_) => "unconstrained region".to_owned(),
|
||||
region_var_bound_by_region_var(r1, r2) => {
|
||||
format!("region var {:?} bound by another region var {:?}; this is \
|
||||
a bug in rustc", r1, r2)
|
||||
|
@ -728,7 +728,7 @@ impl<'a> InferCtxt<'a> {
|
|||
err: Option<&ty::type_err>) {
|
||||
debug!("hi! expected_ty = {:?}, actual_ty = {}", expected_ty, actual_ty);
|
||||
|
||||
let error_str = err.map_or(~"", |t_err| {
|
||||
let error_str = err.map_or("".to_owned(), |t_err| {
|
||||
format!(" ({})", ty::type_err_to_str(self.tcx, t_err))
|
||||
});
|
||||
let resolved_expected = expected_ty.map(|e_ty| {
|
||||
|
|
|
@ -35,7 +35,7 @@ impl<'f> Sub<'f> {
|
|||
|
||||
impl<'f> Combine for Sub<'f> {
|
||||
fn infcx<'a>(&'a self) -> &'a InferCtxt<'a> { self.get_ref().infcx }
|
||||
fn tag(&self) -> ~str { ~"sub" }
|
||||
fn tag(&self) -> ~str { "sub".to_owned() }
|
||||
fn a_is_expected(&self) -> bool { self.get_ref().a_is_expected }
|
||||
fn trace(&self) -> TypeTrace { self.get_ref().trace }
|
||||
|
||||
|
|
|
@ -46,11 +46,11 @@ static EMPTY_SOURCE_STR: &str = "/* Hello, world! */";
|
|||
|
||||
fn setup_env(test_name: &str, source_string: &str) -> Env {
|
||||
let messages = @DVec();
|
||||
let matches = getopts(vec!(~"-Z", ~"verbose"), optgroups()).get();
|
||||
let matches = getopts(vec!("-Z".to_owned(), "verbose".to_owned()), optgroups()).get();
|
||||
let diag = diagnostic::collect(messages);
|
||||
let sessopts = build_session_options(~"rustc", &matches, diag);
|
||||
let sessopts = build_session_options("rustc".to_owned(), &matches, diag);
|
||||
let sess = build_session(sessopts, None, diag);
|
||||
let cfg = build_configuration(sess, ~"whatever", str_input(~""));
|
||||
let cfg = build_configuration(sess, "whatever".to_owned(), str_input("".to_owned()));
|
||||
let dm = HashMap();
|
||||
let amap = HashMap();
|
||||
let freevars = HashMap();
|
||||
|
|
|
@ -53,7 +53,7 @@ impl<V:InferStr> InferStr for Bound<V> {
|
|||
fn inf_str(&self, cx: &InferCtxt) -> ~str {
|
||||
match *self {
|
||||
Some(ref v) => v.inf_str(cx),
|
||||
None => ~"none"
|
||||
None => "none".to_owned()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,9 +118,9 @@ pub fn explain_region_and_span(cx: &ctxt, region: ty::Region)
|
|||
}
|
||||
}
|
||||
|
||||
ReStatic => { (~"the static lifetime", None) }
|
||||
ReStatic => { ("the static lifetime".to_owned(), None) }
|
||||
|
||||
ReEmpty => { (~"the empty lifetime", None) }
|
||||
ReEmpty => { ("the empty lifetime".to_owned(), None) }
|
||||
|
||||
// I believe these cases should not occur (except when debugging,
|
||||
// perhaps)
|
||||
|
@ -192,8 +192,8 @@ pub fn region_to_str(cx: &ctxt, prefix: &str, space: bool, region: Region) -> ~s
|
|||
|
||||
pub fn mutability_to_str(m: ast::Mutability) -> ~str {
|
||||
match m {
|
||||
ast::MutMutable => ~"mut ",
|
||||
ast::MutImmutable => ~"",
|
||||
ast::MutMutable => "mut ".to_owned(),
|
||||
ast::MutImmutable => "".to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -203,7 +203,7 @@ pub fn mt_to_str(cx: &ctxt, m: &mt) -> ~str {
|
|||
|
||||
pub fn trait_store_to_str(cx: &ctxt, s: ty::TraitStore) -> ~str {
|
||||
match s {
|
||||
ty::UniqTraitStore => ~"~",
|
||||
ty::UniqTraitStore => "~".to_owned(),
|
||||
ty::RegionTraitStore(r, m) => {
|
||||
format!("{}{}", region_ptr_to_str(cx, r), mutability_to_str(m))
|
||||
}
|
||||
|
@ -337,22 +337,22 @@ pub fn ty_to_str(cx: &ctxt, typ: t) -> ~str {
|
|||
|
||||
// pretty print the structural type representation:
|
||||
return match ty::get(typ).sty {
|
||||
ty_nil => ~"()",
|
||||
ty_bot => ~"!",
|
||||
ty_bool => ~"bool",
|
||||
ty_char => ~"char",
|
||||
ty_nil => "()".to_owned(),
|
||||
ty_bot => "!".to_owned(),
|
||||
ty_bool => "bool".to_owned(),
|
||||
ty_char => "char".to_owned(),
|
||||
ty_int(t) => ast_util::int_ty_to_str(t, None),
|
||||
ty_uint(t) => ast_util::uint_ty_to_str(t, None),
|
||||
ty_float(t) => ast_util::float_ty_to_str(t),
|
||||
ty_box(typ) => ~"@" + ty_to_str(cx, typ),
|
||||
ty_uniq(typ) => ~"~" + ty_to_str(cx, typ),
|
||||
ty_ptr(ref tm) => ~"*" + mt_to_str(cx, tm),
|
||||
ty_box(typ) => "@".to_owned() + ty_to_str(cx, typ),
|
||||
ty_uniq(typ) => "~".to_owned() + ty_to_str(cx, typ),
|
||||
ty_ptr(ref tm) => "*".to_owned() + mt_to_str(cx, tm),
|
||||
ty_rptr(r, ref tm) => {
|
||||
region_ptr_to_str(cx, r) + mt_to_str(cx, tm)
|
||||
}
|
||||
ty_tup(ref elems) => {
|
||||
let strs: Vec<~str> = elems.iter().map(|elem| ty_to_str(cx, *elem)).collect();
|
||||
~"(" + strs.connect(",") + ")"
|
||||
"(".to_owned() + strs.connect(",") + ")"
|
||||
}
|
||||
ty_closure(ref f) => {
|
||||
closure_to_str(cx, *f)
|
||||
|
@ -361,7 +361,7 @@ pub fn ty_to_str(cx: &ctxt, typ: t) -> ~str {
|
|||
bare_fn_to_str(cx, f.fn_style, f.abi, None, &f.sig)
|
||||
}
|
||||
ty_infer(infer_ty) => infer_ty.to_str(),
|
||||
ty_err => ~"[type error]",
|
||||
ty_err => "[type error]".to_owned(),
|
||||
ty_param(param_ty {idx: id, def_id: did}) => {
|
||||
let ident = match cx.ty_param_defs.borrow().find(&did.node) {
|
||||
Some(def) => token::get_ident(def.ident).get().to_str(),
|
||||
|
@ -375,7 +375,7 @@ pub fn ty_to_str(cx: &ctxt, typ: t) -> ~str {
|
|||
format!("{}:{:?}", ident, did)
|
||||
}
|
||||
}
|
||||
ty_self(..) => ~"Self",
|
||||
ty_self(..) => "Self".to_owned(),
|
||||
ty_enum(did, ref substs) | ty_struct(did, ref substs) => {
|
||||
let base = ty::item_path_str(cx, did);
|
||||
parameterized(cx,
|
||||
|
@ -408,7 +408,7 @@ pub fn ty_to_str(cx: &ctxt, typ: t) -> ~str {
|
|||
ty_str(vs) => {
|
||||
match vs {
|
||||
ty::VstoreFixed(n) => format!("str/{}", n),
|
||||
ty::VstoreUniq => ~"~str",
|
||||
ty::VstoreUniq => "~str".to_owned(),
|
||||
ty::VstoreSlice(r, ()) => format!("{}str", region_ptr_to_str(cx, r))
|
||||
}
|
||||
}
|
||||
|
@ -477,7 +477,7 @@ pub fn ty_to_short_str(cx: &ctxt, typ: t) -> ~str {
|
|||
impl<T:Repr> Repr for Option<T> {
|
||||
fn repr(&self, tcx: &ctxt) -> ~str {
|
||||
match self {
|
||||
&None => ~"None",
|
||||
&None => "None".to_owned(),
|
||||
&Some(ref t) => t.repr(tcx),
|
||||
}
|
||||
}
|
||||
|
@ -494,7 +494,7 @@ impl<T:Repr,U:Repr> Repr for Result<T,U> {
|
|||
|
||||
impl Repr for () {
|
||||
fn repr(&self, _tcx: &ctxt) -> ~str {
|
||||
~"()"
|
||||
"()".to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -568,7 +568,7 @@ impl Repr for ty::substs {
|
|||
impl Repr for ty::RegionSubsts {
|
||||
fn repr(&self, tcx: &ctxt) -> ~str {
|
||||
match *self {
|
||||
ty::ErasedRegions => ~"erased",
|
||||
ty::ErasedRegions => "erased".to_owned(),
|
||||
ty::NonerasedRegions(ref regions) => regions.repr(tcx)
|
||||
}
|
||||
}
|
||||
|
@ -579,11 +579,11 @@ impl Repr for ty::ParamBounds {
|
|||
let mut res = Vec::new();
|
||||
for b in self.builtin_bounds.iter() {
|
||||
res.push(match b {
|
||||
ty::BoundStatic => ~"'static",
|
||||
ty::BoundSend => ~"Send",
|
||||
ty::BoundSized => ~"Sized",
|
||||
ty::BoundCopy => ~"Pod",
|
||||
ty::BoundShare => ~"Share",
|
||||
ty::BoundStatic => "'static".to_owned(),
|
||||
ty::BoundSend => "Send".to_owned(),
|
||||
ty::BoundSized => "Sized".to_owned(),
|
||||
ty::BoundCopy => "Pod".to_owned(),
|
||||
ty::BoundShare => "Share".to_owned(),
|
||||
});
|
||||
}
|
||||
for t in self.trait_bounds.iter() {
|
||||
|
@ -852,7 +852,7 @@ impl Repr for ty::Vstore {
|
|||
fn repr(&self, tcx: &ctxt) -> ~str {
|
||||
match *self {
|
||||
ty::VstoreFixed(n) => format!("{}", n),
|
||||
ty::VstoreUniq => ~"~",
|
||||
ty::VstoreUniq => "~".to_owned(),
|
||||
ty::VstoreSlice(r, m) => {
|
||||
format!("{}{}", region_ptr_to_str(tcx, r), mutability_to_str(m))
|
||||
}
|
||||
|
@ -864,7 +864,7 @@ impl Repr for ty::Vstore<()> {
|
|||
fn repr(&self, tcx: &ctxt) -> ~str {
|
||||
match *self {
|
||||
ty::VstoreFixed(n) => format!("{}", n),
|
||||
ty::VstoreUniq => ~"~",
|
||||
ty::VstoreUniq => "~".to_owned(),
|
||||
ty::VstoreSlice(r, ()) => region_ptr_to_str(tcx, r)
|
||||
}
|
||||
}
|
||||
|
@ -879,11 +879,11 @@ impl Repr for ty::BuiltinBound {
|
|||
impl UserString for ty::BuiltinBound {
|
||||
fn user_string(&self, _tcx: &ctxt) -> ~str {
|
||||
match *self {
|
||||
ty::BoundStatic => ~"'static",
|
||||
ty::BoundSend => ~"Send",
|
||||
ty::BoundSized => ~"Sized",
|
||||
ty::BoundCopy => ~"Pod",
|
||||
ty::BoundShare => ~"Share",
|
||||
ty::BoundStatic => "'static".to_owned(),
|
||||
ty::BoundSend => "Send".to_owned(),
|
||||
ty::BoundSized => "Sized".to_owned(),
|
||||
ty::BoundCopy => "Pod".to_owned(),
|
||||
ty::BoundShare => "Share".to_owned(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -909,7 +909,7 @@ impl<A:UserString> UserString for @A {
|
|||
|
||||
impl UserString for ty::BuiltinBounds {
|
||||
fn user_string(&self, tcx: &ctxt) -> ~str {
|
||||
if self.is_empty() { ~"<no-bounds>" } else {
|
||||
if self.is_empty() { "<no-bounds>".to_owned() } else {
|
||||
let mut result = Vec::new();
|
||||
for bb in self.iter() {
|
||||
result.push(bb.user_string(tcx));
|
||||
|
|
|
@ -576,16 +576,19 @@ mod tests {
|
|||
// Examples from wikipedia
|
||||
let wikipedia_tests = vec!(
|
||||
Test {
|
||||
input: ~"",
|
||||
output_str: ~"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
||||
input: "".to_owned(),
|
||||
output_str: "e3b0c44298fc1c149afb\
|
||||
f4c8996fb92427ae41e4649b934ca495991b7852b855".to_owned()
|
||||
},
|
||||
Test {
|
||||
input: ~"The quick brown fox jumps over the lazy dog",
|
||||
output_str: ~"d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592"
|
||||
input: "The quick brown fox jumps over the lazy dog".to_owned(),
|
||||
output_str: "d7a8fbb307d7809469ca\
|
||||
9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592".to_owned()
|
||||
},
|
||||
Test {
|
||||
input: ~"The quick brown fox jumps over the lazy dog.",
|
||||
output_str: ~"ef537f25c895bfa782526529a9b63d97aa631564d5d789c2b765448c8635fb6c"
|
||||
input: "The quick brown fox jumps over the lazy dog.".to_owned(),
|
||||
output_str: "ef537f25c895bfa78252\
|
||||
6529a9b63d97aa631564d5d789c2b765448c8635fb6c".to_owned()
|
||||
});
|
||||
|
||||
let tests = wikipedia_tests;
|
||||
|
|
|
@ -202,7 +202,7 @@ impl Clean<Item> for doctree::Module {
|
|||
let name = if self.name.is_some() {
|
||||
self.name.unwrap().clean()
|
||||
} else {
|
||||
~""
|
||||
"".to_owned()
|
||||
};
|
||||
let mut foreigns = Vec::new();
|
||||
for subforeigns in self.foreigns.clean().move_iter() {
|
||||
|
@ -1170,7 +1170,7 @@ impl Clean<Item> for ast::ForeignItem {
|
|||
ForeignStaticItem(Static {
|
||||
type_: ty.clean(),
|
||||
mutability: if mutbl {Mutable} else {Immutable},
|
||||
expr: ~"",
|
||||
expr: "".to_owned(),
|
||||
})
|
||||
}
|
||||
};
|
||||
|
@ -1197,7 +1197,7 @@ impl ToSource for syntax::codemap::Span {
|
|||
let cm = local_data::get(super::ctxtkey, |x| x.unwrap().clone()).sess().codemap().clone();
|
||||
let sn = match cm.span_to_snippet(*self) {
|
||||
Some(x) => x,
|
||||
None => ~""
|
||||
None => "".to_owned()
|
||||
};
|
||||
debug!("got snippet {}", sn);
|
||||
sn
|
||||
|
@ -1208,14 +1208,14 @@ fn lit_to_str(lit: &ast::Lit) -> ~str {
|
|||
match lit.node {
|
||||
ast::LitStr(ref st, _) => st.get().to_owned(),
|
||||
ast::LitBinary(ref data) => format!("{:?}", data.as_slice()),
|
||||
ast::LitChar(c) => ~"'" + std::char::from_u32(c).unwrap().to_str() + "'",
|
||||
ast::LitChar(c) => "'".to_owned() + std::char::from_u32(c).unwrap().to_str() + "'",
|
||||
ast::LitInt(i, _t) => i.to_str(),
|
||||
ast::LitUint(u, _t) => u.to_str(),
|
||||
ast::LitIntUnsuffixed(i) => i.to_str(),
|
||||
ast::LitFloat(ref f, _t) => f.get().to_str(),
|
||||
ast::LitFloatUnsuffixed(ref f) => f.get().to_str(),
|
||||
ast::LitBool(b) => b.to_str(),
|
||||
ast::LitNil => ~"",
|
||||
ast::LitNil => "".to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1224,19 +1224,19 @@ fn name_from_pat(p: &ast::Pat) -> ~str {
|
|||
debug!("Trying to get a name from pattern: {:?}", p);
|
||||
|
||||
match p.node {
|
||||
PatWild => ~"_",
|
||||
PatWildMulti => ~"..",
|
||||
PatWild => "_".to_owned(),
|
||||
PatWildMulti => "..".to_owned(),
|
||||
PatIdent(_, ref p, _) => path_to_str(p),
|
||||
PatEnum(ref p, _) => path_to_str(p),
|
||||
PatStruct(..) => fail!("tried to get argument name from pat_struct, \
|
||||
which is not allowed in function arguments"),
|
||||
PatTup(..) => ~"(tuple arg NYI)",
|
||||
PatTup(..) => "(tuple arg NYI)".to_owned(),
|
||||
PatUniq(p) => name_from_pat(p),
|
||||
PatRegion(p) => name_from_pat(p),
|
||||
PatLit(..) => {
|
||||
warn!("tried to get argument name from PatLit, \
|
||||
which is silly in function arguments");
|
||||
~"()"
|
||||
"()".to_owned()
|
||||
},
|
||||
PatRange(..) => fail!("tried to get argument name from PatRange, \
|
||||
which is not allowed in function arguments"),
|
||||
|
|
|
@ -214,7 +214,7 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool,
|
|||
let cache = cache.unwrap();
|
||||
let abs_root = root(&**cache, loc.as_slice());
|
||||
let rel_root = match path.segments.get(0).name.as_slice() {
|
||||
"self" => Some(~"./"),
|
||||
"self" => Some("./".to_owned()),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
|
@ -343,7 +343,7 @@ impl fmt::Show for clean::Type {
|
|||
{arrow, select, yes{ -> {ret}} other{}}",
|
||||
style = FnStyleSpace(decl.fn_style),
|
||||
lifetimes = if decl.lifetimes.len() == 0 {
|
||||
~""
|
||||
"".to_owned()
|
||||
} else {
|
||||
format!("<{:#}>", decl.lifetimes)
|
||||
},
|
||||
|
@ -379,13 +379,13 @@ impl fmt::Show for clean::Type {
|
|||
{arrow, select, yes{ -> {ret}} other{}}",
|
||||
style = FnStyleSpace(decl.fn_style),
|
||||
lifetimes = if decl.lifetimes.len() == 0 {
|
||||
~""
|
||||
"".to_owned()
|
||||
} else {
|
||||
format!("<{:#}>", decl.lifetimes)
|
||||
},
|
||||
args = decl.decl.inputs,
|
||||
bounds = if decl.bounds.len() == 0 {
|
||||
~""
|
||||
"".to_owned()
|
||||
} else {
|
||||
let mut m = decl.bounds.iter().map(|s| s.to_str());
|
||||
": " + m.collect::<~[~str]>().connect(" + ")
|
||||
|
@ -397,8 +397,8 @@ impl fmt::Show for clean::Type {
|
|||
write!(f.buf, "{}{}fn{}{}",
|
||||
FnStyleSpace(decl.fn_style),
|
||||
match decl.abi {
|
||||
ref x if "" == *x => ~"",
|
||||
ref x if "\"Rust\"" == *x => ~"",
|
||||
ref x if "" == *x => "".to_owned(),
|
||||
ref x if "\"Rust\"" == *x => "".to_owned(),
|
||||
ref s => " " + *s + " ",
|
||||
},
|
||||
decl.generics,
|
||||
|
@ -432,7 +432,7 @@ impl fmt::Show for clean::Type {
|
|||
}, **t)
|
||||
}
|
||||
clean::BorrowedRef{ lifetime: ref l, mutability, type_: ref ty} => {
|
||||
let lt = match *l { Some(ref l) => format!("{} ", *l), _ => ~"" };
|
||||
let lt = match *l { Some(ref l) => format!("{} ", *l), _ => "".to_owned() };
|
||||
write!(f.buf, "&{}{}{}",
|
||||
lt,
|
||||
match mutability {
|
||||
|
|
|
@ -27,7 +27,7 @@ use t = syntax::parse::token;
|
|||
/// Highlights some source code, returning the HTML output.
|
||||
pub fn highlight(src: &str, class: Option<&str>) -> ~str {
|
||||
let sess = parse::new_parse_sess();
|
||||
let fm = parse::string_to_filemap(&sess, src.to_owned(), ~"<stdin>");
|
||||
let fm = parse::string_to_filemap(&sess, src.to_owned(), "<stdin>".to_owned());
|
||||
|
||||
let mut out = io::MemWriter::new();
|
||||
doit(&sess,
|
||||
|
|
|
@ -173,7 +173,7 @@ pub fn render(w: &mut io::Writer, s: &str, print_toc: bool) -> fmt::Result {
|
|||
|
||||
// Extract the text provided
|
||||
let s = if text.is_null() {
|
||||
~""
|
||||
"".to_owned()
|
||||
} else {
|
||||
unsafe {
|
||||
str::raw::from_buf_len((*text).data, (*text).size as uint)
|
||||
|
|
|
@ -214,8 +214,8 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
|
|||
root_path: StrBuf::new(),
|
||||
sidebar: HashMap::new(),
|
||||
layout: layout::Layout {
|
||||
logo: ~"",
|
||||
favicon: ~"",
|
||||
logo: "".to_owned(),
|
||||
favicon: "".to_owned(),
|
||||
krate: krate.name.clone(),
|
||||
},
|
||||
include_sources: true,
|
||||
|
@ -309,7 +309,7 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
|
|||
let mut w = MemWriter::new();
|
||||
try!(write!(&mut w, r#"searchIndex['{}'] = \{"items":["#, krate.name));
|
||||
|
||||
let mut lastpath = ~"";
|
||||
let mut lastpath = "".to_owned();
|
||||
for (i, item) in cache.search_index.iter().enumerate() {
|
||||
// Omit the path if it is same to that of the prior item.
|
||||
let path;
|
||||
|
|
|
@ -200,7 +200,7 @@ mod test {
|
|||
// there's been no macro mistake.
|
||||
macro_rules! push {
|
||||
($level: expr, $name: expr) => {
|
||||
assert_eq!(builder.push($level, $name.to_owned(), ~""), $name);
|
||||
assert_eq!(builder.push($level, $name.to_owned(), "".to_owned()), $name);
|
||||
}
|
||||
}
|
||||
push!(2, "0.1");
|
||||
|
@ -240,7 +240,7 @@ mod test {
|
|||
level: $level,
|
||||
name: $name.to_owned(),
|
||||
sec_number: $name.to_owned(),
|
||||
id: ~"",
|
||||
id: "".to_owned(),
|
||||
children: toc!($($sub),*)
|
||||
}
|
||||
),*
|
||||
|
|
|
@ -186,7 +186,7 @@ pub fn main_args(args: &[~str]) -> int {
|
|||
(false, false) => {}
|
||||
}
|
||||
|
||||
if matches.opt_strs("passes").as_slice() == &[~"list"] {
|
||||
if matches.opt_strs("passes").as_slice() == &["list".to_owned()] {
|
||||
println!("Available passes for running rustdoc:");
|
||||
for &(name, _, description) in PASSES.iter() {
|
||||
println!("{:>20s} - {}", name, description);
|
||||
|
@ -309,7 +309,7 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
|
|||
}
|
||||
|
||||
// Load all plugins/passes into a PluginManager
|
||||
let path = matches.opt_str("plugin-path").unwrap_or(~"/tmp/rustdoc/plugins");
|
||||
let path = matches.opt_str("plugin-path").unwrap_or("/tmp/rustdoc/plugins".to_owned());
|
||||
let mut pm = plugins::PluginManager::new(Path::new(path));
|
||||
for pass in passes.iter() {
|
||||
let plugin = match PASSES.iter().position(|&(p, _, _)| p == *pass) {
|
||||
|
@ -343,29 +343,29 @@ fn json_input(input: &str) -> Result<Output, ~str> {
|
|||
Ok(json::Object(obj)) => {
|
||||
let mut obj = obj;
|
||||
// Make sure the schema is what we expect
|
||||
match obj.pop(&~"schema") {
|
||||
match obj.pop(&"schema".to_owned()) {
|
||||
Some(json::String(version)) => {
|
||||
if version.as_slice() != SCHEMA_VERSION {
|
||||
return Err(format!("sorry, but I only understand \
|
||||
version {}", SCHEMA_VERSION))
|
||||
}
|
||||
}
|
||||
Some(..) => return Err(~"malformed json"),
|
||||
None => return Err(~"expected a schema version"),
|
||||
Some(..) => return Err("malformed json".to_owned()),
|
||||
None => return Err("expected a schema version".to_owned()),
|
||||
}
|
||||
let krate = match obj.pop(&~"crate") {
|
||||
let krate = match obj.pop(&"crate".to_owned()) {
|
||||
Some(json) => {
|
||||
let mut d = json::Decoder::new(json);
|
||||
Decodable::decode(&mut d).unwrap()
|
||||
}
|
||||
None => return Err(~"malformed json"),
|
||||
None => return Err("malformed json".to_owned()),
|
||||
};
|
||||
// FIXME: this should read from the "plugins" field, but currently
|
||||
// Json doesn't implement decodable...
|
||||
let plugin_output = Vec::new();
|
||||
Ok((krate, plugin_output))
|
||||
}
|
||||
Ok(..) => Err(~"malformed json input: expected an object at the top"),
|
||||
Ok(..) => Err("malformed json input: expected an object at the top".to_owned()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -379,7 +379,7 @@ fn json_output(krate: clean::Crate, res: Vec<plugins::PluginJson> ,
|
|||
// "plugins": { output of plugins ... }
|
||||
// }
|
||||
let mut json = ~collections::TreeMap::new();
|
||||
json.insert(~"schema", json::String(SCHEMA_VERSION.to_owned()));
|
||||
json.insert("schema".to_owned(), json::String(SCHEMA_VERSION.to_owned()));
|
||||
let plugins_json = ~res.move_iter().filter_map(|opt| opt).collect();
|
||||
|
||||
// FIXME #8335: yuck, Rust -> str -> JSON round trip! No way to .encode
|
||||
|
@ -397,8 +397,8 @@ fn json_output(krate: clean::Crate, res: Vec<plugins::PluginJson> ,
|
|||
Err(e) => fail!("Rust generated JSON is invalid: {:?}", e)
|
||||
};
|
||||
|
||||
json.insert(~"crate", crate_json);
|
||||
json.insert(~"plugins", json::Object(plugins_json));
|
||||
json.insert("crate".to_owned(), crate_json);
|
||||
json.insert("plugins".to_owned(), json::Object(plugins_json));
|
||||
|
||||
let mut file = try!(File::create(&dst));
|
||||
try!(json::Object(json).to_writer(&mut file));
|
||||
|
|
|
@ -166,7 +166,7 @@ pub fn test(input: &str, libs: HashSet<Path>, mut test_args: Vec<~str>) -> int {
|
|||
|
||||
let mut collector = Collector::new(input.to_owned(), libs, true, true);
|
||||
find_testable_code(input_str, &mut collector);
|
||||
test_args.unshift(~"rustdoctest");
|
||||
test_args.unshift("rustdoctest".to_owned());
|
||||
testing::test_main(test_args.as_slice(), collector.tests);
|
||||
0
|
||||
}
|
||||
|
|
|
@ -219,7 +219,7 @@ pub fn unindent_comments(krate: clean::Crate) -> plugins::PluginResult {
|
|||
for attr in i.attrs.iter() {
|
||||
match attr {
|
||||
&clean::NameValue(ref x, ref s) if "doc" == *x => avec.push(
|
||||
clean::NameValue(~"doc", unindent(*s))),
|
||||
clean::NameValue("doc".to_owned(), unindent(*s))),
|
||||
x => avec.push(x.clone())
|
||||
}
|
||||
}
|
||||
|
@ -252,7 +252,7 @@ pub fn collapse_docs(krate: clean::Crate) -> plugins::PluginResult {
|
|||
_ => true
|
||||
}).map(|x| x.clone()).collect();
|
||||
if docstr.len() > 0 {
|
||||
a.push(clean::NameValue(~"doc", docstr.into_owned()));
|
||||
a.push(clean::NameValue("doc".to_owned(), docstr.into_owned()));
|
||||
}
|
||||
i.attrs = a;
|
||||
self.fold_item_recur(i)
|
||||
|
@ -329,25 +329,25 @@ mod unindent_tests {
|
|||
|
||||
#[test]
|
||||
fn should_unindent() {
|
||||
let s = ~" line1\n line2";
|
||||
let s = " line1\n line2".to_owned();
|
||||
let r = unindent(s);
|
||||
assert_eq!(r, ~"line1\nline2");
|
||||
assert_eq!(r, "line1\nline2".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_unindent_multiple_paragraphs() {
|
||||
let s = ~" line1\n\n line2";
|
||||
let s = " line1\n\n line2".to_owned();
|
||||
let r = unindent(s);
|
||||
assert_eq!(r, ~"line1\n\nline2");
|
||||
assert_eq!(r, "line1\n\nline2".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_leave_multiple_indent_levels() {
|
||||
// Line 2 is indented another level beyond the
|
||||
// base indentation and should be preserved
|
||||
let s = ~" line1\n\n line2";
|
||||
let s = " line1\n\n line2".to_owned();
|
||||
let r = unindent(s);
|
||||
assert_eq!(r, ~"line1\n\n line2");
|
||||
assert_eq!(r, "line1\n\n line2".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -357,15 +357,15 @@ mod unindent_tests {
|
|||
//
|
||||
// #[doc = "Start way over here
|
||||
// and continue here"]
|
||||
let s = ~"line1\n line2";
|
||||
let s = "line1\n line2".to_owned();
|
||||
let r = unindent(s);
|
||||
assert_eq!(r, ~"line1\nline2");
|
||||
assert_eq!(r, "line1\nline2".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_not_ignore_first_line_indent_in_a_single_line_para() {
|
||||
let s = ~"line1\n\n line2";
|
||||
let s = "line1\n\n line2".to_owned();
|
||||
let r = unindent(s);
|
||||
assert_eq!(r, ~"line1\n\n line2");
|
||||
assert_eq!(r, "line1\n\n line2".to_owned());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ pub fn run(input: &str, cfgs: Vec<~str>,
|
|||
false);
|
||||
collector.fold_crate(krate);
|
||||
|
||||
test_args.unshift(~"rustdoctest");
|
||||
test_args.unshift("rustdoctest".to_owned());
|
||||
|
||||
testing::test_main(test_args.as_slice(),
|
||||
collector.tests.move_iter().collect());
|
||||
|
|
|
@ -388,7 +388,7 @@ impl fmt::Show for UvError {
|
|||
#[test]
|
||||
fn error_smoke_test() {
|
||||
let err: UvError = UvError(uvll::EOF);
|
||||
assert_eq!(err.to_str(), ~"EOF: end of file");
|
||||
assert_eq!(err.to_str(), "EOF: end of file".to_owned());
|
||||
}
|
||||
|
||||
pub fn uv_error_to_io_error(uverr: UvError) -> IoError {
|
||||
|
|
|
@ -743,7 +743,7 @@ mod test {
|
|||
fn connect_close_ip4() {
|
||||
match TcpWatcher::connect(local_loop(), next_test_ip4()) {
|
||||
Ok(..) => fail!(),
|
||||
Err(e) => assert_eq!(e.name(), ~"ECONNREFUSED"),
|
||||
Err(e) => assert_eq!(e.name(), "ECONNREFUSED".to_owned()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -751,7 +751,7 @@ mod test {
|
|||
fn connect_close_ip6() {
|
||||
match TcpWatcher::connect(local_loop(), next_test_ip6()) {
|
||||
Ok(..) => fail!(),
|
||||
Err(e) => assert_eq!(e.name(), ~"ECONNREFUSED"),
|
||||
Err(e) => assert_eq!(e.name(), "ECONNREFUSED".to_owned()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -275,7 +275,7 @@ mod tests {
|
|||
fn bind_err() {
|
||||
match PipeListener::bind(local_loop(), &"path/to/nowhere".to_c_str()) {
|
||||
Ok(..) => fail!(),
|
||||
Err(e) => assert_eq!(e.name(), ~"EACCES"),
|
||||
Err(e) => assert_eq!(e.name(), "EACCES".to_owned()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -308,14 +308,14 @@ fn test_parse() {
|
|||
major: 1u,
|
||||
minor: 2u,
|
||||
patch: 3u,
|
||||
pre: vec!(AlphaNumeric(~"alpha1")),
|
||||
pre: vec!(AlphaNumeric("alpha1".to_owned())),
|
||||
build: vec!(),
|
||||
}));
|
||||
assert!(parse(" 1.2.3-alpha1 ") == Some(Version {
|
||||
major: 1u,
|
||||
minor: 2u,
|
||||
patch: 3u,
|
||||
pre: vec!(AlphaNumeric(~"alpha1")),
|
||||
pre: vec!(AlphaNumeric("alpha1".to_owned())),
|
||||
build: vec!()
|
||||
}));
|
||||
assert!(parse("1.2.3+build5") == Some(Version {
|
||||
|
@ -323,37 +323,37 @@ fn test_parse() {
|
|||
minor: 2u,
|
||||
patch: 3u,
|
||||
pre: vec!(),
|
||||
build: vec!(AlphaNumeric(~"build5"))
|
||||
build: vec!(AlphaNumeric("build5".to_owned()))
|
||||
}));
|
||||
assert!(parse(" 1.2.3+build5 ") == Some(Version {
|
||||
major: 1u,
|
||||
minor: 2u,
|
||||
patch: 3u,
|
||||
pre: vec!(),
|
||||
build: vec!(AlphaNumeric(~"build5"))
|
||||
build: vec!(AlphaNumeric("build5".to_owned()))
|
||||
}));
|
||||
assert!(parse("1.2.3-alpha1+build5") == Some(Version {
|
||||
major: 1u,
|
||||
minor: 2u,
|
||||
patch: 3u,
|
||||
pre: vec!(AlphaNumeric(~"alpha1")),
|
||||
build: vec!(AlphaNumeric(~"build5"))
|
||||
pre: vec!(AlphaNumeric("alpha1".to_owned())),
|
||||
build: vec!(AlphaNumeric("build5".to_owned()))
|
||||
}));
|
||||
assert!(parse(" 1.2.3-alpha1+build5 ") == Some(Version {
|
||||
major: 1u,
|
||||
minor: 2u,
|
||||
patch: 3u,
|
||||
pre: vec!(AlphaNumeric(~"alpha1")),
|
||||
build: vec!(AlphaNumeric(~"build5"))
|
||||
pre: vec!(AlphaNumeric("alpha1".to_owned())),
|
||||
build: vec!(AlphaNumeric("build5".to_owned()))
|
||||
}));
|
||||
assert!(parse("1.2.3-1.alpha1.9+build5.7.3aedf ") == Some(Version {
|
||||
major: 1u,
|
||||
minor: 2u,
|
||||
patch: 3u,
|
||||
pre: vec!(Numeric(1),AlphaNumeric(~"alpha1"),Numeric(9)),
|
||||
build: vec!(AlphaNumeric(~"build5"),
|
||||
pre: vec!(Numeric(1),AlphaNumeric("alpha1".to_owned()),Numeric(9)),
|
||||
build: vec!(AlphaNumeric("build5".to_owned()),
|
||||
Numeric(7),
|
||||
AlphaNumeric(~"3aedf"))
|
||||
AlphaNumeric("3aedf".to_owned()))
|
||||
}));
|
||||
|
||||
}
|
||||
|
@ -377,18 +377,18 @@ fn test_ne() {
|
|||
|
||||
#[test]
|
||||
fn test_show() {
|
||||
assert_eq!(format!("{}", parse("1.2.3").unwrap()), ~"1.2.3");
|
||||
assert_eq!(format!("{}", parse("1.2.3-alpha1").unwrap()), ~"1.2.3-alpha1");
|
||||
assert_eq!(format!("{}", parse("1.2.3+build.42").unwrap()), ~"1.2.3+build.42");
|
||||
assert_eq!(format!("{}", parse("1.2.3-alpha1+42").unwrap()), ~"1.2.3-alpha1+42");
|
||||
assert_eq!(format!("{}", parse("1.2.3").unwrap()), "1.2.3".to_owned());
|
||||
assert_eq!(format!("{}", parse("1.2.3-alpha1").unwrap()), "1.2.3-alpha1".to_owned());
|
||||
assert_eq!(format!("{}", parse("1.2.3+build.42").unwrap()), "1.2.3+build.42".to_owned());
|
||||
assert_eq!(format!("{}", parse("1.2.3-alpha1+42").unwrap()), "1.2.3-alpha1+42".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_str() {
|
||||
assert_eq!(parse("1.2.3").unwrap().to_str(), ~"1.2.3");
|
||||
assert_eq!(parse("1.2.3-alpha1").unwrap().to_str(), ~"1.2.3-alpha1");
|
||||
assert_eq!(parse("1.2.3+build.42").unwrap().to_str(), ~"1.2.3+build.42");
|
||||
assert_eq!(parse("1.2.3-alpha1+42").unwrap().to_str(), ~"1.2.3-alpha1+42");
|
||||
assert_eq!(parse("1.2.3").unwrap().to_str(), "1.2.3".to_owned());
|
||||
assert_eq!(parse("1.2.3-alpha1").unwrap().to_str(), "1.2.3-alpha1".to_owned());
|
||||
assert_eq!(parse("1.2.3+build.42").unwrap().to_str(), "1.2.3+build.42".to_owned());
|
||||
assert_eq!(parse("1.2.3-alpha1+42").unwrap().to_str(), "1.2.3-alpha1+42".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -269,13 +269,13 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_to_base64_basic() {
|
||||
assert_eq!("".as_bytes().to_base64(STANDARD), ~"");
|
||||
assert_eq!("f".as_bytes().to_base64(STANDARD), ~"Zg==");
|
||||
assert_eq!("fo".as_bytes().to_base64(STANDARD), ~"Zm8=");
|
||||
assert_eq!("foo".as_bytes().to_base64(STANDARD), ~"Zm9v");
|
||||
assert_eq!("foob".as_bytes().to_base64(STANDARD), ~"Zm9vYg==");
|
||||
assert_eq!("fooba".as_bytes().to_base64(STANDARD), ~"Zm9vYmE=");
|
||||
assert_eq!("foobar".as_bytes().to_base64(STANDARD), ~"Zm9vYmFy");
|
||||
assert_eq!("".as_bytes().to_base64(STANDARD), "".to_owned());
|
||||
assert_eq!("f".as_bytes().to_base64(STANDARD), "Zg==".to_owned());
|
||||
assert_eq!("fo".as_bytes().to_base64(STANDARD), "Zm8=".to_owned());
|
||||
assert_eq!("foo".as_bytes().to_base64(STANDARD), "Zm9v".to_owned());
|
||||
assert_eq!("foob".as_bytes().to_base64(STANDARD), "Zm9vYg==".to_owned());
|
||||
assert_eq!("fooba".as_bytes().to_base64(STANDARD), "Zm9vYmE=".to_owned());
|
||||
assert_eq!("foobar".as_bytes().to_base64(STANDARD), "Zm9vYmFy".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -284,19 +284,19 @@ mod tests {
|
|||
.contains("\r\n"));
|
||||
assert_eq!("foobar".as_bytes().to_base64(Config {line_length: Some(4),
|
||||
..STANDARD}),
|
||||
~"Zm9v\r\nYmFy");
|
||||
"Zm9v\r\nYmFy".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_base64_padding() {
|
||||
assert_eq!("f".as_bytes().to_base64(Config {pad: false, ..STANDARD}), ~"Zg");
|
||||
assert_eq!("fo".as_bytes().to_base64(Config {pad: false, ..STANDARD}), ~"Zm8");
|
||||
assert_eq!("f".as_bytes().to_base64(Config {pad: false, ..STANDARD}), "Zg".to_owned());
|
||||
assert_eq!("fo".as_bytes().to_base64(Config {pad: false, ..STANDARD}), "Zm8".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_base64_url_safe() {
|
||||
assert_eq!([251, 255].to_base64(URL_SAFE), ~"-_8");
|
||||
assert_eq!([251, 255].to_base64(STANDARD), ~"+/8=");
|
||||
assert_eq!([251, 255].to_base64(URL_SAFE), "-_8".to_owned());
|
||||
assert_eq!([251, 255].to_base64(STANDARD), "+/8=".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -145,7 +145,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
pub fn test_to_hex() {
|
||||
assert_eq!("foobar".as_bytes().to_hex(), ~"666f6f626172");
|
||||
assert_eq!("foobar".as_bytes().to_hex(), "666f6f626172".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -68,7 +68,7 @@ use serialize::{json, Encodable};
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let to_encode_object = TestStruct{data_str:~"example of string to encode"};
|
||||
let to_encode_object = TestStruct{data_str:"example of string to encode".to_owned()};
|
||||
let mut m = io::MemWriter::new();
|
||||
{
|
||||
let mut encoder = json::Encoder::new(&mut m as &mut std::io::Writer);
|
||||
|
@ -85,7 +85,7 @@ into a string (~str) or buffer (~[u8]): `str_encode(&m)` and `buffer_encode(&m)`
|
|||
|
||||
```rust
|
||||
use serialize::json;
|
||||
let to_encode_object = ~"example of string to encode";
|
||||
let to_encode_object = "example of string to encode".to_owned();
|
||||
let encoded_str: ~str = json::Encoder::str_encode(&to_encode_object);
|
||||
```
|
||||
|
||||
|
@ -114,14 +114,14 @@ pub struct MyStruct {
|
|||
impl ToJson for MyStruct {
|
||||
fn to_json( &self ) -> json::Json {
|
||||
let mut d = ~TreeMap::new();
|
||||
d.insert(~"attr1", self.attr1.to_json());
|
||||
d.insert(~"attr2", self.attr2.to_json());
|
||||
d.insert("attr1".to_owned(), self.attr1.to_json());
|
||||
d.insert("attr2".to_owned(), self.attr2.to_json());
|
||||
json::Object(d)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let test2: MyStruct = MyStruct {attr1: 1, attr2:~"test"};
|
||||
let test2: MyStruct = MyStruct {attr1: 1, attr2:"test".to_owned()};
|
||||
let tjson: json::Json = test2.to_json();
|
||||
let json_str: ~str = tjson.to_str();
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ pub struct MyStruct {
|
|||
|
||||
fn main() {
|
||||
let json_str_to_decode: ~str =
|
||||
~"{\"attr1\":1,\"attr2\":\"toto\"}";
|
||||
"{\"attr1\":1,\"attr2\":\"toto\"}".to_owned();
|
||||
let json_object = json::from_str(json_str_to_decode);
|
||||
let mut decoder = json::Decoder::new(json_object.unwrap());
|
||||
let decoded_object: MyStruct = match Decodable::decode(&mut decoder) {
|
||||
|
@ -173,7 +173,7 @@ use serialize::{json, Encodable, Decodable};
|
|||
// It calls the generated `Encodable` impl.
|
||||
fn main() {
|
||||
let to_encode_object = TestStruct1
|
||||
{data_int: 1, data_str:~"toto", data_vector:~[2,3,4,5]};
|
||||
{data_int: 1, data_str:"toto".to_owned(), data_vector:~[2,3,4,5]};
|
||||
let encoded_str: ~str = json::Encoder::str_encode(&to_encode_object);
|
||||
|
||||
// To deserialize use the `json::from_str` and `json::Decoder`
|
||||
|
@ -207,9 +207,9 @@ pub struct TestStruct1 {
|
|||
impl ToJson for TestStruct1 {
|
||||
fn to_json( &self ) -> json::Json {
|
||||
let mut d = ~TreeMap::new();
|
||||
d.insert(~"data_int", self.data_int.to_json());
|
||||
d.insert(~"data_str", self.data_str.to_json());
|
||||
d.insert(~"data_vector", self.data_vector.to_json());
|
||||
d.insert("data_int".to_owned(), self.data_int.to_json());
|
||||
d.insert("data_str".to_owned(), self.data_str.to_json());
|
||||
d.insert("data_vector".to_owned(), self.data_vector.to_json());
|
||||
json::Object(d)
|
||||
}
|
||||
}
|
||||
|
@ -217,7 +217,8 @@ impl ToJson for TestStruct1 {
|
|||
fn main() {
|
||||
// Serialization using our impl of to_json
|
||||
|
||||
let test2: TestStruct1 = TestStruct1 {data_int: 1, data_str:~"toto", data_vector:~[2,3,4,5]};
|
||||
let test2: TestStruct1 = TestStruct1 {data_int: 1, data_str:"toto".to_owned(),
|
||||
data_vector:~[2,3,4,5]};
|
||||
let tjson: json::Json = test2.to_json();
|
||||
let json_str: ~str = tjson.to_str();
|
||||
|
||||
|
@ -931,7 +932,7 @@ impl<T: Iterator<char>> Parser<T> {
|
|||
if self.eof() {
|
||||
Ok(value)
|
||||
} else {
|
||||
self.error(~"trailing characters")
|
||||
self.error("trailing characters".to_owned())
|
||||
}
|
||||
}
|
||||
Err(e) => Err(e)
|
||||
|
@ -968,7 +969,7 @@ impl<T : Iterator<char>> Parser<T> {
|
|||
fn parse_value(&mut self) -> DecodeResult<Json> {
|
||||
self.parse_whitespace();
|
||||
|
||||
if self.eof() { return self.error(~"EOF while parsing value"); }
|
||||
if self.eof() { return self.error("EOF while parsing value".to_owned()); }
|
||||
|
||||
match self.ch_or_null() {
|
||||
'n' => self.parse_ident("ull", Null),
|
||||
|
@ -983,7 +984,7 @@ impl<T : Iterator<char>> Parser<T> {
|
|||
},
|
||||
'[' => self.parse_list(),
|
||||
'{' => self.parse_object(),
|
||||
_ => self.error(~"invalid syntax"),
|
||||
_ => self.error("invalid syntax".to_owned()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -999,7 +1000,7 @@ impl<T : Iterator<char>> Parser<T> {
|
|||
self.bump();
|
||||
Ok(value)
|
||||
} else {
|
||||
self.error(~"invalid syntax")
|
||||
self.error("invalid syntax".to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1042,7 +1043,7 @@ impl<T : Iterator<char>> Parser<T> {
|
|||
|
||||
// There can be only one leading '0'.
|
||||
match self.ch_or_null() {
|
||||
'0' .. '9' => return self.error(~"invalid number"),
|
||||
'0' .. '9' => return self.error("invalid number".to_owned()),
|
||||
_ => ()
|
||||
}
|
||||
},
|
||||
|
@ -1059,7 +1060,7 @@ impl<T : Iterator<char>> Parser<T> {
|
|||
}
|
||||
}
|
||||
}
|
||||
_ => return self.error(~"invalid number"),
|
||||
_ => return self.error("invalid number".to_owned()),
|
||||
}
|
||||
Ok(res)
|
||||
}
|
||||
|
@ -1070,7 +1071,7 @@ impl<T : Iterator<char>> Parser<T> {
|
|||
// Make sure a digit follows the decimal place.
|
||||
match self.ch_or_null() {
|
||||
'0' .. '9' => (),
|
||||
_ => return self.error(~"invalid number")
|
||||
_ => return self.error("invalid number".to_owned())
|
||||
}
|
||||
|
||||
let mut res = res;
|
||||
|
@ -1106,7 +1107,7 @@ impl<T : Iterator<char>> Parser<T> {
|
|||
// Make sure a digit follows the exponent place.
|
||||
match self.ch_or_null() {
|
||||
'0' .. '9' => (),
|
||||
_ => return self.error(~"invalid number")
|
||||
_ => return self.error("invalid number".to_owned())
|
||||
}
|
||||
while !self.eof() {
|
||||
match self.ch_or_null() {
|
||||
|
@ -1144,7 +1145,7 @@ impl<T : Iterator<char>> Parser<T> {
|
|||
'e' | 'E' => n * 16_u16 + 14_u16,
|
||||
'f' | 'F' => n * 16_u16 + 15_u16,
|
||||
_ => return self.error(
|
||||
~"invalid \\u escape (unrecognized hex)")
|
||||
"invalid \\u escape (unrecognized hex)".to_owned())
|
||||
};
|
||||
|
||||
i += 1u;
|
||||
|
@ -1153,7 +1154,7 @@ impl<T : Iterator<char>> Parser<T> {
|
|||
// Error out if we didn't parse 4 digits.
|
||||
if i != 4u {
|
||||
return self.error(
|
||||
~"invalid \\u escape (not four digits)");
|
||||
"invalid \\u escape (not four digits)".to_owned());
|
||||
}
|
||||
|
||||
Ok(n)
|
||||
|
@ -1166,7 +1167,7 @@ impl<T : Iterator<char>> Parser<T> {
|
|||
loop {
|
||||
self.bump();
|
||||
if self.eof() {
|
||||
return self.error(~"EOF while parsing string");
|
||||
return self.error("EOF while parsing string".to_owned());
|
||||
}
|
||||
|
||||
if escape {
|
||||
|
@ -1181,7 +1182,7 @@ impl<T : Iterator<char>> Parser<T> {
|
|||
't' => res.push_char('\t'),
|
||||
'u' => match try!(self.decode_hex_escape()) {
|
||||
0xDC00 .. 0xDFFF => return self.error(
|
||||
~"lone trailing surrogate in hex escape"),
|
||||
"lone trailing surrogate in hex escape".to_owned()),
|
||||
|
||||
// Non-BMP characters are encoded as a sequence of
|
||||
// two hex escapes, representing UTF-16 surrogates.
|
||||
|
@ -1191,14 +1192,14 @@ impl<T : Iterator<char>> Parser<T> {
|
|||
match (c1, c2) {
|
||||
(Some('\\'), Some('u')) => (),
|
||||
_ => return self.error(
|
||||
~"unexpected end of non-BMP hex escape"),
|
||||
"unexpected end of non-BMP hex escape".to_owned()),
|
||||
}
|
||||
|
||||
let buf = [n1, try!(self.decode_hex_escape())];
|
||||
match str::utf16_items(buf.as_slice()).next() {
|
||||
Some(ScalarValue(c)) => res.push_char(c),
|
||||
_ => return self.error(
|
||||
~"lone leading surrogate in hex escape"),
|
||||
"lone leading surrogate in hex escape".to_owned()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1208,7 +1209,7 @@ impl<T : Iterator<char>> Parser<T> {
|
|||
format!("invalid Unicode codepoint {:u}", n)),
|
||||
},
|
||||
},
|
||||
_ => return self.error(~"invalid escape"),
|
||||
_ => return self.error("invalid escape".to_owned()),
|
||||
}
|
||||
escape = false;
|
||||
} else if self.ch_is('\\') {
|
||||
|
@ -1245,7 +1246,7 @@ impl<T : Iterator<char>> Parser<T> {
|
|||
|
||||
self.parse_whitespace();
|
||||
if self.eof() {
|
||||
return self.error(~"EOF while parsing list");
|
||||
return self.error("EOF while parsing list".to_owned());
|
||||
}
|
||||
|
||||
if self.ch_is(',') {
|
||||
|
@ -1254,7 +1255,7 @@ impl<T : Iterator<char>> Parser<T> {
|
|||
self.bump();
|
||||
return Ok(List(values.move_iter().collect()));
|
||||
} else {
|
||||
return self.error(~"expected `,` or `]`")
|
||||
return self.error("expected `,` or `]`".to_owned())
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1274,7 +1275,7 @@ impl<T : Iterator<char>> Parser<T> {
|
|||
self.parse_whitespace();
|
||||
|
||||
if !self.ch_is('"') {
|
||||
return self.error(~"key must be a string");
|
||||
return self.error("key must be a string".to_owned());
|
||||
}
|
||||
|
||||
let key = match self.parse_str() {
|
||||
|
@ -1286,7 +1287,7 @@ impl<T : Iterator<char>> Parser<T> {
|
|||
|
||||
if !self.ch_is(':') {
|
||||
if self.eof() { break; }
|
||||
return self.error(~"expected `:`");
|
||||
return self.error("expected `:`".to_owned());
|
||||
}
|
||||
self.bump();
|
||||
|
||||
|
@ -1301,12 +1302,12 @@ impl<T : Iterator<char>> Parser<T> {
|
|||
'}' => { self.bump(); return Ok(Object(values)); },
|
||||
_ => {
|
||||
if self.eof() { break; }
|
||||
return self.error(~"expected `,` or `}`");
|
||||
return self.error("expected `,` or `}`".to_owned());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return self.error(~"EOF while parsing object");
|
||||
return self.error("EOF while parsing object".to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1318,7 +1319,7 @@ pub fn from_reader(rdr: &mut io::Reader) -> DecodeResult<Json> {
|
|||
};
|
||||
let s = match str::from_utf8(contents.as_slice()) {
|
||||
Some(s) => s.to_owned(),
|
||||
None => return Err(ParseError(~"contents not utf-8", 0, 0))
|
||||
None => return Err(ParseError("contents not utf-8".to_owned(), 0, 0))
|
||||
};
|
||||
let mut parser = Parser::new(s.chars());
|
||||
parser.parse()
|
||||
|
@ -1354,7 +1355,7 @@ macro_rules! expect(
|
|||
($e:expr, Null) => ({
|
||||
match $e {
|
||||
Null => Ok(()),
|
||||
other => Err(ExpectedError(~"Null", format!("{}", other)))
|
||||
other => Err(ExpectedError("Null".to_owned(), format!("{}", other)))
|
||||
}
|
||||
});
|
||||
($e:expr, $t:ident) => ({
|
||||
|
@ -1399,7 +1400,7 @@ impl ::Decoder<Error> for Decoder {
|
|||
// is going to have a string here, as per JSON spec..
|
||||
Ok(FromStr::from_str(s).unwrap())
|
||||
},
|
||||
value => Err(ExpectedError(~"Number", format!("{}", value)))
|
||||
value => Err(ExpectedError("Number".to_owned(), format!("{}", value)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1415,7 +1416,7 @@ impl ::Decoder<Error> for Decoder {
|
|||
_ => ()
|
||||
}
|
||||
}
|
||||
Err(ExpectedError(~"single character string", format!("{}", s)))
|
||||
Err(ExpectedError("single character string".to_owned(), format!("{}", s)))
|
||||
}
|
||||
|
||||
fn read_str(&mut self) -> DecodeResult<~str> {
|
||||
|
@ -1438,23 +1439,23 @@ impl ::Decoder<Error> for Decoder {
|
|||
let name = match self.pop() {
|
||||
String(s) => s,
|
||||
Object(mut o) => {
|
||||
let n = match o.pop(&~"variant") {
|
||||
let n = match o.pop(&"variant".to_owned()) {
|
||||
Some(String(s)) => s,
|
||||
Some(val) => return Err(ExpectedError(~"String", format!("{}", val))),
|
||||
None => return Err(MissingFieldError(~"variant"))
|
||||
Some(val) => return Err(ExpectedError("String".to_owned(), format!("{}", val))),
|
||||
None => return Err(MissingFieldError("variant".to_owned()))
|
||||
};
|
||||
match o.pop(&~"fields") {
|
||||
match o.pop(&"fields".to_owned()) {
|
||||
Some(List(l)) => {
|
||||
for field in l.move_rev_iter() {
|
||||
self.stack.push(field.clone());
|
||||
}
|
||||
},
|
||||
Some(val) => return Err(ExpectedError(~"List", format!("{}", val))),
|
||||
None => return Err(MissingFieldError(~"fields"))
|
||||
Some(val) => return Err(ExpectedError("List".to_owned(), format!("{}", val))),
|
||||
None => return Err(MissingFieldError("fields".to_owned()))
|
||||
}
|
||||
n
|
||||
}
|
||||
json => return Err(ExpectedError(~"String or Object", format!("{}", json)))
|
||||
json => return Err(ExpectedError("String or Object".to_owned(), format!("{}", json)))
|
||||
};
|
||||
let idx = match names.iter().position(|n| str::eq_slice(*n, name)) {
|
||||
Some(idx) => idx,
|
||||
|
@ -1820,68 +1821,68 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_write_null() {
|
||||
assert_eq!(Null.to_str(), ~"null");
|
||||
assert_eq!(Null.to_pretty_str(), ~"null");
|
||||
assert_eq!(Null.to_str(), "null".to_owned());
|
||||
assert_eq!(Null.to_pretty_str(), "null".to_owned());
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_write_number() {
|
||||
assert_eq!(Number(3.0).to_str(), ~"3");
|
||||
assert_eq!(Number(3.0).to_pretty_str(), ~"3");
|
||||
assert_eq!(Number(3.0).to_str(), "3".to_owned());
|
||||
assert_eq!(Number(3.0).to_pretty_str(), "3".to_owned());
|
||||
|
||||
assert_eq!(Number(3.1).to_str(), ~"3.1");
|
||||
assert_eq!(Number(3.1).to_pretty_str(), ~"3.1");
|
||||
assert_eq!(Number(3.1).to_str(), "3.1".to_owned());
|
||||
assert_eq!(Number(3.1).to_pretty_str(), "3.1".to_owned());
|
||||
|
||||
assert_eq!(Number(-1.5).to_str(), ~"-1.5");
|
||||
assert_eq!(Number(-1.5).to_pretty_str(), ~"-1.5");
|
||||
assert_eq!(Number(-1.5).to_str(), "-1.5".to_owned());
|
||||
assert_eq!(Number(-1.5).to_pretty_str(), "-1.5".to_owned());
|
||||
|
||||
assert_eq!(Number(0.5).to_str(), ~"0.5");
|
||||
assert_eq!(Number(0.5).to_pretty_str(), ~"0.5");
|
||||
assert_eq!(Number(0.5).to_str(), "0.5".to_owned());
|
||||
assert_eq!(Number(0.5).to_pretty_str(), "0.5".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_write_str() {
|
||||
assert_eq!(String(~"").to_str(), ~"\"\"");
|
||||
assert_eq!(String(~"").to_pretty_str(), ~"\"\"");
|
||||
assert_eq!(String("".to_owned()).to_str(), "\"\"".to_owned());
|
||||
assert_eq!(String("".to_owned()).to_pretty_str(), "\"\"".to_owned());
|
||||
|
||||
assert_eq!(String(~"foo").to_str(), ~"\"foo\"");
|
||||
assert_eq!(String(~"foo").to_pretty_str(), ~"\"foo\"");
|
||||
assert_eq!(String("foo".to_owned()).to_str(), "\"foo\"".to_owned());
|
||||
assert_eq!(String("foo".to_owned()).to_pretty_str(), "\"foo\"".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_write_bool() {
|
||||
assert_eq!(Boolean(true).to_str(), ~"true");
|
||||
assert_eq!(Boolean(true).to_pretty_str(), ~"true");
|
||||
assert_eq!(Boolean(true).to_str(), "true".to_owned());
|
||||
assert_eq!(Boolean(true).to_pretty_str(), "true".to_owned());
|
||||
|
||||
assert_eq!(Boolean(false).to_str(), ~"false");
|
||||
assert_eq!(Boolean(false).to_pretty_str(), ~"false");
|
||||
assert_eq!(Boolean(false).to_str(), "false".to_owned());
|
||||
assert_eq!(Boolean(false).to_pretty_str(), "false".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_write_list() {
|
||||
assert_eq!(List(~[]).to_str(), ~"[]");
|
||||
assert_eq!(List(~[]).to_pretty_str(), ~"[]");
|
||||
assert_eq!(List(~[]).to_str(), "[]".to_owned());
|
||||
assert_eq!(List(~[]).to_pretty_str(), "[]".to_owned());
|
||||
|
||||
assert_eq!(List(~[Boolean(true)]).to_str(), ~"[true]");
|
||||
assert_eq!(List(~[Boolean(true)]).to_str(), "[true]".to_owned());
|
||||
assert_eq!(
|
||||
List(~[Boolean(true)]).to_pretty_str(),
|
||||
~"\
|
||||
"\
|
||||
[\n \
|
||||
true\n\
|
||||
]"
|
||||
]".to_owned()
|
||||
);
|
||||
|
||||
let long_test_list = List(~[
|
||||
Boolean(false),
|
||||
Null,
|
||||
List(~[String(~"foo\nbar"), Number(3.5)])]);
|
||||
List(~[String("foo\nbar".to_owned()), Number(3.5)])]);
|
||||
|
||||
assert_eq!(long_test_list.to_str(),
|
||||
~"[false,null,[\"foo\\nbar\",3.5]]");
|
||||
"[false,null,[\"foo\\nbar\",3.5]]".to_owned());
|
||||
assert_eq!(
|
||||
long_test_list.to_pretty_str(),
|
||||
~"\
|
||||
"\
|
||||
[\n \
|
||||
false,\n \
|
||||
null,\n \
|
||||
|
@ -1889,46 +1890,46 @@ mod tests {
|
|||
\"foo\\nbar\",\n \
|
||||
3.5\n \
|
||||
]\n\
|
||||
]"
|
||||
]".to_owned()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_write_object() {
|
||||
assert_eq!(mk_object([]).to_str(), ~"{}");
|
||||
assert_eq!(mk_object([]).to_pretty_str(), ~"{}");
|
||||
assert_eq!(mk_object([]).to_str(), "{}".to_owned());
|
||||
assert_eq!(mk_object([]).to_pretty_str(), "{}".to_owned());
|
||||
|
||||
assert_eq!(
|
||||
mk_object([(~"a", Boolean(true))]).to_str(),
|
||||
~"{\"a\":true}"
|
||||
mk_object([("a".to_owned(), Boolean(true))]).to_str(),
|
||||
"{\"a\":true}".to_owned()
|
||||
);
|
||||
assert_eq!(
|
||||
mk_object([(~"a", Boolean(true))]).to_pretty_str(),
|
||||
~"\
|
||||
mk_object([("a".to_owned(), Boolean(true))]).to_pretty_str(),
|
||||
"\
|
||||
{\n \
|
||||
\"a\": true\n\
|
||||
}"
|
||||
}".to_owned()
|
||||
);
|
||||
|
||||
let complex_obj = mk_object([
|
||||
(~"b", List(~[
|
||||
mk_object([(~"c", String(~"\x0c\r"))]),
|
||||
mk_object([(~"d", String(~""))])
|
||||
("b".to_owned(), List(~[
|
||||
mk_object([("c".to_owned(), String("\x0c\r".to_owned()))]),
|
||||
mk_object([("d".to_owned(), String("".to_owned()))])
|
||||
]))
|
||||
]);
|
||||
|
||||
assert_eq!(
|
||||
complex_obj.to_str(),
|
||||
~"{\
|
||||
"{\
|
||||
\"b\":[\
|
||||
{\"c\":\"\\f\\r\"},\
|
||||
{\"d\":\"\"}\
|
||||
]\
|
||||
}"
|
||||
}".to_owned()
|
||||
);
|
||||
assert_eq!(
|
||||
complex_obj.to_pretty_str(),
|
||||
~"\
|
||||
"\
|
||||
{\n \
|
||||
\"b\": [\n \
|
||||
{\n \
|
||||
|
@ -1938,14 +1939,14 @@ mod tests {
|
|||
\"d\": \"\"\n \
|
||||
}\n \
|
||||
]\n\
|
||||
}"
|
||||
}".to_owned()
|
||||
);
|
||||
|
||||
let a = mk_object([
|
||||
(~"a", Boolean(true)),
|
||||
(~"b", List(~[
|
||||
mk_object([(~"c", String(~"\x0c\r"))]),
|
||||
mk_object([(~"d", String(~""))])
|
||||
("a".to_owned(), Boolean(true)),
|
||||
("b".to_owned(), List(~[
|
||||
mk_object([("c".to_owned(), String("\x0c\r".to_owned()))]),
|
||||
mk_object([("d".to_owned(), String("".to_owned()))])
|
||||
]))
|
||||
]);
|
||||
|
||||
|
@ -1972,53 +1973,53 @@ mod tests {
|
|||
let mut encoder = Encoder::new(wr);
|
||||
animal.encode(&mut encoder).unwrap();
|
||||
}),
|
||||
~"\"Dog\""
|
||||
"\"Dog\"".to_owned()
|
||||
);
|
||||
assert_eq!(
|
||||
with_str_writer(|wr| {
|
||||
let mut encoder = PrettyEncoder::new(wr);
|
||||
animal.encode(&mut encoder).unwrap();
|
||||
}),
|
||||
~"\"Dog\""
|
||||
"\"Dog\"".to_owned()
|
||||
);
|
||||
|
||||
let animal = Frog(~"Henry", 349);
|
||||
let animal = Frog("Henry".to_owned(), 349);
|
||||
assert_eq!(
|
||||
with_str_writer(|wr| {
|
||||
let mut encoder = Encoder::new(wr);
|
||||
animal.encode(&mut encoder).unwrap();
|
||||
}),
|
||||
~"{\"variant\":\"Frog\",\"fields\":[\"Henry\",349]}"
|
||||
"{\"variant\":\"Frog\",\"fields\":[\"Henry\",349]}".to_owned()
|
||||
);
|
||||
assert_eq!(
|
||||
with_str_writer(|wr| {
|
||||
let mut encoder = PrettyEncoder::new(wr);
|
||||
animal.encode(&mut encoder).unwrap();
|
||||
}),
|
||||
~"\
|
||||
"\
|
||||
[\n \
|
||||
\"Frog\",\n \
|
||||
\"Henry\",\n \
|
||||
349\n\
|
||||
]"
|
||||
]".to_owned()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_write_some() {
|
||||
let value = Some(~"jodhpurs");
|
||||
let value = Some("jodhpurs".to_owned());
|
||||
let s = with_str_writer(|wr| {
|
||||
let mut encoder = Encoder::new(wr);
|
||||
value.encode(&mut encoder).unwrap();
|
||||
});
|
||||
assert_eq!(s, ~"\"jodhpurs\"");
|
||||
assert_eq!(s, "\"jodhpurs\"".to_owned());
|
||||
|
||||
let value = Some(~"jodhpurs");
|
||||
let value = Some("jodhpurs".to_owned());
|
||||
let s = with_str_writer(|wr| {
|
||||
let mut encoder = PrettyEncoder::new(wr);
|
||||
value.encode(&mut encoder).unwrap();
|
||||
});
|
||||
assert_eq!(s, ~"\"jodhpurs\"");
|
||||
assert_eq!(s, "\"jodhpurs\"".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2028,47 +2029,47 @@ mod tests {
|
|||
let mut encoder = Encoder::new(wr);
|
||||
value.encode(&mut encoder).unwrap();
|
||||
});
|
||||
assert_eq!(s, ~"null");
|
||||
assert_eq!(s, "null".to_owned());
|
||||
|
||||
let s = with_str_writer(|wr| {
|
||||
let mut encoder = Encoder::new(wr);
|
||||
value.encode(&mut encoder).unwrap();
|
||||
});
|
||||
assert_eq!(s, ~"null");
|
||||
assert_eq!(s, "null".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_trailing_characters() {
|
||||
assert_eq!(from_str("nulla"),
|
||||
Err(ParseError(~"trailing characters", 1u, 5u)));
|
||||
Err(ParseError("trailing characters".to_owned(), 1u, 5u)));
|
||||
assert_eq!(from_str("truea"),
|
||||
Err(ParseError(~"trailing characters", 1u, 5u)));
|
||||
Err(ParseError("trailing characters".to_owned(), 1u, 5u)));
|
||||
assert_eq!(from_str("falsea"),
|
||||
Err(ParseError(~"trailing characters", 1u, 6u)));
|
||||
Err(ParseError("trailing characters".to_owned(), 1u, 6u)));
|
||||
assert_eq!(from_str("1a"),
|
||||
Err(ParseError(~"trailing characters", 1u, 2u)));
|
||||
Err(ParseError("trailing characters".to_owned(), 1u, 2u)));
|
||||
assert_eq!(from_str("[]a"),
|
||||
Err(ParseError(~"trailing characters", 1u, 3u)));
|
||||
Err(ParseError("trailing characters".to_owned(), 1u, 3u)));
|
||||
assert_eq!(from_str("{}a"),
|
||||
Err(ParseError(~"trailing characters", 1u, 3u)));
|
||||
Err(ParseError("trailing characters".to_owned(), 1u, 3u)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_read_identifiers() {
|
||||
assert_eq!(from_str("n"),
|
||||
Err(ParseError(~"invalid syntax", 1u, 2u)));
|
||||
Err(ParseError("invalid syntax".to_owned(), 1u, 2u)));
|
||||
assert_eq!(from_str("nul"),
|
||||
Err(ParseError(~"invalid syntax", 1u, 4u)));
|
||||
Err(ParseError("invalid syntax".to_owned(), 1u, 4u)));
|
||||
|
||||
assert_eq!(from_str("t"),
|
||||
Err(ParseError(~"invalid syntax", 1u, 2u)));
|
||||
Err(ParseError("invalid syntax".to_owned(), 1u, 2u)));
|
||||
assert_eq!(from_str("truz"),
|
||||
Err(ParseError(~"invalid syntax", 1u, 4u)));
|
||||
Err(ParseError("invalid syntax".to_owned(), 1u, 4u)));
|
||||
|
||||
assert_eq!(from_str("f"),
|
||||
Err(ParseError(~"invalid syntax", 1u, 2u)));
|
||||
Err(ParseError("invalid syntax".to_owned(), 1u, 2u)));
|
||||
assert_eq!(from_str("faz"),
|
||||
Err(ParseError(~"invalid syntax", 1u, 3u)));
|
||||
Err(ParseError("invalid syntax".to_owned(), 1u, 3u)));
|
||||
|
||||
assert_eq!(from_str("null"), Ok(Null));
|
||||
assert_eq!(from_str("true"), Ok(Boolean(true)));
|
||||
|
@ -2096,20 +2097,20 @@ mod tests {
|
|||
#[test]
|
||||
fn test_read_number() {
|
||||
assert_eq!(from_str("+"),
|
||||
Err(ParseError(~"invalid syntax", 1u, 1u)));
|
||||
Err(ParseError("invalid syntax".to_owned(), 1u, 1u)));
|
||||
assert_eq!(from_str("."),
|
||||
Err(ParseError(~"invalid syntax", 1u, 1u)));
|
||||
Err(ParseError("invalid syntax".to_owned(), 1u, 1u)));
|
||||
|
||||
assert_eq!(from_str("-"),
|
||||
Err(ParseError(~"invalid number", 1u, 2u)));
|
||||
Err(ParseError("invalid number".to_owned(), 1u, 2u)));
|
||||
assert_eq!(from_str("00"),
|
||||
Err(ParseError(~"invalid number", 1u, 2u)));
|
||||
Err(ParseError("invalid number".to_owned(), 1u, 2u)));
|
||||
assert_eq!(from_str("1."),
|
||||
Err(ParseError(~"invalid number", 1u, 3u)));
|
||||
Err(ParseError("invalid number".to_owned(), 1u, 3u)));
|
||||
assert_eq!(from_str("1e"),
|
||||
Err(ParseError(~"invalid number", 1u, 3u)));
|
||||
Err(ParseError("invalid number".to_owned(), 1u, 3u)));
|
||||
assert_eq!(from_str("1e+"),
|
||||
Err(ParseError(~"invalid number", 1u, 4u)));
|
||||
Err(ParseError("invalid number".to_owned(), 1u, 4u)));
|
||||
|
||||
assert_eq!(from_str("3"), Ok(Number(3.0)));
|
||||
assert_eq!(from_str("3.1"), Ok(Number(3.1)));
|
||||
|
@ -2155,24 +2156,24 @@ mod tests {
|
|||
#[test]
|
||||
fn test_read_str() {
|
||||
assert_eq!(from_str("\""),
|
||||
Err(ParseError(~"EOF while parsing string", 1u, 2u)));
|
||||
Err(ParseError("EOF while parsing string".to_owned(), 1u, 2u)));
|
||||
assert_eq!(from_str("\"lol"),
|
||||
Err(ParseError(~"EOF while parsing string", 1u, 5u)));
|
||||
Err(ParseError("EOF while parsing string".to_owned(), 1u, 5u)));
|
||||
|
||||
assert_eq!(from_str("\"\""), Ok(String(~"")));
|
||||
assert_eq!(from_str("\"foo\""), Ok(String(~"foo")));
|
||||
assert_eq!(from_str("\"\\\"\""), Ok(String(~"\"")));
|
||||
assert_eq!(from_str("\"\\b\""), Ok(String(~"\x08")));
|
||||
assert_eq!(from_str("\"\\n\""), Ok(String(~"\n")));
|
||||
assert_eq!(from_str("\"\\r\""), Ok(String(~"\r")));
|
||||
assert_eq!(from_str("\"\\t\""), Ok(String(~"\t")));
|
||||
assert_eq!(from_str(" \"foo\" "), Ok(String(~"foo")));
|
||||
assert_eq!(from_str("\"\\u12ab\""), Ok(String(~"\u12ab")));
|
||||
assert_eq!(from_str("\"\\uAB12\""), Ok(String(~"\uAB12")));
|
||||
assert_eq!(from_str("\"\""), Ok(String("".to_owned())));
|
||||
assert_eq!(from_str("\"foo\""), Ok(String("foo".to_owned())));
|
||||
assert_eq!(from_str("\"\\\"\""), Ok(String("\"".to_owned())));
|
||||
assert_eq!(from_str("\"\\b\""), Ok(String("\x08".to_owned())));
|
||||
assert_eq!(from_str("\"\\n\""), Ok(String("\n".to_owned())));
|
||||
assert_eq!(from_str("\"\\r\""), Ok(String("\r".to_owned())));
|
||||
assert_eq!(from_str("\"\\t\""), Ok(String("\t".to_owned())));
|
||||
assert_eq!(from_str(" \"foo\" "), Ok(String("foo".to_owned())));
|
||||
assert_eq!(from_str("\"\\u12ab\""), Ok(String("\u12ab".to_owned())));
|
||||
assert_eq!(from_str("\"\\uAB12\""), Ok(String("\uAB12".to_owned())));
|
||||
|
||||
// Non-BMP escapes. The exact error messages and positions are kind of
|
||||
// arbitrary.
|
||||
assert_eq!(from_str("\"\\ud83d\\udca9\""), Ok(String(~"\U0001F4A9")));
|
||||
assert_eq!(from_str("\"\\ud83d\\udca9\""), Ok(String("\U0001F4A9".to_owned())));
|
||||
assert!(from_str("\"\\ud83d\"").is_err());
|
||||
assert!(from_str("\"\\udca9\"").is_err());
|
||||
assert!(from_str("\"\\ud83d\\ud83d\"").is_err());
|
||||
|
@ -2185,53 +2186,53 @@ mod tests {
|
|||
fn test_decode_str() {
|
||||
let mut decoder = Decoder::new(from_str("\"\"").unwrap());
|
||||
let v: ~str = Decodable::decode(&mut decoder).unwrap();
|
||||
assert_eq!(v, ~"");
|
||||
assert_eq!(v, "".to_owned());
|
||||
|
||||
let mut decoder = Decoder::new(from_str("\"foo\"").unwrap());
|
||||
let v: ~str = Decodable::decode(&mut decoder).unwrap();
|
||||
assert_eq!(v, ~"foo");
|
||||
assert_eq!(v, "foo".to_owned());
|
||||
|
||||
let mut decoder = Decoder::new(from_str("\"\\\"\"").unwrap());
|
||||
let v: ~str = Decodable::decode(&mut decoder).unwrap();
|
||||
assert_eq!(v, ~"\"");
|
||||
assert_eq!(v, "\"".to_owned());
|
||||
|
||||
let mut decoder = Decoder::new(from_str("\"\\b\"").unwrap());
|
||||
let v: ~str = Decodable::decode(&mut decoder).unwrap();
|
||||
assert_eq!(v, ~"\x08");
|
||||
assert_eq!(v, "\x08".to_owned());
|
||||
|
||||
let mut decoder = Decoder::new(from_str("\"\\n\"").unwrap());
|
||||
let v: ~str = Decodable::decode(&mut decoder).unwrap();
|
||||
assert_eq!(v, ~"\n");
|
||||
assert_eq!(v, "\n".to_owned());
|
||||
|
||||
let mut decoder = Decoder::new(from_str("\"\\r\"").unwrap());
|
||||
let v: ~str = Decodable::decode(&mut decoder).unwrap();
|
||||
assert_eq!(v, ~"\r");
|
||||
assert_eq!(v, "\r".to_owned());
|
||||
|
||||
let mut decoder = Decoder::new(from_str("\"\\t\"").unwrap());
|
||||
let v: ~str = Decodable::decode(&mut decoder).unwrap();
|
||||
assert_eq!(v, ~"\t");
|
||||
assert_eq!(v, "\t".to_owned());
|
||||
|
||||
let mut decoder = Decoder::new(from_str("\"\\u12ab\"").unwrap());
|
||||
let v: ~str = Decodable::decode(&mut decoder).unwrap();
|
||||
assert_eq!(v, ~"\u12ab");
|
||||
assert_eq!(v, "\u12ab".to_owned());
|
||||
|
||||
let mut decoder = Decoder::new(from_str("\"\\uAB12\"").unwrap());
|
||||
let v: ~str = Decodable::decode(&mut decoder).unwrap();
|
||||
assert_eq!(v, ~"\uAB12");
|
||||
assert_eq!(v, "\uAB12".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_read_list() {
|
||||
assert_eq!(from_str("["),
|
||||
Err(ParseError(~"EOF while parsing value", 1u, 2u)));
|
||||
Err(ParseError("EOF while parsing value".to_owned(), 1u, 2u)));
|
||||
assert_eq!(from_str("[1"),
|
||||
Err(ParseError(~"EOF while parsing list", 1u, 3u)));
|
||||
Err(ParseError("EOF while parsing list".to_owned(), 1u, 3u)));
|
||||
assert_eq!(from_str("[1,"),
|
||||
Err(ParseError(~"EOF while parsing value", 1u, 4u)));
|
||||
Err(ParseError("EOF while parsing value".to_owned(), 1u, 4u)));
|
||||
assert_eq!(from_str("[1,]"),
|
||||
Err(ParseError(~"invalid syntax", 1u, 4u)));
|
||||
Err(ParseError("invalid syntax".to_owned(), 1u, 4u)));
|
||||
assert_eq!(from_str("[6 7]"),
|
||||
Err(ParseError(~"expected `,` or `]`", 1u, 4u)));
|
||||
Err(ParseError("expected `,` or `]`".to_owned(), 1u, 4u)));
|
||||
|
||||
assert_eq!(from_str("[]"), Ok(List(~[])));
|
||||
assert_eq!(from_str("[ ]"), Ok(List(~[])));
|
||||
|
@ -2276,50 +2277,50 @@ mod tests {
|
|||
#[test]
|
||||
fn test_read_object() {
|
||||
assert_eq!(from_str("{"),
|
||||
Err(ParseError(~"EOF while parsing object", 1u, 2u)));
|
||||
Err(ParseError("EOF while parsing object".to_owned(), 1u, 2u)));
|
||||
assert_eq!(from_str("{ "),
|
||||
Err(ParseError(~"EOF while parsing object", 1u, 3u)));
|
||||
Err(ParseError("EOF while parsing object".to_owned(), 1u, 3u)));
|
||||
assert_eq!(from_str("{1"),
|
||||
Err(ParseError(~"key must be a string", 1u, 2u)));
|
||||
Err(ParseError("key must be a string".to_owned(), 1u, 2u)));
|
||||
assert_eq!(from_str("{ \"a\""),
|
||||
Err(ParseError(~"EOF while parsing object", 1u, 6u)));
|
||||
Err(ParseError("EOF while parsing object".to_owned(), 1u, 6u)));
|
||||
assert_eq!(from_str("{\"a\""),
|
||||
Err(ParseError(~"EOF while parsing object", 1u, 5u)));
|
||||
Err(ParseError("EOF while parsing object".to_owned(), 1u, 5u)));
|
||||
assert_eq!(from_str("{\"a\" "),
|
||||
Err(ParseError(~"EOF while parsing object", 1u, 6u)));
|
||||
Err(ParseError("EOF while parsing object".to_owned(), 1u, 6u)));
|
||||
|
||||
assert_eq!(from_str("{\"a\" 1"),
|
||||
Err(ParseError(~"expected `:`", 1u, 6u)));
|
||||
Err(ParseError("expected `:`".to_owned(), 1u, 6u)));
|
||||
assert_eq!(from_str("{\"a\":"),
|
||||
Err(ParseError(~"EOF while parsing value", 1u, 6u)));
|
||||
Err(ParseError("EOF while parsing value".to_owned(), 1u, 6u)));
|
||||
assert_eq!(from_str("{\"a\":1"),
|
||||
Err(ParseError(~"EOF while parsing object", 1u, 7u)));
|
||||
Err(ParseError("EOF while parsing object".to_owned(), 1u, 7u)));
|
||||
assert_eq!(from_str("{\"a\":1 1"),
|
||||
Err(ParseError(~"expected `,` or `}`", 1u, 8u)));
|
||||
Err(ParseError("expected `,` or `}`".to_owned(), 1u, 8u)));
|
||||
assert_eq!(from_str("{\"a\":1,"),
|
||||
Err(ParseError(~"EOF while parsing object", 1u, 8u)));
|
||||
Err(ParseError("EOF while parsing object".to_owned(), 1u, 8u)));
|
||||
|
||||
assert_eq!(from_str("{}").unwrap(), mk_object([]));
|
||||
assert_eq!(from_str("{\"a\": 3}").unwrap(),
|
||||
mk_object([(~"a", Number(3.0))]));
|
||||
mk_object([("a".to_owned(), Number(3.0))]));
|
||||
|
||||
assert_eq!(from_str(
|
||||
"{ \"a\": null, \"b\" : true }").unwrap(),
|
||||
mk_object([
|
||||
(~"a", Null),
|
||||
(~"b", Boolean(true))]));
|
||||
("a".to_owned(), Null),
|
||||
("b".to_owned(), Boolean(true))]));
|
||||
assert_eq!(from_str("\n{ \"a\": null, \"b\" : true }\n").unwrap(),
|
||||
mk_object([
|
||||
(~"a", Null),
|
||||
(~"b", Boolean(true))]));
|
||||
("a".to_owned(), Null),
|
||||
("b".to_owned(), Boolean(true))]));
|
||||
assert_eq!(from_str(
|
||||
"{\"a\" : 1.0 ,\"b\": [ true ]}").unwrap(),
|
||||
mk_object([
|
||||
(~"a", Number(1.0)),
|
||||
(~"b", List(~[Boolean(true)]))
|
||||
("a".to_owned(), Number(1.0)),
|
||||
("b".to_owned(), List(~[Boolean(true)]))
|
||||
]));
|
||||
assert_eq!(from_str(
|
||||
~"{" +
|
||||
"{".to_owned() +
|
||||
"\"a\": 1.0, " +
|
||||
"\"b\": [" +
|
||||
"true," +
|
||||
|
@ -2328,12 +2329,12 @@ mod tests {
|
|||
"]" +
|
||||
"}").unwrap(),
|
||||
mk_object([
|
||||
(~"a", Number(1.0)),
|
||||
(~"b", List(~[
|
||||
("a".to_owned(), Number(1.0)),
|
||||
("b".to_owned(), List(~[
|
||||
Boolean(true),
|
||||
String(~"foo\nbar"),
|
||||
String("foo\nbar".to_owned()),
|
||||
mk_object([
|
||||
(~"c", mk_object([(~"d", Null)]))
|
||||
("c".to_owned(), mk_object([("d".to_owned(), Null)]))
|
||||
])
|
||||
]))
|
||||
]));
|
||||
|
@ -2341,18 +2342,18 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_decode_struct() {
|
||||
let s = ~"{
|
||||
let s = "{
|
||||
\"inner\": [
|
||||
{ \"a\": null, \"b\": 2, \"c\": [\"abc\", \"xyz\"] }
|
||||
]
|
||||
}";
|
||||
}".to_owned();
|
||||
let mut decoder = Decoder::new(from_str(s).unwrap());
|
||||
let v: Outer = Decodable::decode(&mut decoder).unwrap();
|
||||
assert_eq!(
|
||||
v,
|
||||
Outer {
|
||||
inner: ~[
|
||||
Inner { a: (), b: 2, c: ~[~"abc", ~"xyz"] }
|
||||
Inner { a: (), b: 2, c: ~["abc".to_owned(), "xyz".to_owned()] }
|
||||
]
|
||||
}
|
||||
);
|
||||
|
@ -2366,7 +2367,7 @@ mod tests {
|
|||
|
||||
let mut decoder = Decoder::new(from_str("\"jodhpurs\"").unwrap());
|
||||
let value: Option<~str> = Decodable::decode(&mut decoder).unwrap();
|
||||
assert_eq!(value, Some(~"jodhpurs"));
|
||||
assert_eq!(value, Some("jodhpurs".to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -2378,23 +2379,24 @@ mod tests {
|
|||
let s = "{\"variant\":\"Frog\",\"fields\":[\"Henry\",349]}";
|
||||
let mut decoder = Decoder::new(from_str(s).unwrap());
|
||||
let value: Animal = Decodable::decode(&mut decoder).unwrap();
|
||||
assert_eq!(value, Frog(~"Henry", 349));
|
||||
assert_eq!(value, Frog("Henry".to_owned(), 349));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_decode_map() {
|
||||
let s = ~"{\"a\": \"Dog\", \"b\": {\"variant\":\"Frog\",\"fields\":[\"Henry\", 349]}}";
|
||||
let s = "{\"a\": \"Dog\", \"b\": {\"variant\":\"Frog\",\
|
||||
\"fields\":[\"Henry\", 349]}}".to_owned();
|
||||
let mut decoder = Decoder::new(from_str(s).unwrap());
|
||||
let mut map: TreeMap<~str, Animal> = Decodable::decode(&mut decoder).unwrap();
|
||||
|
||||
assert_eq!(map.pop(&~"a"), Some(Dog));
|
||||
assert_eq!(map.pop(&~"b"), Some(Frog(~"Henry", 349)));
|
||||
assert_eq!(map.pop(&"a".to_owned()), Some(Dog));
|
||||
assert_eq!(map.pop(&"b".to_owned()), Some(Frog("Henry".to_owned(), 349)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multiline_errors() {
|
||||
assert_eq!(from_str("{\n \"foo\":\n \"bar\""),
|
||||
Err(ParseError(~"EOF while parsing object", 3u, 8u)));
|
||||
Err(ParseError("EOF while parsing object".to_owned(), 3u, 8u)));
|
||||
}
|
||||
|
||||
#[deriving(Decodable)]
|
||||
|
@ -2427,50 +2429,51 @@ mod tests {
|
|||
}
|
||||
#[test]
|
||||
fn test_decode_errors_struct() {
|
||||
check_err::<DecodeStruct>("[]", ExpectedError(~"Object", ~"[]"));
|
||||
check_err::<DecodeStruct>("[]", ExpectedError("Object".to_owned(), "[]".to_owned()));
|
||||
check_err::<DecodeStruct>("{\"x\": true, \"y\": true, \"z\": \"\", \"w\": []}",
|
||||
ExpectedError(~"Number", ~"true"));
|
||||
ExpectedError("Number".to_owned(), "true".to_owned()));
|
||||
check_err::<DecodeStruct>("{\"x\": 1, \"y\": [], \"z\": \"\", \"w\": []}",
|
||||
ExpectedError(~"Boolean", ~"[]"));
|
||||
ExpectedError("Boolean".to_owned(), "[]".to_owned()));
|
||||
check_err::<DecodeStruct>("{\"x\": 1, \"y\": true, \"z\": {}, \"w\": []}",
|
||||
ExpectedError(~"String", ~"{}"));
|
||||
ExpectedError("String".to_owned(), "{}".to_owned()));
|
||||
check_err::<DecodeStruct>("{\"x\": 1, \"y\": true, \"z\": \"\", \"w\": null}",
|
||||
ExpectedError(~"List", ~"null"));
|
||||
ExpectedError("List".to_owned(), "null".to_owned()));
|
||||
check_err::<DecodeStruct>("{\"x\": 1, \"y\": true, \"z\": \"\"}",
|
||||
MissingFieldError(~"w"));
|
||||
MissingFieldError("w".to_owned()));
|
||||
}
|
||||
#[test]
|
||||
fn test_decode_errors_enum() {
|
||||
check_err::<DecodeEnum>("{}",
|
||||
MissingFieldError(~"variant"));
|
||||
MissingFieldError("variant".to_owned()));
|
||||
check_err::<DecodeEnum>("{\"variant\": 1}",
|
||||
ExpectedError(~"String", ~"1"));
|
||||
ExpectedError("String".to_owned(), "1".to_owned()));
|
||||
check_err::<DecodeEnum>("{\"variant\": \"A\"}",
|
||||
MissingFieldError(~"fields"));
|
||||
MissingFieldError("fields".to_owned()));
|
||||
check_err::<DecodeEnum>("{\"variant\": \"A\", \"fields\": null}",
|
||||
ExpectedError(~"List", ~"null"));
|
||||
ExpectedError("List".to_owned(), "null".to_owned()));
|
||||
check_err::<DecodeEnum>("{\"variant\": \"C\", \"fields\": []}",
|
||||
UnknownVariantError(~"C"));
|
||||
UnknownVariantError("C".to_owned()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_find(){
|
||||
let json_value = from_str("{\"dog\" : \"cat\"}").unwrap();
|
||||
let found_str = json_value.find(&~"dog");
|
||||
let found_str = json_value.find(&"dog".to_owned());
|
||||
assert!(found_str.is_some() && found_str.unwrap().as_string().unwrap() == &"cat");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_find_path(){
|
||||
let json_value = from_str("{\"dog\":{\"cat\": {\"mouse\" : \"cheese\"}}}").unwrap();
|
||||
let found_str = json_value.find_path(&[&~"dog", &~"cat", &~"mouse"]);
|
||||
let found_str = json_value.find_path(&[&"dog".to_owned(),
|
||||
&"cat".to_owned(), &"mouse".to_owned()]);
|
||||
assert!(found_str.is_some() && found_str.unwrap().as_string().unwrap() == &"cheese");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_search(){
|
||||
let json_value = from_str("{\"dog\":{\"cat\": {\"mouse\" : \"cheese\"}}}").unwrap();
|
||||
let found_str = json_value.search(&~"mouse").and_then(|j| j.as_string());
|
||||
let found_str = json_value.search(&"mouse".to_owned()).and_then(|j| j.as_string());
|
||||
assert!(found_str.is_some());
|
||||
assert!(found_str.unwrap() == &"cheese");
|
||||
}
|
||||
|
|
|
@ -164,6 +164,7 @@ impl<'a> fmt::Show for &'a Any {
|
|||
mod tests {
|
||||
use prelude::*;
|
||||
use super::*;
|
||||
use str::StrSlice;
|
||||
|
||||
#[deriving(Eq, Show)]
|
||||
struct Test;
|
||||
|
@ -290,13 +291,13 @@ mod tests {
|
|||
fn test_show() {
|
||||
let a = ~8u as ~Any;
|
||||
let b = ~Test as ~Any;
|
||||
assert_eq!(format!("{}", a), ~"~Any");
|
||||
assert_eq!(format!("{}", b), ~"~Any");
|
||||
assert_eq!(format!("{}", a), "~Any".to_owned());
|
||||
assert_eq!(format!("{}", b), "~Any".to_owned());
|
||||
|
||||
let a = &8u as &Any;
|
||||
let b = &Test as &Any;
|
||||
assert_eq!(format!("{}", a), ~"&Any");
|
||||
assert_eq!(format!("{}", b), ~"&Any");
|
||||
assert_eq!(format!("{}", a), "&Any".to_owned());
|
||||
assert_eq!(format!("{}", b), "&Any".to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -487,6 +487,7 @@ mod tests {
|
|||
use str::from_char;
|
||||
use char::from_u32;
|
||||
use vec::Vec;
|
||||
use str::StrSlice;
|
||||
|
||||
macro_rules! v2ascii (
|
||||
( [$($e:expr),*]) => (&[$(Ascii{chr:$e}),*]);
|
||||
|
@ -536,14 +537,14 @@ mod tests {
|
|||
// FIXME: #5475 borrowchk error, owned vectors do not live long enough
|
||||
// if chained-from directly
|
||||
let v = ~[40u8, 32u8, 59u8]; assert_eq!(v.to_ascii(), v2ascii!([40, 32, 59]));
|
||||
let v = ~"( ;"; assert_eq!(v.to_ascii(), v2ascii!([40, 32, 59]));
|
||||
let v = "( ;".to_owned(); assert_eq!(v.to_ascii(), v2ascii!([40, 32, 59]));
|
||||
|
||||
assert_eq!("abCDef&?#".to_ascii().to_lower().into_str(), ~"abcdef&?#");
|
||||
assert_eq!("abCDef&?#".to_ascii().to_upper().into_str(), ~"ABCDEF&?#");
|
||||
assert_eq!("abCDef&?#".to_ascii().to_lower().into_str(), "abcdef&?#".to_owned());
|
||||
assert_eq!("abCDef&?#".to_ascii().to_upper().into_str(), "ABCDEF&?#".to_owned());
|
||||
|
||||
assert_eq!("".to_ascii().to_lower().into_str(), ~"");
|
||||
assert_eq!("YMCA".to_ascii().to_lower().into_str(), ~"ymca");
|
||||
assert_eq!("abcDEFxyz:.;".to_ascii().to_upper().into_str(), ~"ABCDEFXYZ:.;");
|
||||
assert_eq!("".to_ascii().to_lower().into_str(), "".to_owned());
|
||||
assert_eq!("YMCA".to_ascii().to_lower().into_str(), "ymca".to_owned());
|
||||
assert_eq!("abcDEFxyz:.;".to_ascii().to_upper().into_str(), "ABCDEFXYZ:.;".to_owned());
|
||||
|
||||
assert!("aBcDeF&?#".to_ascii().eq_ignore_case("AbCdEf&?#".to_ascii()));
|
||||
|
||||
|
@ -555,18 +556,19 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_ascii_vec_ng() {
|
||||
assert_eq!(Vec::from_slice("abCDef&?#".to_ascii().to_lower()).into_str(), ~"abcdef&?#");
|
||||
assert_eq!(Vec::from_slice("abCDef&?#".to_ascii().to_upper()).into_str(), ~"ABCDEF&?#");
|
||||
|
||||
assert_eq!(Vec::from_slice("".to_ascii().to_lower()).into_str(), ~"");
|
||||
assert_eq!(Vec::from_slice("YMCA".to_ascii().to_lower()).into_str(), ~"ymca");
|
||||
assert_eq!(Vec::from_slice("abCDef&?#".to_ascii().to_lower()).into_str(),
|
||||
"abcdef&?#".to_owned());
|
||||
assert_eq!(Vec::from_slice("abCDef&?#".to_ascii().to_upper()).into_str(),
|
||||
"ABCDEF&?#".to_owned());
|
||||
assert_eq!(Vec::from_slice("".to_ascii().to_lower()).into_str(), "".to_owned());
|
||||
assert_eq!(Vec::from_slice("YMCA".to_ascii().to_lower()).into_str(), "ymca".to_owned());
|
||||
assert_eq!(Vec::from_slice("abcDEFxyz:.;".to_ascii().to_upper()).into_str(),
|
||||
~"ABCDEFXYZ:.;");
|
||||
"ABCDEFXYZ:.;".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_owned_ascii_vec() {
|
||||
assert_eq!((~"( ;").into_ascii(), v2ascii!(~[40, 32, 59]));
|
||||
assert_eq!(("( ;".to_owned()).into_ascii(), v2ascii!(~[40, 32, 59]));
|
||||
assert_eq!((~[40u8, 32u8, 59u8]).into_ascii(), v2ascii!(~[40, 32, 59]));
|
||||
}
|
||||
|
||||
|
@ -578,8 +580,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_ascii_into_str() {
|
||||
assert_eq!(v2ascii!(~[40, 32, 59]).into_str(), ~"( ;");
|
||||
assert_eq!(vec2ascii!(40, 32, 59).into_str(), ~"( ;");
|
||||
assert_eq!(v2ascii!(~[40, 32, 59]).into_str(), "( ;".to_owned());
|
||||
assert_eq!(vec2ascii!(40, 32, 59).into_str(), "( ;".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -626,14 +628,14 @@ mod tests {
|
|||
assert_eq!((~[40u8, 32u8, 59u8]).into_ascii_opt(), Some(v2ascii!(~[40, 32, 59])));
|
||||
assert_eq!((~[127u8, 128u8, 255u8]).into_ascii_opt(), None);
|
||||
|
||||
assert_eq!((~"( ;").into_ascii_opt(), Some(v2ascii!(~[40, 32, 59])));
|
||||
assert_eq!((~"zoä华").into_ascii_opt(), None);
|
||||
assert_eq!(("( ;".to_owned()).into_ascii_opt(), Some(v2ascii!(~[40, 32, 59])));
|
||||
assert_eq!(("zoä华".to_owned()).into_ascii_opt(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_ascii_upper() {
|
||||
assert_eq!("url()URL()uRl()ürl".to_ascii_upper(), ~"URL()URL()URL()üRL");
|
||||
assert_eq!("hıKß".to_ascii_upper(), ~"HıKß");
|
||||
assert_eq!("url()URL()uRl()ürl".to_ascii_upper(), "URL()URL()URL()üRL".to_owned());
|
||||
assert_eq!("hıKß".to_ascii_upper(), "HıKß".to_owned());
|
||||
|
||||
let mut i = 0;
|
||||
while i <= 500 {
|
||||
|
@ -647,9 +649,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_to_ascii_lower() {
|
||||
assert_eq!("url()URL()uRl()Ürl".to_ascii_lower(), ~"url()url()url()Ürl");
|
||||
assert_eq!("url()URL()uRl()Ürl".to_ascii_lower(), "url()url()url()Ürl".to_owned());
|
||||
// Dotted capital I, Kelvin sign, Sharp S.
|
||||
assert_eq!("HİKß".to_ascii_lower(), ~"hİKß");
|
||||
assert_eq!("HİKß".to_ascii_lower(), "hİKß".to_owned());
|
||||
|
||||
let mut i = 0;
|
||||
while i <= 500 {
|
||||
|
@ -663,8 +665,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_into_ascii_upper() {
|
||||
assert_eq!((~"url()URL()uRl()ürl").into_ascii_upper(), ~"URL()URL()URL()üRL");
|
||||
assert_eq!((~"hıKß").into_ascii_upper(), ~"HıKß");
|
||||
assert_eq!(("url()URL()uRl()ürl".to_owned()).into_ascii_upper(),
|
||||
"URL()URL()URL()üRL".to_owned());
|
||||
assert_eq!(("hıKß".to_owned()).into_ascii_upper(), "HıKß".to_owned());
|
||||
|
||||
let mut i = 0;
|
||||
while i <= 500 {
|
||||
|
@ -678,9 +681,10 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_into_ascii_lower() {
|
||||
assert_eq!((~"url()URL()uRl()Ürl").into_ascii_lower(), ~"url()url()url()Ürl");
|
||||
assert_eq!(("url()URL()uRl()Ürl".to_owned()).into_ascii_lower(),
|
||||
"url()url()url()Ürl".to_owned());
|
||||
// Dotted capital I, Kelvin sign, Sharp S.
|
||||
assert_eq!((~"HİKß").into_ascii_lower(), ~"hİKß");
|
||||
assert_eq!(("HİKß".to_owned()).into_ascii_lower(), "hİKß".to_owned());
|
||||
|
||||
let mut i = 0;
|
||||
while i <= 500 {
|
||||
|
@ -716,12 +720,12 @@ mod tests {
|
|||
#[test]
|
||||
fn test_to_str() {
|
||||
let s = Ascii{ chr: 't' as u8 }.to_str();
|
||||
assert_eq!(s, ~"t");
|
||||
assert_eq!(s, "t".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_show() {
|
||||
let c = Ascii { chr: 't' as u8 };
|
||||
assert_eq!(format!("{}", c), ~"t");
|
||||
assert_eq!(format!("{}", c), "t".to_owned());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -199,6 +199,7 @@ impl Default for bool {
|
|||
mod tests {
|
||||
use prelude::*;
|
||||
use super::to_bit;
|
||||
use str::StrSlice;
|
||||
|
||||
#[test]
|
||||
fn test_to_bit() {
|
||||
|
@ -268,8 +269,8 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_to_str() {
|
||||
assert_eq!(false.to_str(), ~"false");
|
||||
assert_eq!(true.to_str(), ~"true");
|
||||
assert_eq!(false.to_str(), "false".to_owned());
|
||||
assert_eq!(true.to_str(), "true".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -428,6 +428,7 @@ mod tests {
|
|||
use super::*;
|
||||
use libc;
|
||||
use ptr;
|
||||
use str::StrSlice;
|
||||
|
||||
#[test]
|
||||
fn test_str_multistring_parsing() {
|
||||
|
@ -638,7 +639,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_clone_noleak() {
|
||||
fn foo(f: |c: &CString|) {
|
||||
let s = ~"test";
|
||||
let s = "test".to_owned();
|
||||
let c = s.to_c_str();
|
||||
// give the closure a non-owned CString
|
||||
let mut c_ = c.with_ref(|c| unsafe { CString::new(c, false) } );
|
||||
|
|
|
@ -108,6 +108,7 @@ pub unsafe fn copy_lifetime_vec<'a,S,T>(_ptr: &'a [S], ptr: &T) -> &'a T {
|
|||
mod tests {
|
||||
use cast::{bump_box_refcount, transmute};
|
||||
use raw;
|
||||
use str::StrSlice;
|
||||
|
||||
#[test]
|
||||
fn test_transmute_copy() {
|
||||
|
@ -117,13 +118,13 @@ mod tests {
|
|||
#[test]
|
||||
fn test_bump_managed_refcount() {
|
||||
unsafe {
|
||||
let managed = @~"box box box"; // refcount 1
|
||||
let managed = @"box box box".to_owned(); // refcount 1
|
||||
bump_box_refcount(managed); // refcount 2
|
||||
let ptr: *int = transmute(managed); // refcount 2
|
||||
let _box1: @~str = ::cast::transmute_copy(&ptr);
|
||||
let _box2: @~str = ::cast::transmute_copy(&ptr);
|
||||
assert!(*_box1 == ~"box box box");
|
||||
assert!(*_box2 == ~"box box box");
|
||||
assert!(*_box1 == "box box box".to_owned());
|
||||
assert!(*_box2 == "box box box".to_owned());
|
||||
// Will destroy _box1 and _box2. Without the bump, this would
|
||||
// use-after-free. With too many bumps, it would leak.
|
||||
}
|
||||
|
@ -142,7 +143,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_transmute2() {
|
||||
unsafe {
|
||||
assert_eq!(~[76u8], transmute(~"L"));
|
||||
assert_eq!(~[76u8], transmute("L".to_owned()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -779,19 +779,19 @@ fn test_escape_default() {
|
|||
escape_default(c, |c| { result.push_char(c); });
|
||||
return result.into_owned();
|
||||
}
|
||||
assert_eq!(string('\n'), ~"\\n");
|
||||
assert_eq!(string('\r'), ~"\\r");
|
||||
assert_eq!(string('\''), ~"\\'");
|
||||
assert_eq!(string('"'), ~"\\\"");
|
||||
assert_eq!(string(' '), ~" ");
|
||||
assert_eq!(string('a'), ~"a");
|
||||
assert_eq!(string('~'), ~"~");
|
||||
assert_eq!(string('\x00'), ~"\\x00");
|
||||
assert_eq!(string('\x1f'), ~"\\x1f");
|
||||
assert_eq!(string('\x7f'), ~"\\x7f");
|
||||
assert_eq!(string('\xff'), ~"\\xff");
|
||||
assert_eq!(string('\u011b'), ~"\\u011b");
|
||||
assert_eq!(string('\U0001d4b6'), ~"\\U0001d4b6");
|
||||
assert_eq!(string('\n'), "\\n".to_owned());
|
||||
assert_eq!(string('\r'), "\\r".to_owned());
|
||||
assert_eq!(string('\''), "\\'".to_owned());
|
||||
assert_eq!(string('"'), "\\\"".to_owned());
|
||||
assert_eq!(string(' '), " ".to_owned());
|
||||
assert_eq!(string('a'), "a".to_owned());
|
||||
assert_eq!(string('~'), "~".to_owned());
|
||||
assert_eq!(string('\x00'), "\\x00".to_owned());
|
||||
assert_eq!(string('\x1f'), "\\x1f".to_owned());
|
||||
assert_eq!(string('\x7f'), "\\x7f".to_owned());
|
||||
assert_eq!(string('\xff'), "\\xff".to_owned());
|
||||
assert_eq!(string('\u011b'), "\\u011b".to_owned());
|
||||
assert_eq!(string('\U0001d4b6'), "\\U0001d4b6".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -801,19 +801,19 @@ fn test_escape_unicode() {
|
|||
escape_unicode(c, |c| { result.push_char(c); });
|
||||
return result.into_owned();
|
||||
}
|
||||
assert_eq!(string('\x00'), ~"\\x00");
|
||||
assert_eq!(string('\n'), ~"\\x0a");
|
||||
assert_eq!(string(' '), ~"\\x20");
|
||||
assert_eq!(string('a'), ~"\\x61");
|
||||
assert_eq!(string('\u011b'), ~"\\u011b");
|
||||
assert_eq!(string('\U0001d4b6'), ~"\\U0001d4b6");
|
||||
assert_eq!(string('\x00'), "\\x00".to_owned());
|
||||
assert_eq!(string('\n'), "\\x0a".to_owned());
|
||||
assert_eq!(string(' '), "\\x20".to_owned());
|
||||
assert_eq!(string('a'), "\\x61".to_owned());
|
||||
assert_eq!(string('\u011b'), "\\u011b".to_owned());
|
||||
assert_eq!(string('\U0001d4b6'), "\\U0001d4b6".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_str() {
|
||||
use to_str::ToStr;
|
||||
let s = 't'.to_str();
|
||||
assert_eq!(s, ~"t");
|
||||
assert_eq!(s, "t".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -34,12 +34,12 @@ arguments directly while performing minimal allocations.
|
|||
Some examples of the `format!` extension are:
|
||||
|
||||
```rust
|
||||
format!("Hello"); // => ~"Hello"
|
||||
format!("Hello, {:s}!", "world"); // => ~"Hello, world!"
|
||||
format!("The number is {:d}", 1); // => ~"The number is 1"
|
||||
format!("{:?}", ~[3, 4]); // => ~"~[3, 4]"
|
||||
format!("{value}", value=4); // => ~"4"
|
||||
format!("{} {}", 1, 2); // => ~"1 2"
|
||||
format!("Hello"); // => "Hello".to_owned()
|
||||
format!("Hello, {:s}!", "world"); // => "Hello, world!".to_owned()
|
||||
format!("The number is {:d}", 1); // => "The number is 1".to_owned()
|
||||
format!("{:?}", ~[3, 4]); // => "~[3, 4]".to_owned()
|
||||
format!("{value}", value=4); // => "4".to_owned()
|
||||
format!("{} {}", 1, 2); // => "1 2".to_owned()
|
||||
```
|
||||
|
||||
From these, you can see that the first argument is a format string. It is
|
||||
|
@ -62,7 +62,7 @@ iterator over the argument. Each time a "next argument" specifier is seen, the
|
|||
iterator advances. This leads to behavior like this:
|
||||
|
||||
```rust
|
||||
format!("{1} {} {0} {}", 1, 2); // => ~"2 1 1 2"
|
||||
format!("{1} {} {0} {}", 1, 2); // => "2 1 1 2".to_owned()
|
||||
```
|
||||
|
||||
The internal iterator over the argument has not been advanced by the time the
|
||||
|
@ -89,9 +89,9 @@ identifier '=' expression
|
|||
For example, the following `format!` expressions all use named argument:
|
||||
|
||||
```rust
|
||||
format!("{argument}", argument = "test"); // => ~"test"
|
||||
format!("{name} {}", 1, name = 2); // => ~"2 1"
|
||||
format!("{a:s} {c:d} {b:?}", a="a", b=(), c=3); // => ~"a 3 ()"
|
||||
format!("{argument}", argument = "test"); // => "test".to_owned()
|
||||
format!("{name} {}", 1, name = 2); // => "2 1".to_owned()
|
||||
format!("{a:s} {c:d} {b:?}", a="a", b=(), c=3); // => "a 3 ()".to_owned()
|
||||
```
|
||||
|
||||
It is illegal to put positional parameters (those without names) after arguments
|
||||
|
@ -330,7 +330,7 @@ to reference the string value of the argument which was selected upon. As an
|
|||
example:
|
||||
|
||||
```rust
|
||||
format!("{0, select, other{#}}", "hello"); // => ~"hello"
|
||||
format!("{0, select, other{#}}", "hello"); // => "hello".to_owned()
|
||||
```
|
||||
|
||||
This example is the equivalent of `{0:s}` essentially.
|
||||
|
@ -771,7 +771,7 @@ pub unsafe fn write_unsafe(output: &mut io::Writer,
|
|||
/// use std::fmt;
|
||||
///
|
||||
/// let s = format_args!(fmt::format, "Hello, {}!", "world");
|
||||
/// assert_eq!(s, ~"Hello, world!");
|
||||
/// assert_eq!(s, "Hello, world!".to_owned());
|
||||
/// ```
|
||||
pub fn format(args: &Arguments) -> ~str {
|
||||
unsafe { format_unsafe(args.fmt, args.args) }
|
||||
|
|
|
@ -138,7 +138,7 @@ pub struct RadixFmt<T, R>(T, R);
|
|||
///
|
||||
/// ~~~
|
||||
/// use std::fmt::radix;
|
||||
/// assert_eq!(format!("{}", radix(55, 36)), ~"1j");
|
||||
/// assert_eq!(format!("{}", radix(55, 36)), "1j".to_owned());
|
||||
/// ~~~
|
||||
pub fn radix<T>(x: T, base: u8) -> RadixFmt<T, Radix> {
|
||||
RadixFmt(x, Radix::new(base))
|
||||
|
@ -192,6 +192,7 @@ mod tests {
|
|||
use fmt::radix;
|
||||
use super::{Binary, Octal, Decimal, LowerHex, UpperHex};
|
||||
use super::{GenericRadix, Radix};
|
||||
use str::StrSlice;
|
||||
|
||||
#[test]
|
||||
fn test_radix_base() {
|
||||
|
@ -243,143 +244,143 @@ mod tests {
|
|||
// Formatting integers should select the right implementation based off
|
||||
// the type of the argument. Also, hex/octal/binary should be defined
|
||||
// for integers, but they shouldn't emit the negative sign.
|
||||
assert_eq!(format!("{}", 1i), ~"1");
|
||||
assert_eq!(format!("{}", 1i8), ~"1");
|
||||
assert_eq!(format!("{}", 1i16), ~"1");
|
||||
assert_eq!(format!("{}", 1i32), ~"1");
|
||||
assert_eq!(format!("{}", 1i64), ~"1");
|
||||
assert_eq!(format!("{:d}", -1i), ~"-1");
|
||||
assert_eq!(format!("{:d}", -1i8), ~"-1");
|
||||
assert_eq!(format!("{:d}", -1i16), ~"-1");
|
||||
assert_eq!(format!("{:d}", -1i32), ~"-1");
|
||||
assert_eq!(format!("{:d}", -1i64), ~"-1");
|
||||
assert_eq!(format!("{:t}", 1i), ~"1");
|
||||
assert_eq!(format!("{:t}", 1i8), ~"1");
|
||||
assert_eq!(format!("{:t}", 1i16), ~"1");
|
||||
assert_eq!(format!("{:t}", 1i32), ~"1");
|
||||
assert_eq!(format!("{:t}", 1i64), ~"1");
|
||||
assert_eq!(format!("{:x}", 1i), ~"1");
|
||||
assert_eq!(format!("{:x}", 1i8), ~"1");
|
||||
assert_eq!(format!("{:x}", 1i16), ~"1");
|
||||
assert_eq!(format!("{:x}", 1i32), ~"1");
|
||||
assert_eq!(format!("{:x}", 1i64), ~"1");
|
||||
assert_eq!(format!("{:X}", 1i), ~"1");
|
||||
assert_eq!(format!("{:X}", 1i8), ~"1");
|
||||
assert_eq!(format!("{:X}", 1i16), ~"1");
|
||||
assert_eq!(format!("{:X}", 1i32), ~"1");
|
||||
assert_eq!(format!("{:X}", 1i64), ~"1");
|
||||
assert_eq!(format!("{:o}", 1i), ~"1");
|
||||
assert_eq!(format!("{:o}", 1i8), ~"1");
|
||||
assert_eq!(format!("{:o}", 1i16), ~"1");
|
||||
assert_eq!(format!("{:o}", 1i32), ~"1");
|
||||
assert_eq!(format!("{:o}", 1i64), ~"1");
|
||||
assert_eq!(format!("{}", 1i), "1".to_owned());
|
||||
assert_eq!(format!("{}", 1i8), "1".to_owned());
|
||||
assert_eq!(format!("{}", 1i16), "1".to_owned());
|
||||
assert_eq!(format!("{}", 1i32), "1".to_owned());
|
||||
assert_eq!(format!("{}", 1i64), "1".to_owned());
|
||||
assert_eq!(format!("{:d}", -1i), "-1".to_owned());
|
||||
assert_eq!(format!("{:d}", -1i8), "-1".to_owned());
|
||||
assert_eq!(format!("{:d}", -1i16), "-1".to_owned());
|
||||
assert_eq!(format!("{:d}", -1i32), "-1".to_owned());
|
||||
assert_eq!(format!("{:d}", -1i64), "-1".to_owned());
|
||||
assert_eq!(format!("{:t}", 1i), "1".to_owned());
|
||||
assert_eq!(format!("{:t}", 1i8), "1".to_owned());
|
||||
assert_eq!(format!("{:t}", 1i16), "1".to_owned());
|
||||
assert_eq!(format!("{:t}", 1i32), "1".to_owned());
|
||||
assert_eq!(format!("{:t}", 1i64), "1".to_owned());
|
||||
assert_eq!(format!("{:x}", 1i), "1".to_owned());
|
||||
assert_eq!(format!("{:x}", 1i8), "1".to_owned());
|
||||
assert_eq!(format!("{:x}", 1i16), "1".to_owned());
|
||||
assert_eq!(format!("{:x}", 1i32), "1".to_owned());
|
||||
assert_eq!(format!("{:x}", 1i64), "1".to_owned());
|
||||
assert_eq!(format!("{:X}", 1i), "1".to_owned());
|
||||
assert_eq!(format!("{:X}", 1i8), "1".to_owned());
|
||||
assert_eq!(format!("{:X}", 1i16), "1".to_owned());
|
||||
assert_eq!(format!("{:X}", 1i32), "1".to_owned());
|
||||
assert_eq!(format!("{:X}", 1i64), "1".to_owned());
|
||||
assert_eq!(format!("{:o}", 1i), "1".to_owned());
|
||||
assert_eq!(format!("{:o}", 1i8), "1".to_owned());
|
||||
assert_eq!(format!("{:o}", 1i16), "1".to_owned());
|
||||
assert_eq!(format!("{:o}", 1i32), "1".to_owned());
|
||||
assert_eq!(format!("{:o}", 1i64), "1".to_owned());
|
||||
|
||||
assert_eq!(format!("{}", 1u), ~"1");
|
||||
assert_eq!(format!("{}", 1u8), ~"1");
|
||||
assert_eq!(format!("{}", 1u16), ~"1");
|
||||
assert_eq!(format!("{}", 1u32), ~"1");
|
||||
assert_eq!(format!("{}", 1u64), ~"1");
|
||||
assert_eq!(format!("{:u}", 1u), ~"1");
|
||||
assert_eq!(format!("{:u}", 1u8), ~"1");
|
||||
assert_eq!(format!("{:u}", 1u16), ~"1");
|
||||
assert_eq!(format!("{:u}", 1u32), ~"1");
|
||||
assert_eq!(format!("{:u}", 1u64), ~"1");
|
||||
assert_eq!(format!("{:t}", 1u), ~"1");
|
||||
assert_eq!(format!("{:t}", 1u8), ~"1");
|
||||
assert_eq!(format!("{:t}", 1u16), ~"1");
|
||||
assert_eq!(format!("{:t}", 1u32), ~"1");
|
||||
assert_eq!(format!("{:t}", 1u64), ~"1");
|
||||
assert_eq!(format!("{:x}", 1u), ~"1");
|
||||
assert_eq!(format!("{:x}", 1u8), ~"1");
|
||||
assert_eq!(format!("{:x}", 1u16), ~"1");
|
||||
assert_eq!(format!("{:x}", 1u32), ~"1");
|
||||
assert_eq!(format!("{:x}", 1u64), ~"1");
|
||||
assert_eq!(format!("{:X}", 1u), ~"1");
|
||||
assert_eq!(format!("{:X}", 1u8), ~"1");
|
||||
assert_eq!(format!("{:X}", 1u16), ~"1");
|
||||
assert_eq!(format!("{:X}", 1u32), ~"1");
|
||||
assert_eq!(format!("{:X}", 1u64), ~"1");
|
||||
assert_eq!(format!("{:o}", 1u), ~"1");
|
||||
assert_eq!(format!("{:o}", 1u8), ~"1");
|
||||
assert_eq!(format!("{:o}", 1u16), ~"1");
|
||||
assert_eq!(format!("{:o}", 1u32), ~"1");
|
||||
assert_eq!(format!("{:o}", 1u64), ~"1");
|
||||
assert_eq!(format!("{}", 1u), "1".to_owned());
|
||||
assert_eq!(format!("{}", 1u8), "1".to_owned());
|
||||
assert_eq!(format!("{}", 1u16), "1".to_owned());
|
||||
assert_eq!(format!("{}", 1u32), "1".to_owned());
|
||||
assert_eq!(format!("{}", 1u64), "1".to_owned());
|
||||
assert_eq!(format!("{:u}", 1u), "1".to_owned());
|
||||
assert_eq!(format!("{:u}", 1u8), "1".to_owned());
|
||||
assert_eq!(format!("{:u}", 1u16), "1".to_owned());
|
||||
assert_eq!(format!("{:u}", 1u32), "1".to_owned());
|
||||
assert_eq!(format!("{:u}", 1u64), "1".to_owned());
|
||||
assert_eq!(format!("{:t}", 1u), "1".to_owned());
|
||||
assert_eq!(format!("{:t}", 1u8), "1".to_owned());
|
||||
assert_eq!(format!("{:t}", 1u16), "1".to_owned());
|
||||
assert_eq!(format!("{:t}", 1u32), "1".to_owned());
|
||||
assert_eq!(format!("{:t}", 1u64), "1".to_owned());
|
||||
assert_eq!(format!("{:x}", 1u), "1".to_owned());
|
||||
assert_eq!(format!("{:x}", 1u8), "1".to_owned());
|
||||
assert_eq!(format!("{:x}", 1u16), "1".to_owned());
|
||||
assert_eq!(format!("{:x}", 1u32), "1".to_owned());
|
||||
assert_eq!(format!("{:x}", 1u64), "1".to_owned());
|
||||
assert_eq!(format!("{:X}", 1u), "1".to_owned());
|
||||
assert_eq!(format!("{:X}", 1u8), "1".to_owned());
|
||||
assert_eq!(format!("{:X}", 1u16), "1".to_owned());
|
||||
assert_eq!(format!("{:X}", 1u32), "1".to_owned());
|
||||
assert_eq!(format!("{:X}", 1u64), "1".to_owned());
|
||||
assert_eq!(format!("{:o}", 1u), "1".to_owned());
|
||||
assert_eq!(format!("{:o}", 1u8), "1".to_owned());
|
||||
assert_eq!(format!("{:o}", 1u16), "1".to_owned());
|
||||
assert_eq!(format!("{:o}", 1u32), "1".to_owned());
|
||||
assert_eq!(format!("{:o}", 1u64), "1".to_owned());
|
||||
|
||||
// Test a larger number
|
||||
assert_eq!(format!("{:t}", 55), ~"110111");
|
||||
assert_eq!(format!("{:o}", 55), ~"67");
|
||||
assert_eq!(format!("{:d}", 55), ~"55");
|
||||
assert_eq!(format!("{:x}", 55), ~"37");
|
||||
assert_eq!(format!("{:X}", 55), ~"37");
|
||||
assert_eq!(format!("{:t}", 55), "110111".to_owned());
|
||||
assert_eq!(format!("{:o}", 55), "67".to_owned());
|
||||
assert_eq!(format!("{:d}", 55), "55".to_owned());
|
||||
assert_eq!(format!("{:x}", 55), "37".to_owned());
|
||||
assert_eq!(format!("{:X}", 55), "37".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_int_zero() {
|
||||
assert_eq!(format!("{}", 0i), ~"0");
|
||||
assert_eq!(format!("{:d}", 0i), ~"0");
|
||||
assert_eq!(format!("{:t}", 0i), ~"0");
|
||||
assert_eq!(format!("{:o}", 0i), ~"0");
|
||||
assert_eq!(format!("{:x}", 0i), ~"0");
|
||||
assert_eq!(format!("{:X}", 0i), ~"0");
|
||||
assert_eq!(format!("{}", 0i), "0".to_owned());
|
||||
assert_eq!(format!("{:d}", 0i), "0".to_owned());
|
||||
assert_eq!(format!("{:t}", 0i), "0".to_owned());
|
||||
assert_eq!(format!("{:o}", 0i), "0".to_owned());
|
||||
assert_eq!(format!("{:x}", 0i), "0".to_owned());
|
||||
assert_eq!(format!("{:X}", 0i), "0".to_owned());
|
||||
|
||||
assert_eq!(format!("{}", 0u), ~"0");
|
||||
assert_eq!(format!("{:u}", 0u), ~"0");
|
||||
assert_eq!(format!("{:t}", 0u), ~"0");
|
||||
assert_eq!(format!("{:o}", 0u), ~"0");
|
||||
assert_eq!(format!("{:x}", 0u), ~"0");
|
||||
assert_eq!(format!("{:X}", 0u), ~"0");
|
||||
assert_eq!(format!("{}", 0u), "0".to_owned());
|
||||
assert_eq!(format!("{:u}", 0u), "0".to_owned());
|
||||
assert_eq!(format!("{:t}", 0u), "0".to_owned());
|
||||
assert_eq!(format!("{:o}", 0u), "0".to_owned());
|
||||
assert_eq!(format!("{:x}", 0u), "0".to_owned());
|
||||
assert_eq!(format!("{:X}", 0u), "0".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_int_flags() {
|
||||
assert_eq!(format!("{:3d}", 1), ~" 1");
|
||||
assert_eq!(format!("{:>3d}", 1), ~" 1");
|
||||
assert_eq!(format!("{:>+3d}", 1), ~" +1");
|
||||
assert_eq!(format!("{:<3d}", 1), ~"1 ");
|
||||
assert_eq!(format!("{:#d}", 1), ~"1");
|
||||
assert_eq!(format!("{:#x}", 10), ~"0xa");
|
||||
assert_eq!(format!("{:#X}", 10), ~"0xA");
|
||||
assert_eq!(format!("{:#5x}", 10), ~" 0xa");
|
||||
assert_eq!(format!("{:#o}", 10), ~"0o12");
|
||||
assert_eq!(format!("{:08x}", 10), ~"0000000a");
|
||||
assert_eq!(format!("{:8x}", 10), ~" a");
|
||||
assert_eq!(format!("{:<8x}", 10), ~"a ");
|
||||
assert_eq!(format!("{:>8x}", 10), ~" a");
|
||||
assert_eq!(format!("{:#08x}", 10), ~"0x00000a");
|
||||
assert_eq!(format!("{:08d}", -10), ~"-0000010");
|
||||
assert_eq!(format!("{:x}", -1u8), ~"ff");
|
||||
assert_eq!(format!("{:X}", -1u8), ~"FF");
|
||||
assert_eq!(format!("{:t}", -1u8), ~"11111111");
|
||||
assert_eq!(format!("{:o}", -1u8), ~"377");
|
||||
assert_eq!(format!("{:#x}", -1u8), ~"0xff");
|
||||
assert_eq!(format!("{:#X}", -1u8), ~"0xFF");
|
||||
assert_eq!(format!("{:#t}", -1u8), ~"0b11111111");
|
||||
assert_eq!(format!("{:#o}", -1u8), ~"0o377");
|
||||
assert_eq!(format!("{:3d}", 1), " 1".to_owned());
|
||||
assert_eq!(format!("{:>3d}", 1), " 1".to_owned());
|
||||
assert_eq!(format!("{:>+3d}", 1), " +1".to_owned());
|
||||
assert_eq!(format!("{:<3d}", 1), "1 ".to_owned());
|
||||
assert_eq!(format!("{:#d}", 1), "1".to_owned());
|
||||
assert_eq!(format!("{:#x}", 10), "0xa".to_owned());
|
||||
assert_eq!(format!("{:#X}", 10), "0xA".to_owned());
|
||||
assert_eq!(format!("{:#5x}", 10), " 0xa".to_owned());
|
||||
assert_eq!(format!("{:#o}", 10), "0o12".to_owned());
|
||||
assert_eq!(format!("{:08x}", 10), "0000000a".to_owned());
|
||||
assert_eq!(format!("{:8x}", 10), " a".to_owned());
|
||||
assert_eq!(format!("{:<8x}", 10), "a ".to_owned());
|
||||
assert_eq!(format!("{:>8x}", 10), " a".to_owned());
|
||||
assert_eq!(format!("{:#08x}", 10), "0x00000a".to_owned());
|
||||
assert_eq!(format!("{:08d}", -10), "-0000010".to_owned());
|
||||
assert_eq!(format!("{:x}", -1u8), "ff".to_owned());
|
||||
assert_eq!(format!("{:X}", -1u8), "FF".to_owned());
|
||||
assert_eq!(format!("{:t}", -1u8), "11111111".to_owned());
|
||||
assert_eq!(format!("{:o}", -1u8), "377".to_owned());
|
||||
assert_eq!(format!("{:#x}", -1u8), "0xff".to_owned());
|
||||
assert_eq!(format!("{:#X}", -1u8), "0xFF".to_owned());
|
||||
assert_eq!(format!("{:#t}", -1u8), "0b11111111".to_owned());
|
||||
assert_eq!(format!("{:#o}", -1u8), "0o377".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_int_sign_padding() {
|
||||
assert_eq!(format!("{:+5d}", 1), ~" +1");
|
||||
assert_eq!(format!("{:+5d}", -1), ~" -1");
|
||||
assert_eq!(format!("{:05d}", 1), ~"00001");
|
||||
assert_eq!(format!("{:05d}", -1), ~"-0001");
|
||||
assert_eq!(format!("{:+05d}", 1), ~"+0001");
|
||||
assert_eq!(format!("{:+05d}", -1), ~"-0001");
|
||||
assert_eq!(format!("{:+5d}", 1), " +1".to_owned());
|
||||
assert_eq!(format!("{:+5d}", -1), " -1".to_owned());
|
||||
assert_eq!(format!("{:05d}", 1), "00001".to_owned());
|
||||
assert_eq!(format!("{:05d}", -1), "-0001".to_owned());
|
||||
assert_eq!(format!("{:+05d}", 1), "+0001".to_owned());
|
||||
assert_eq!(format!("{:+05d}", -1), "-0001".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_int_twos_complement() {
|
||||
use {i8, i16, i32, i64};
|
||||
assert_eq!(format!("{}", i8::MIN), ~"-128");
|
||||
assert_eq!(format!("{}", i16::MIN), ~"-32768");
|
||||
assert_eq!(format!("{}", i32::MIN), ~"-2147483648");
|
||||
assert_eq!(format!("{}", i64::MIN), ~"-9223372036854775808");
|
||||
assert_eq!(format!("{}", i8::MIN), "-128".to_owned());
|
||||
assert_eq!(format!("{}", i16::MIN), "-32768".to_owned());
|
||||
assert_eq!(format!("{}", i32::MIN), "-2147483648".to_owned());
|
||||
assert_eq!(format!("{}", i64::MIN), "-9223372036854775808".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_radix() {
|
||||
assert_eq!(format!("{:04}", radix(3, 2)), ~"0011");
|
||||
assert_eq!(format!("{}", radix(55, 36)), ~"1j");
|
||||
assert_eq!(format!("{:04}", radix(3, 2)), "0011".to_owned());
|
||||
assert_eq!(format!("{}", radix(55, 36)), "1j".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -27,8 +27,8 @@
|
|||
* phone: u64,
|
||||
* }
|
||||
*
|
||||
* let person1 = Person { id: 5, name: ~"Janet", phone: 555_666_7777 };
|
||||
* let person2 = Person { id: 5, name: ~"Bob", phone: 555_666_7777 };
|
||||
* let person1 = Person { id: 5, name: "Janet".to_owned(), phone: 555_666_7777 };
|
||||
* let person2 = Person { id: 5, name: "Bob".to_owned(), phone: 555_666_7777 };
|
||||
*
|
||||
* assert!(hash::hash(&person1) != hash::hash(&person2));
|
||||
* ```
|
||||
|
@ -54,8 +54,8 @@
|
|||
* }
|
||||
* }
|
||||
*
|
||||
* let person1 = Person { id: 5, name: ~"Janet", phone: 555_666_7777 };
|
||||
* let person2 = Person { id: 5, name: ~"Bob", phone: 555_666_7777 };
|
||||
* let person1 = Person { id: 5, name: "Janet".to_owned(), phone: 555_666_7777 };
|
||||
* let person2 = Person { id: 5, name: "Bob".to_owned(), phone: 555_666_7777 };
|
||||
*
|
||||
* assert!(hash::hash(&person1) == hash::hash(&person2));
|
||||
* ```
|
||||
|
|
|
@ -361,6 +361,10 @@ mod tests {
|
|||
extern crate test;
|
||||
use prelude::*;
|
||||
use num::ToStrRadix;
|
||||
use option::{Some, None};
|
||||
use str::{Str,StrSlice};
|
||||
use strbuf::StrBuf;
|
||||
use slice::{Vector, ImmutableVector, OwnedVector};
|
||||
use self::test::Bencher;
|
||||
|
||||
use super::super::Hash;
|
||||
|
@ -640,7 +644,7 @@ officia deserunt mollit anim id est laborum.";
|
|||
let compound = Compound {
|
||||
x: 1,
|
||||
y: 2,
|
||||
z: ~"foobarbaz",
|
||||
z: "foobarbaz".to_owned(),
|
||||
};
|
||||
b.iter(|| {
|
||||
assert_eq!(hash(&compound), 15783192367317361799);
|
||||
|
|
|
@ -372,6 +372,7 @@ mod test {
|
|||
use super::*;
|
||||
use super::super::mem::{MemReader, MemWriter, BufReader};
|
||||
use self::test::Bencher;
|
||||
use str::StrSlice;
|
||||
|
||||
/// A type, free to create, primarily intended for benchmarking creation of
|
||||
/// wrappers that, just for construction, don't need a Reader/Writer that
|
||||
|
@ -535,9 +536,9 @@ mod test {
|
|||
fn test_read_line() {
|
||||
let in_buf = MemReader::new(Vec::from_slice(bytes!("a\nb\nc")));
|
||||
let mut reader = BufferedReader::with_capacity(2, in_buf);
|
||||
assert_eq!(reader.read_line(), Ok(~"a\n"));
|
||||
assert_eq!(reader.read_line(), Ok(~"b\n"));
|
||||
assert_eq!(reader.read_line(), Ok(~"c"));
|
||||
assert_eq!(reader.read_line(), Ok("a\n".to_owned()));
|
||||
assert_eq!(reader.read_line(), Ok("b\n".to_owned()));
|
||||
assert_eq!(reader.read_line(), Ok("c".to_owned()));
|
||||
assert!(reader.read_line().is_err());
|
||||
}
|
||||
|
||||
|
@ -546,9 +547,9 @@ mod test {
|
|||
let in_buf = MemReader::new(Vec::from_slice(bytes!("a\nb\nc")));
|
||||
let mut reader = BufferedReader::with_capacity(2, in_buf);
|
||||
let mut it = reader.lines();
|
||||
assert_eq!(it.next(), Some(Ok(~"a\n")));
|
||||
assert_eq!(it.next(), Some(Ok(~"b\n")));
|
||||
assert_eq!(it.next(), Some(Ok(~"c")));
|
||||
assert_eq!(it.next(), Some(Ok("a\n".to_owned())));
|
||||
assert_eq!(it.next(), Some(Ok("b\n".to_owned())));
|
||||
assert_eq!(it.next(), Some(Ok("c".to_owned())));
|
||||
assert_eq!(it.next(), None);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ use io;
|
|||
use option::{None, Option, Some};
|
||||
use result::{Ok, Err};
|
||||
use super::{Reader, Writer, IoResult};
|
||||
use str::StrSlice;
|
||||
use slice::{bytes, CloneableVector, MutableVector, ImmutableVector};
|
||||
|
||||
/// Allows reading from a rx.
|
||||
|
|
|
@ -711,6 +711,7 @@ mod test {
|
|||
use path::Path;
|
||||
use io;
|
||||
use ops::Drop;
|
||||
use str::StrSlice;
|
||||
|
||||
macro_rules! check( ($e:expr) => (
|
||||
match $e {
|
||||
|
|
|
@ -339,6 +339,7 @@ mod test {
|
|||
use super::*;
|
||||
use io::*;
|
||||
use io;
|
||||
use str::StrSlice;
|
||||
|
||||
#[test]
|
||||
fn test_mem_writer() {
|
||||
|
@ -496,7 +497,7 @@ mod test {
|
|||
writer.write_line("testing").unwrap();
|
||||
writer.write_str("testing").unwrap();
|
||||
let mut r = BufReader::new(writer.get_ref());
|
||||
assert_eq!(r.read_to_str().unwrap(), ~"testingtesting\ntesting");
|
||||
assert_eq!(r.read_to_str().unwrap(), "testingtesting\ntesting".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -506,7 +507,7 @@ mod test {
|
|||
writer.write_char('\n').unwrap();
|
||||
writer.write_char('ệ').unwrap();
|
||||
let mut r = BufReader::new(writer.get_ref());
|
||||
assert_eq!(r.read_to_str().unwrap(), ~"a\nệ");
|
||||
assert_eq!(r.read_to_str().unwrap(), "a\nệ".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -1188,7 +1188,7 @@ pub trait Buffer: Reader {
|
|||
/// use std::io;
|
||||
///
|
||||
/// let mut reader = io::stdin();
|
||||
/// let input = reader.read_line().ok().unwrap_or(~"nothing");
|
||||
/// let input = reader.read_line().ok().unwrap_or("nothing".to_owned());
|
||||
/// ```
|
||||
///
|
||||
/// # Error
|
||||
|
|
|
@ -445,7 +445,8 @@ mod test {
|
|||
#[test]
|
||||
fn ipv6_addr_to_str() {
|
||||
let a1 = Ipv6Addr(0, 0, 0, 0, 0, 0xffff, 0xc000, 0x280);
|
||||
assert!(a1.to_str() == ~"::ffff:192.0.2.128" || a1.to_str() == ~"::FFFF:192.0.2.128");
|
||||
assert_eq!(Ipv6Addr(8, 9, 10, 11, 12, 13, 14, 15).to_str(), ~"8:9:a:b:c:d:e:f");
|
||||
assert!(a1.to_str() == "::ffff:192.0.2.128".to_owned() ||
|
||||
a1.to_str() == "::FFFF:192.0.2.128".to_owned());
|
||||
assert_eq!(Ipv6Addr(8, 9, 10, 11, 12, 13, 14, 15).to_str(), "8:9:a:b:c:d:e:f".to_owned());
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue