2012-12-11 01:32:48 +00:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2011-08-22 20:53:39 +00:00
|
|
|
fn test_stack_assign() {
|
2012-07-14 05:57:48 +00:00
|
|
|
let s: ~str = ~"a";
|
2013-10-21 20:08:31 +00:00
|
|
|
info!("{}", s.clone());
|
2012-07-14 05:57:48 +00:00
|
|
|
let t: ~str = ~"a";
|
2013-05-19 02:02:45 +00:00
|
|
|
assert!(s == t);
|
2012-07-14 05:57:48 +00:00
|
|
|
let u: ~str = ~"b";
|
2013-03-29 01:39:09 +00:00
|
|
|
assert!((s != u));
|
2011-08-22 20:53:39 +00:00
|
|
|
}
|
|
|
|
|
2012-07-14 05:57:48 +00:00
|
|
|
fn test_heap_lit() { ~"a big string"; }
|
2011-08-22 20:53:39 +00:00
|
|
|
|
2011-08-22 21:33:31 +00:00
|
|
|
fn test_heap_assign() {
|
2012-07-14 05:57:48 +00:00
|
|
|
let s: ~str = ~"a big ol' string";
|
|
|
|
let t: ~str = ~"a big ol' string";
|
2013-05-19 02:02:45 +00:00
|
|
|
assert!(s == t);
|
2012-07-14 05:57:48 +00:00
|
|
|
let u: ~str = ~"a bad ol' string";
|
2013-03-29 01:39:09 +00:00
|
|
|
assert!((s != u));
|
2011-08-22 21:33:31 +00:00
|
|
|
}
|
|
|
|
|
2013-10-21 20:08:31 +00:00
|
|
|
fn test_heap_log() { let s = ~"a big ol' string"; info!("{}", s); }
|
2011-08-22 23:12:42 +00:00
|
|
|
|
2011-08-22 23:39:18 +00:00
|
|
|
fn test_stack_add() {
|
2013-08-17 15:37:42 +00:00
|
|
|
assert_eq!(~"a" + "b", ~"ab");
|
2012-07-14 05:57:48 +00:00
|
|
|
let s: ~str = ~"a";
|
2013-05-19 02:02:45 +00:00
|
|
|
assert_eq!(s + s, ~"aa");
|
2013-08-17 15:37:42 +00:00
|
|
|
assert_eq!(~"" + "", ~"");
|
2011-08-22 23:39:18 +00:00
|
|
|
}
|
|
|
|
|
2013-08-17 15:37:42 +00:00
|
|
|
fn test_stack_heap_add() { assert!((~"a" + "bracadabra" == ~"abracadabra")); }
|
2011-08-22 23:39:18 +00:00
|
|
|
|
|
|
|
fn test_heap_add() {
|
2013-08-17 15:37:42 +00:00
|
|
|
assert_eq!(~"this should" + " totally work", ~"this should totally work");
|
2011-08-22 23:39:18 +00:00
|
|
|
}
|
|
|
|
|
2011-08-23 00:35:38 +00:00
|
|
|
fn test_append() {
|
2012-07-14 05:57:48 +00:00
|
|
|
let mut s = ~"";
|
2013-08-17 15:37:42 +00:00
|
|
|
s.push_str("a");
|
2013-05-19 02:02:45 +00:00
|
|
|
assert_eq!(s, ~"a");
|
2011-08-23 00:35:38 +00:00
|
|
|
|
2012-07-14 05:57:48 +00:00
|
|
|
let mut s = ~"a";
|
2013-08-17 15:37:42 +00:00
|
|
|
s.push_str("b");
|
2013-10-21 20:08:31 +00:00
|
|
|
info!("{}", s.clone());
|
2013-05-19 02:02:45 +00:00
|
|
|
assert_eq!(s, ~"ab");
|
2011-08-23 00:35:38 +00:00
|
|
|
|
2012-07-14 05:57:48 +00:00
|
|
|
let mut s = ~"c";
|
2013-08-17 15:37:42 +00:00
|
|
|
s.push_str("offee");
|
2013-05-19 02:02:45 +00:00
|
|
|
assert!(s == ~"coffee");
|
2011-08-23 00:35:38 +00:00
|
|
|
|
2013-08-17 15:37:42 +00:00
|
|
|
s.push_str("&tea");
|
2013-05-19 02:02:45 +00:00
|
|
|
assert!(s == ~"coffee&tea");
|
2011-08-23 00:35:38 +00:00
|
|
|
}
|
|
|
|
|
2013-02-02 03:43:17 +00:00
|
|
|
pub fn main() {
|
2011-08-22 20:53:39 +00:00
|
|
|
test_stack_assign();
|
|
|
|
test_heap_lit();
|
2011-08-22 21:33:31 +00:00
|
|
|
test_heap_assign();
|
2011-08-22 23:12:42 +00:00
|
|
|
test_heap_log();
|
2011-08-22 23:39:18 +00:00
|
|
|
test_stack_add();
|
|
|
|
test_stack_heap_add();
|
|
|
|
test_heap_add();
|
2011-08-23 00:35:38 +00:00
|
|
|
test_append();
|
2011-09-02 22:34:58 +00:00
|
|
|
}
|