]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/istr.rs
New upstream version 1.19.0+dfsg1
[rustc.git] / src / test / run-pass / istr.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![feature(collections)]
12
13 use std::string::String;
14
15 fn test_stack_assign() {
16 let s: String = "a".to_string();
17 println!("{}", s.clone());
18 let t: String = "a".to_string();
19 assert_eq!(s, t);
20 let u: String = "b".to_string();
21 assert!((s != u));
22 }
23
24 fn test_heap_lit() { "a big string".to_string(); }
25
26 fn test_heap_assign() {
27 let s: String = "a big ol' string".to_string();
28 let t: String = "a big ol' string".to_string();
29 assert_eq!(s, t);
30 let u: String = "a bad ol' string".to_string();
31 assert!((s != u));
32 }
33
34 fn test_heap_log() {
35 let s = "a big ol' string".to_string();
36 println!("{}", s);
37 }
38
39 fn test_append() {
40 let mut s = String::new();
41 s.push_str("a");
42 assert_eq!(s, "a");
43
44 let mut s = String::from("a");
45 s.push_str("b");
46 println!("{}", s.clone());
47 assert_eq!(s, "ab");
48
49 let mut s = String::from("c");
50 s.push_str("offee");
51 assert_eq!(s, "coffee");
52
53 s.push_str("&tea");
54 assert_eq!(s, "coffee&tea");
55 }
56
57 pub fn main() {
58 test_stack_assign();
59 test_heap_lit();
60 test_heap_assign();
61 test_heap_log();
62 test_append();
63 }