2012-12-10 17:32:48 -08: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 13:53:39 -07:00
|
|
|
fn test_stack_assign() {
|
2012-07-13 22:57:48 -07:00
|
|
|
let s: ~str = ~"a";
|
2012-12-05 16:51:32 -08:00
|
|
|
log(debug, copy s);
|
2012-07-13 22:57:48 -07:00
|
|
|
let t: ~str = ~"a";
|
2013-03-06 13:58:02 -08:00
|
|
|
fail_unless!((s == t));
|
2012-07-13 22:57:48 -07:00
|
|
|
let u: ~str = ~"b";
|
2013-03-06 13:58:02 -08:00
|
|
|
fail_unless!((s != u));
|
2011-08-22 13:53:39 -07:00
|
|
|
}
|
|
|
|
|
2012-07-13 22:57:48 -07:00
|
|
|
fn test_heap_lit() { ~"a big string"; }
|
2011-08-22 13:53:39 -07:00
|
|
|
|
2011-08-22 14:33:31 -07:00
|
|
|
fn test_heap_assign() {
|
2012-07-13 22:57:48 -07:00
|
|
|
let s: ~str = ~"a big ol' string";
|
|
|
|
let t: ~str = ~"a big ol' string";
|
2013-03-06 13:58:02 -08:00
|
|
|
fail_unless!((s == t));
|
2012-07-13 22:57:48 -07:00
|
|
|
let u: ~str = ~"a bad ol' string";
|
2013-03-06 13:58:02 -08:00
|
|
|
fail_unless!((s != u));
|
2011-08-22 14:33:31 -07:00
|
|
|
}
|
|
|
|
|
2012-07-13 22:57:48 -07:00
|
|
|
fn test_heap_log() { let s = ~"a big ol' string"; log(debug, s); }
|
2011-08-22 16:12:42 -07:00
|
|
|
|
2011-08-22 16:39:18 -07:00
|
|
|
fn test_stack_add() {
|
2013-03-06 13:58:02 -08:00
|
|
|
fail_unless!((~"a" + ~"b" == ~"ab"));
|
2012-07-13 22:57:48 -07:00
|
|
|
let s: ~str = ~"a";
|
2013-03-06 13:58:02 -08:00
|
|
|
fail_unless!((s + s == ~"aa"));
|
|
|
|
fail_unless!((~"" + ~"" == ~""));
|
2011-08-22 16:39:18 -07:00
|
|
|
}
|
|
|
|
|
2013-03-06 13:58:02 -08:00
|
|
|
fn test_stack_heap_add() { fail_unless!((~"a" + ~"bracadabra" == ~"abracadabra")); }
|
2011-08-22 16:39:18 -07:00
|
|
|
|
|
|
|
fn test_heap_add() {
|
2013-03-06 13:58:02 -08:00
|
|
|
fail_unless!((~"this should" + ~" totally work" == ~"this should totally work"));
|
2011-08-22 16:39:18 -07:00
|
|
|
}
|
|
|
|
|
2011-08-22 17:35:38 -07:00
|
|
|
fn test_append() {
|
2012-07-13 22:57:48 -07:00
|
|
|
let mut s = ~"";
|
|
|
|
s += ~"a";
|
2013-03-06 13:58:02 -08:00
|
|
|
fail_unless!((s == ~"a"));
|
2011-08-22 17:35:38 -07:00
|
|
|
|
2012-07-13 22:57:48 -07:00
|
|
|
let mut s = ~"a";
|
|
|
|
s += ~"b";
|
2012-12-05 16:51:32 -08:00
|
|
|
log(debug, copy s);
|
2013-03-06 13:58:02 -08:00
|
|
|
fail_unless!((s == ~"ab"));
|
2011-08-22 17:35:38 -07:00
|
|
|
|
2012-07-13 22:57:48 -07:00
|
|
|
let mut s = ~"c";
|
|
|
|
s += ~"offee";
|
2013-03-06 13:58:02 -08:00
|
|
|
fail_unless!((s == ~"coffee"));
|
2011-08-22 17:35:38 -07:00
|
|
|
|
2012-07-13 22:57:48 -07:00
|
|
|
s += ~"&tea";
|
2013-03-06 13:58:02 -08:00
|
|
|
fail_unless!((s == ~"coffee&tea"));
|
2011-08-22 17:35:38 -07:00
|
|
|
}
|
|
|
|
|
2013-02-01 19:43:17 -08:00
|
|
|
pub fn main() {
|
2011-08-22 13:53:39 -07:00
|
|
|
test_stack_assign();
|
|
|
|
test_heap_lit();
|
2011-08-22 14:33:31 -07:00
|
|
|
test_heap_assign();
|
2011-08-22 16:12:42 -07:00
|
|
|
test_heap_log();
|
2011-08-22 16:39:18 -07:00
|
|
|
test_stack_add();
|
|
|
|
test_stack_heap_add();
|
|
|
|
test_heap_add();
|
2011-08-22 17:35:38 -07:00
|
|
|
test_append();
|
2011-09-02 15:34:58 -07:00
|
|
|
}
|