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-06-13 17:25:36 -07:00
|
|
|
// Issue 483 - Assignment expressions result in nil
|
|
|
|
fn test_assign() {
|
2012-03-22 08:39:41 -07:00
|
|
|
let mut x: int;
|
2013-08-17 08:37:42 -07:00
|
|
|
let y: () = x = 10;
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(x, 10);
|
2013-08-17 08:37:42 -07:00
|
|
|
assert_eq!(y, ());
|
2012-03-22 08:39:41 -07:00
|
|
|
let mut z = x = 11;
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(x, 11);
|
2013-08-17 08:37:42 -07:00
|
|
|
assert_eq!(z, ());
|
2011-06-15 11:19:50 -07:00
|
|
|
z = x = 12;
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(x, 12);
|
2013-08-17 08:37:42 -07:00
|
|
|
assert_eq!(z, ());
|
2011-06-13 17:25:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn test_assign_op() {
|
2012-03-22 08:39:41 -07:00
|
|
|
let mut x: int = 0;
|
2013-08-17 08:37:42 -07:00
|
|
|
let y: () = x += 10;
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(x, 10);
|
2013-08-17 08:37:42 -07:00
|
|
|
assert_eq!(y, ());
|
2012-03-22 08:39:41 -07:00
|
|
|
let mut z = x += 11;
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(x, 21);
|
2013-08-17 08:37:42 -07:00
|
|
|
assert_eq!(z, ());
|
2011-06-15 11:19:50 -07:00
|
|
|
z = x += 12;
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(x, 33);
|
2013-08-17 08:37:42 -07:00
|
|
|
assert_eq!(z, ());
|
2011-06-13 17:25:36 -07:00
|
|
|
}
|
|
|
|
|
2013-02-01 19:43:17 -08:00
|
|
|
pub fn main() { test_assign(); test_assign_op(); }
|