]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/istr.rs
auto merge of #13600 : brandonw/rust/master, r=brson
[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::strbuf::StrBuf;
12
13 fn test_stack_assign() {
14     let s: ~str = ~"a";
15     println!("{}", s.clone());
16     let t: ~str = ~"a";
17     assert!(s == t);
18     let u: ~str = ~"b";
19     assert!((s != u));
20 }
21
22 fn test_heap_lit() { ~"a big string"; }
23
24 fn test_heap_assign() {
25     let s: ~str = ~"a big ol' string";
26     let t: ~str = ~"a big ol' string";
27     assert!(s == t);
28     let u: ~str = ~"a bad ol' string";
29     assert!((s != u));
30 }
31
32 fn test_heap_log() { let s = ~"a big ol' string"; println!("{}", s); }
33
34 fn test_stack_add() {
35     assert_eq!(~"a" + "b", ~"ab");
36     let s: ~str = ~"a";
37     assert_eq!(s + s, ~"aa");
38     assert_eq!(~"" + "", ~"");
39 }
40
41 fn test_stack_heap_add() { assert!((~"a" + "bracadabra" == ~"abracadabra")); }
42
43 fn test_heap_add() {
44     assert_eq!(~"this should" + " totally work", ~"this should totally work");
45 }
46
47 fn test_append() {
48     let mut s = StrBuf::new();
49     s.push_str("a");
50     assert_eq!(s.as_slice(), "a");
51
52     let mut s = StrBuf::from_str("a");
53     s.push_str("b");
54     println!("{}", s.clone());
55     assert_eq!(s.as_slice(), "ab");
56
57     let mut s = StrBuf::from_str("c");
58     s.push_str("offee");
59     assert!(s.as_slice() == "coffee");
60
61     s.push_str("&tea");
62     assert!(s.as_slice() == "coffee&tea");
63 }
64
65 pub fn main() {
66     test_stack_assign();
67     test_heap_lit();
68     test_heap_assign();
69     test_heap_log();
70     test_stack_add();
71     test_stack_heap_add();
72     test_heap_add();
73     test_append();
74 }