]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/istr.rs
auto merge of #19648 : mquandalle/rust/patch-1, r=alexcrichton
[rust.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 use std::string::String;
12
13 fn test_stack_assign() {
14     let s: String = "a".to_string();
15     println!("{}", s.clone());
16     let t: String = "a".to_string();
17     assert!(s == t);
18     let u: String = "b".to_string();
19     assert!((s != u));
20 }
21
22 fn test_heap_lit() { "a big string".to_string(); }
23
24 fn test_heap_assign() {
25     let s: String = "a big ol' string".to_string();
26     let t: String = "a big ol' string".to_string();
27     assert!(s == t);
28     let u: String = "a bad ol' string".to_string();
29     assert!((s != u));
30 }
31
32 fn test_heap_log() {
33     let s = "a big ol' string".to_string();
34     println!("{}", s);
35 }
36
37 fn test_append() {
38     let mut s = String::new();
39     s.push_str("a");
40     assert_eq!(s.as_slice(), "a");
41
42     let mut s = String::from_str("a");
43     s.push_str("b");
44     println!("{}", s.clone());
45     assert_eq!(s.as_slice(), "ab");
46
47     let mut s = String::from_str("c");
48     s.push_str("offee");
49     assert!(s.as_slice() == "coffee");
50
51     s.push_str("&tea");
52     assert!(s.as_slice() == "coffee&tea");
53 }
54
55 pub fn main() {
56     test_stack_assign();
57     test_heap_lit();
58     test_heap_assign();
59     test_heap_log();
60     test_append();
61 }