rust/src/test/stdtest/vec.rs

375 lines
8.8 KiB
Rust
Raw Normal View History

use std;
2011-08-15 16:38:23 -07:00
import std::vec;
import std::vec::*;
2011-07-05 17:22:02 -07:00
import std::option;
import std::option::none;
import std::option::some;
2011-07-27 14:19:39 +02:00
fn square(n: uint) -> uint { ret n * n; }
2011-07-27 14:19:39 +02:00
fn square_alias(n: &uint) -> uint { ret n * n; }
2011-07-27 14:19:39 +02:00
pred is_three(n: &uint) -> bool { ret n == 3u; }
fn square_if_odd(n: &uint) -> option::t<uint> {
2011-07-27 14:19:39 +02:00
ret if n % 2u == 1u { some(n * n) } else { none };
2011-07-05 17:22:02 -07:00
}
2011-07-27 14:19:39 +02:00
fn add(x: &uint, y: &uint) -> uint { ret x + y; }
2011-07-05 18:29:18 -07:00
The Big Test Suite Overhaul This replaces the make-based test runner with a set of Rust-based test runners. I believe that all existing functionality has been preserved. The primary objective is to dogfood the Rust test framework. A few main things happen here: 1) The run-pass/lib-* tests are all moved into src/test/stdtest. This is a standalone test crate intended for all standard library tests. It compiles to build/test/stdtest.stageN. 2) rustc now compiles into yet another build artifact, this one a test runner that runs any tests contained directly in the rustc crate. This allows much more fine-grained unit testing of the compiler. It compiles to build/test/rustctest.stageN. 3) There is a new custom test runner crate at src/test/compiletest that reproduces all the functionality for running the compile-fail, run-fail, run-pass and bench tests while integrating with Rust's test framework. It compiles to build/test/compiletest.stageN. 4) The build rules have been completely changed to use the new test runners, while also being less redundant, following the example of the recent stageN.mk rewrite. It adds two new features to the cfail/rfail/rpass/bench tests: 1) Tests can specify multiple 'error-pattern' directives which must be satisfied in order. 2) Tests can specify a 'compile-flags' directive which will make the test runner provide additional command line arguments to rustc. There are some downsides, the primary being that Rust has to be functioning pretty well just to run _any_ tests, which I imagine will be the source of some frustration when the entire test suite breaks. Will also cause some headaches during porting. Not having individual make rules, each rpass, etc test no longer remembers between runs whether it completed successfully. As a result, it's not possible to incrementally fix multiple tests by just running 'make check', fixing a test, and repeating without re-running all the tests contained in the test runner. Instead you can filter just the tests you want to run by using the TESTNAME environment variable. This also dispenses with the ability to run stage0 tests, but they tended to be broken more often than not anyway.
2011-07-12 19:01:09 -07:00
#[test]
fn test_reserve_and_on_heap() {
let v: [int] = ~[1, 2];
2011-08-15 16:38:23 -07:00
assert (!vec::on_heap(v));
vec::reserve(v, 8u);
assert (vec::on_heap(v));
}
The Big Test Suite Overhaul This replaces the make-based test runner with a set of Rust-based test runners. I believe that all existing functionality has been preserved. The primary objective is to dogfood the Rust test framework. A few main things happen here: 1) The run-pass/lib-* tests are all moved into src/test/stdtest. This is a standalone test crate intended for all standard library tests. It compiles to build/test/stdtest.stageN. 2) rustc now compiles into yet another build artifact, this one a test runner that runs any tests contained directly in the rustc crate. This allows much more fine-grained unit testing of the compiler. It compiles to build/test/rustctest.stageN. 3) There is a new custom test runner crate at src/test/compiletest that reproduces all the functionality for running the compile-fail, run-fail, run-pass and bench tests while integrating with Rust's test framework. It compiles to build/test/compiletest.stageN. 4) The build rules have been completely changed to use the new test runners, while also being less redundant, following the example of the recent stageN.mk rewrite. It adds two new features to the cfail/rfail/rpass/bench tests: 1) Tests can specify multiple 'error-pattern' directives which must be satisfied in order. 2) Tests can specify a 'compile-flags' directive which will make the test runner provide additional command line arguments to rustc. There are some downsides, the primary being that Rust has to be functioning pretty well just to run _any_ tests, which I imagine will be the source of some frustration when the entire test suite breaks. Will also cause some headaches during porting. Not having individual make rules, each rpass, etc test no longer remembers between runs whether it completed successfully. As a result, it's not possible to incrementally fix multiple tests by just running 'make check', fixing a test, and repeating without re-running all the tests contained in the test runner. Instead you can filter just the tests you want to run by using the TESTNAME environment variable. This also dispenses with the ability to run stage0 tests, but they tended to be broken more often than not anyway.
2011-07-12 19:01:09 -07:00
#[test]
fn test_unsafe_ptrs() {
// Test on-stack copy-from-buf.
2011-07-27 14:19:39 +02:00
let a = ~[1, 2, 3];
2011-08-15 16:38:23 -07:00
let ptr = vec::to_ptr(a);
2011-07-27 14:19:39 +02:00
let b = ~[];
2011-08-15 16:38:23 -07:00
vec::unsafe::copy_from_buf(b, ptr, 3u);
assert (vec::len(b) == 3u);
assert (b.(0) == 1);
assert (b.(1) == 2);
assert (b.(2) == 3);
// Test on-heap copy-from-buf.
2011-07-27 14:19:39 +02:00
let c = ~[1, 2, 3, 4, 5];
2011-08-15 16:38:23 -07:00
ptr = vec::to_ptr(c);
2011-07-27 14:19:39 +02:00
let d = ~[];
2011-08-15 16:38:23 -07:00
vec::unsafe::copy_from_buf(d, ptr, 5u);
assert (vec::len(d) == 5u);
assert (d.(0) == 1);
assert (d.(1) == 2);
assert (d.(2) == 3);
assert (d.(3) == 4);
assert (d.(4) == 5);
}
The Big Test Suite Overhaul This replaces the make-based test runner with a set of Rust-based test runners. I believe that all existing functionality has been preserved. The primary objective is to dogfood the Rust test framework. A few main things happen here: 1) The run-pass/lib-* tests are all moved into src/test/stdtest. This is a standalone test crate intended for all standard library tests. It compiles to build/test/stdtest.stageN. 2) rustc now compiles into yet another build artifact, this one a test runner that runs any tests contained directly in the rustc crate. This allows much more fine-grained unit testing of the compiler. It compiles to build/test/rustctest.stageN. 3) There is a new custom test runner crate at src/test/compiletest that reproduces all the functionality for running the compile-fail, run-fail, run-pass and bench tests while integrating with Rust's test framework. It compiles to build/test/compiletest.stageN. 4) The build rules have been completely changed to use the new test runners, while also being less redundant, following the example of the recent stageN.mk rewrite. It adds two new features to the cfail/rfail/rpass/bench tests: 1) Tests can specify multiple 'error-pattern' directives which must be satisfied in order. 2) Tests can specify a 'compile-flags' directive which will make the test runner provide additional command line arguments to rustc. There are some downsides, the primary being that Rust has to be functioning pretty well just to run _any_ tests, which I imagine will be the source of some frustration when the entire test suite breaks. Will also cause some headaches during porting. Not having individual make rules, each rpass, etc test no longer remembers between runs whether it completed successfully. As a result, it's not possible to incrementally fix multiple tests by just running 'make check', fixing a test, and repeating without re-running all the tests contained in the test runner. Instead you can filter just the tests you want to run by using the TESTNAME environment variable. This also dispenses with the ability to run stage0 tests, but they tended to be broken more often than not anyway.
2011-07-12 19:01:09 -07:00
#[test]
fn test_init_fn() {
// Test on-stack init_fn.
2011-08-15 16:38:23 -07:00
let v = vec::init_fn(square, 3u);
assert (vec::len(v) == 3u);
assert (v.(0) == 0u);
assert (v.(1) == 1u);
assert (v.(2) == 4u);
// Test on-heap init_fn.
2011-08-15 16:38:23 -07:00
v = vec::init_fn(square, 5u);
assert (vec::len(v) == 5u);
assert (v.(0) == 0u);
assert (v.(1) == 1u);
assert (v.(2) == 4u);
assert (v.(3) == 9u);
assert (v.(4) == 16u);
}
The Big Test Suite Overhaul This replaces the make-based test runner with a set of Rust-based test runners. I believe that all existing functionality has been preserved. The primary objective is to dogfood the Rust test framework. A few main things happen here: 1) The run-pass/lib-* tests are all moved into src/test/stdtest. This is a standalone test crate intended for all standard library tests. It compiles to build/test/stdtest.stageN. 2) rustc now compiles into yet another build artifact, this one a test runner that runs any tests contained directly in the rustc crate. This allows much more fine-grained unit testing of the compiler. It compiles to build/test/rustctest.stageN. 3) There is a new custom test runner crate at src/test/compiletest that reproduces all the functionality for running the compile-fail, run-fail, run-pass and bench tests while integrating with Rust's test framework. It compiles to build/test/compiletest.stageN. 4) The build rules have been completely changed to use the new test runners, while also being less redundant, following the example of the recent stageN.mk rewrite. It adds two new features to the cfail/rfail/rpass/bench tests: 1) Tests can specify multiple 'error-pattern' directives which must be satisfied in order. 2) Tests can specify a 'compile-flags' directive which will make the test runner provide additional command line arguments to rustc. There are some downsides, the primary being that Rust has to be functioning pretty well just to run _any_ tests, which I imagine will be the source of some frustration when the entire test suite breaks. Will also cause some headaches during porting. Not having individual make rules, each rpass, etc test no longer remembers between runs whether it completed successfully. As a result, it's not possible to incrementally fix multiple tests by just running 'make check', fixing a test, and repeating without re-running all the tests contained in the test runner. Instead you can filter just the tests you want to run by using the TESTNAME environment variable. This also dispenses with the ability to run stage0 tests, but they tended to be broken more often than not anyway.
2011-07-12 19:01:09 -07:00
#[test]
fn test_init_elt() {
// Test on-stack init_elt.
2011-08-15 16:38:23 -07:00
let v = vec::init_elt(10u, 2u);
assert (vec::len(v) == 2u);
assert (v.(0) == 10u);
assert (v.(1) == 10u);
// Test on-heap init_elt.
2011-08-15 16:38:23 -07:00
v = vec::init_elt(20u, 6u);
assert (v.(0) == 20u);
assert (v.(1) == 20u);
assert (v.(2) == 20u);
assert (v.(3) == 20u);
assert (v.(4) == 20u);
assert (v.(5) == 20u);
}
The Big Test Suite Overhaul This replaces the make-based test runner with a set of Rust-based test runners. I believe that all existing functionality has been preserved. The primary objective is to dogfood the Rust test framework. A few main things happen here: 1) The run-pass/lib-* tests are all moved into src/test/stdtest. This is a standalone test crate intended for all standard library tests. It compiles to build/test/stdtest.stageN. 2) rustc now compiles into yet another build artifact, this one a test runner that runs any tests contained directly in the rustc crate. This allows much more fine-grained unit testing of the compiler. It compiles to build/test/rustctest.stageN. 3) There is a new custom test runner crate at src/test/compiletest that reproduces all the functionality for running the compile-fail, run-fail, run-pass and bench tests while integrating with Rust's test framework. It compiles to build/test/compiletest.stageN. 4) The build rules have been completely changed to use the new test runners, while also being less redundant, following the example of the recent stageN.mk rewrite. It adds two new features to the cfail/rfail/rpass/bench tests: 1) Tests can specify multiple 'error-pattern' directives which must be satisfied in order. 2) Tests can specify a 'compile-flags' directive which will make the test runner provide additional command line arguments to rustc. There are some downsides, the primary being that Rust has to be functioning pretty well just to run _any_ tests, which I imagine will be the source of some frustration when the entire test suite breaks. Will also cause some headaches during porting. Not having individual make rules, each rpass, etc test no longer remembers between runs whether it completed successfully. As a result, it's not possible to incrementally fix multiple tests by just running 'make check', fixing a test, and repeating without re-running all the tests contained in the test runner. Instead you can filter just the tests you want to run by using the TESTNAME environment variable. This also dispenses with the ability to run stage0 tests, but they tended to be broken more often than not anyway.
2011-07-12 19:01:09 -07:00
#[test]
fn test_is_empty() {
assert (vec::is_empty::<int>(~[]));
2011-08-15 16:38:23 -07:00
assert (!vec::is_empty(~[0]));
}
The Big Test Suite Overhaul This replaces the make-based test runner with a set of Rust-based test runners. I believe that all existing functionality has been preserved. The primary objective is to dogfood the Rust test framework. A few main things happen here: 1) The run-pass/lib-* tests are all moved into src/test/stdtest. This is a standalone test crate intended for all standard library tests. It compiles to build/test/stdtest.stageN. 2) rustc now compiles into yet another build artifact, this one a test runner that runs any tests contained directly in the rustc crate. This allows much more fine-grained unit testing of the compiler. It compiles to build/test/rustctest.stageN. 3) There is a new custom test runner crate at src/test/compiletest that reproduces all the functionality for running the compile-fail, run-fail, run-pass and bench tests while integrating with Rust's test framework. It compiles to build/test/compiletest.stageN. 4) The build rules have been completely changed to use the new test runners, while also being less redundant, following the example of the recent stageN.mk rewrite. It adds two new features to the cfail/rfail/rpass/bench tests: 1) Tests can specify multiple 'error-pattern' directives which must be satisfied in order. 2) Tests can specify a 'compile-flags' directive which will make the test runner provide additional command line arguments to rustc. There are some downsides, the primary being that Rust has to be functioning pretty well just to run _any_ tests, which I imagine will be the source of some frustration when the entire test suite breaks. Will also cause some headaches during porting. Not having individual make rules, each rpass, etc test no longer remembers between runs whether it completed successfully. As a result, it's not possible to incrementally fix multiple tests by just running 'make check', fixing a test, and repeating without re-running all the tests contained in the test runner. Instead you can filter just the tests you want to run by using the TESTNAME environment variable. This also dispenses with the ability to run stage0 tests, but they tended to be broken more often than not anyway.
2011-07-12 19:01:09 -07:00
#[test]
fn test_is_not_empty() {
2011-08-15 16:38:23 -07:00
assert (vec::is_not_empty(~[0]));
assert (!vec::is_not_empty::<int>(~[]));
}
The Big Test Suite Overhaul This replaces the make-based test runner with a set of Rust-based test runners. I believe that all existing functionality has been preserved. The primary objective is to dogfood the Rust test framework. A few main things happen here: 1) The run-pass/lib-* tests are all moved into src/test/stdtest. This is a standalone test crate intended for all standard library tests. It compiles to build/test/stdtest.stageN. 2) rustc now compiles into yet another build artifact, this one a test runner that runs any tests contained directly in the rustc crate. This allows much more fine-grained unit testing of the compiler. It compiles to build/test/rustctest.stageN. 3) There is a new custom test runner crate at src/test/compiletest that reproduces all the functionality for running the compile-fail, run-fail, run-pass and bench tests while integrating with Rust's test framework. It compiles to build/test/compiletest.stageN. 4) The build rules have been completely changed to use the new test runners, while also being less redundant, following the example of the recent stageN.mk rewrite. It adds two new features to the cfail/rfail/rpass/bench tests: 1) Tests can specify multiple 'error-pattern' directives which must be satisfied in order. 2) Tests can specify a 'compile-flags' directive which will make the test runner provide additional command line arguments to rustc. There are some downsides, the primary being that Rust has to be functioning pretty well just to run _any_ tests, which I imagine will be the source of some frustration when the entire test suite breaks. Will also cause some headaches during porting. Not having individual make rules, each rpass, etc test no longer remembers between runs whether it completed successfully. As a result, it's not possible to incrementally fix multiple tests by just running 'make check', fixing a test, and repeating without re-running all the tests contained in the test runner. Instead you can filter just the tests you want to run by using the TESTNAME environment variable. This also dispenses with the ability to run stage0 tests, but they tended to be broken more often than not anyway.
2011-07-12 19:01:09 -07:00
#[test]
fn test_head() {
2011-07-27 14:19:39 +02:00
let a = ~[11, 12];
2011-08-15 16:38:23 -07:00
check (vec::is_not_empty(a));
assert (vec::head(a) == 11);
}
The Big Test Suite Overhaul This replaces the make-based test runner with a set of Rust-based test runners. I believe that all existing functionality has been preserved. The primary objective is to dogfood the Rust test framework. A few main things happen here: 1) The run-pass/lib-* tests are all moved into src/test/stdtest. This is a standalone test crate intended for all standard library tests. It compiles to build/test/stdtest.stageN. 2) rustc now compiles into yet another build artifact, this one a test runner that runs any tests contained directly in the rustc crate. This allows much more fine-grained unit testing of the compiler. It compiles to build/test/rustctest.stageN. 3) There is a new custom test runner crate at src/test/compiletest that reproduces all the functionality for running the compile-fail, run-fail, run-pass and bench tests while integrating with Rust's test framework. It compiles to build/test/compiletest.stageN. 4) The build rules have been completely changed to use the new test runners, while also being less redundant, following the example of the recent stageN.mk rewrite. It adds two new features to the cfail/rfail/rpass/bench tests: 1) Tests can specify multiple 'error-pattern' directives which must be satisfied in order. 2) Tests can specify a 'compile-flags' directive which will make the test runner provide additional command line arguments to rustc. There are some downsides, the primary being that Rust has to be functioning pretty well just to run _any_ tests, which I imagine will be the source of some frustration when the entire test suite breaks. Will also cause some headaches during porting. Not having individual make rules, each rpass, etc test no longer remembers between runs whether it completed successfully. As a result, it's not possible to incrementally fix multiple tests by just running 'make check', fixing a test, and repeating without re-running all the tests contained in the test runner. Instead you can filter just the tests you want to run by using the TESTNAME environment variable. This also dispenses with the ability to run stage0 tests, but they tended to be broken more often than not anyway.
2011-07-12 19:01:09 -07:00
#[test]
fn test_tail() {
2011-07-27 14:19:39 +02:00
let a = ~[11];
2011-08-15 16:38:23 -07:00
check (vec::is_not_empty(a));
assert (vec::tail(a) == ~[]);
a = ~[11, 12];
2011-08-15 16:38:23 -07:00
check (vec::is_not_empty(a));
assert (vec::tail(a) == ~[12]);
}
The Big Test Suite Overhaul This replaces the make-based test runner with a set of Rust-based test runners. I believe that all existing functionality has been preserved. The primary objective is to dogfood the Rust test framework. A few main things happen here: 1) The run-pass/lib-* tests are all moved into src/test/stdtest. This is a standalone test crate intended for all standard library tests. It compiles to build/test/stdtest.stageN. 2) rustc now compiles into yet another build artifact, this one a test runner that runs any tests contained directly in the rustc crate. This allows much more fine-grained unit testing of the compiler. It compiles to build/test/rustctest.stageN. 3) There is a new custom test runner crate at src/test/compiletest that reproduces all the functionality for running the compile-fail, run-fail, run-pass and bench tests while integrating with Rust's test framework. It compiles to build/test/compiletest.stageN. 4) The build rules have been completely changed to use the new test runners, while also being less redundant, following the example of the recent stageN.mk rewrite. It adds two new features to the cfail/rfail/rpass/bench tests: 1) Tests can specify multiple 'error-pattern' directives which must be satisfied in order. 2) Tests can specify a 'compile-flags' directive which will make the test runner provide additional command line arguments to rustc. There are some downsides, the primary being that Rust has to be functioning pretty well just to run _any_ tests, which I imagine will be the source of some frustration when the entire test suite breaks. Will also cause some headaches during porting. Not having individual make rules, each rpass, etc test no longer remembers between runs whether it completed successfully. As a result, it's not possible to incrementally fix multiple tests by just running 'make check', fixing a test, and repeating without re-running all the tests contained in the test runner. Instead you can filter just the tests you want to run by using the TESTNAME environment variable. This also dispenses with the ability to run stage0 tests, but they tended to be broken more often than not anyway.
2011-07-12 19:01:09 -07:00
#[test]
fn test_last() {
2011-08-15 16:38:23 -07:00
let n = vec::last(~[]);
assert (n == none);
2011-08-15 16:38:23 -07:00
n = vec::last(~[1, 2, 3]);
assert (n == some(3));
2011-08-15 16:38:23 -07:00
n = vec::last(~[1, 2, 3, 4, 5]);
assert (n == some(5));
}
The Big Test Suite Overhaul This replaces the make-based test runner with a set of Rust-based test runners. I believe that all existing functionality has been preserved. The primary objective is to dogfood the Rust test framework. A few main things happen here: 1) The run-pass/lib-* tests are all moved into src/test/stdtest. This is a standalone test crate intended for all standard library tests. It compiles to build/test/stdtest.stageN. 2) rustc now compiles into yet another build artifact, this one a test runner that runs any tests contained directly in the rustc crate. This allows much more fine-grained unit testing of the compiler. It compiles to build/test/rustctest.stageN. 3) There is a new custom test runner crate at src/test/compiletest that reproduces all the functionality for running the compile-fail, run-fail, run-pass and bench tests while integrating with Rust's test framework. It compiles to build/test/compiletest.stageN. 4) The build rules have been completely changed to use the new test runners, while also being less redundant, following the example of the recent stageN.mk rewrite. It adds two new features to the cfail/rfail/rpass/bench tests: 1) Tests can specify multiple 'error-pattern' directives which must be satisfied in order. 2) Tests can specify a 'compile-flags' directive which will make the test runner provide additional command line arguments to rustc. There are some downsides, the primary being that Rust has to be functioning pretty well just to run _any_ tests, which I imagine will be the source of some frustration when the entire test suite breaks. Will also cause some headaches during porting. Not having individual make rules, each rpass, etc test no longer remembers between runs whether it completed successfully. As a result, it's not possible to incrementally fix multiple tests by just running 'make check', fixing a test, and repeating without re-running all the tests contained in the test runner. Instead you can filter just the tests you want to run by using the TESTNAME environment variable. This also dispenses with the ability to run stage0 tests, but they tended to be broken more often than not anyway.
2011-07-12 19:01:09 -07:00
#[test]
fn test_slice() {
// Test on-stack -> on-stack slice.
2011-08-15 16:38:23 -07:00
let v = vec::slice(~[1, 2, 3], 1u, 3u);
assert (vec::len(v) == 2u);
assert (v.(0) == 2);
assert (v.(1) == 3);
// Test on-heap -> on-stack slice.
2011-08-15 16:38:23 -07:00
v = vec::slice(~[1, 2, 3, 4, 5], 0u, 3u);
assert (vec::len(v) == 3u);
assert (v.(0) == 1);
assert (v.(1) == 2);
assert (v.(2) == 3);
// Test on-heap -> on-heap slice.
2011-08-15 16:38:23 -07:00
v = vec::slice(~[1, 2, 3, 4, 5, 6], 1u, 6u);
assert (vec::len(v) == 5u);
assert (v.(0) == 2);
assert (v.(1) == 3);
assert (v.(2) == 4);
assert (v.(3) == 5);
assert (v.(4) == 6);
}
The Big Test Suite Overhaul This replaces the make-based test runner with a set of Rust-based test runners. I believe that all existing functionality has been preserved. The primary objective is to dogfood the Rust test framework. A few main things happen here: 1) The run-pass/lib-* tests are all moved into src/test/stdtest. This is a standalone test crate intended for all standard library tests. It compiles to build/test/stdtest.stageN. 2) rustc now compiles into yet another build artifact, this one a test runner that runs any tests contained directly in the rustc crate. This allows much more fine-grained unit testing of the compiler. It compiles to build/test/rustctest.stageN. 3) There is a new custom test runner crate at src/test/compiletest that reproduces all the functionality for running the compile-fail, run-fail, run-pass and bench tests while integrating with Rust's test framework. It compiles to build/test/compiletest.stageN. 4) The build rules have been completely changed to use the new test runners, while also being less redundant, following the example of the recent stageN.mk rewrite. It adds two new features to the cfail/rfail/rpass/bench tests: 1) Tests can specify multiple 'error-pattern' directives which must be satisfied in order. 2) Tests can specify a 'compile-flags' directive which will make the test runner provide additional command line arguments to rustc. There are some downsides, the primary being that Rust has to be functioning pretty well just to run _any_ tests, which I imagine will be the source of some frustration when the entire test suite breaks. Will also cause some headaches during porting. Not having individual make rules, each rpass, etc test no longer remembers between runs whether it completed successfully. As a result, it's not possible to incrementally fix multiple tests by just running 'make check', fixing a test, and repeating without re-running all the tests contained in the test runner. Instead you can filter just the tests you want to run by using the TESTNAME environment variable. This also dispenses with the ability to run stage0 tests, but they tended to be broken more often than not anyway.
2011-07-12 19:01:09 -07:00
#[test]
fn test_pop() {
// Test on-stack pop.
2011-07-27 14:19:39 +02:00
let v = ~[1, 2, 3];
2011-08-15 16:38:23 -07:00
let e = vec::pop(v);
assert (vec::len(v) == 2u);
assert (v.(0) == 1);
assert (v.(1) == 2);
assert (e == 3);
// Test on-heap pop.
2011-07-27 14:19:39 +02:00
v = ~[1, 2, 3, 4, 5];
2011-08-15 16:38:23 -07:00
e = vec::pop(v);
assert (vec::len(v) == 4u);
assert (v.(0) == 1);
assert (v.(1) == 2);
assert (v.(2) == 3);
assert (v.(3) == 4);
assert (e == 5);
}
The Big Test Suite Overhaul This replaces the make-based test runner with a set of Rust-based test runners. I believe that all existing functionality has been preserved. The primary objective is to dogfood the Rust test framework. A few main things happen here: 1) The run-pass/lib-* tests are all moved into src/test/stdtest. This is a standalone test crate intended for all standard library tests. It compiles to build/test/stdtest.stageN. 2) rustc now compiles into yet another build artifact, this one a test runner that runs any tests contained directly in the rustc crate. This allows much more fine-grained unit testing of the compiler. It compiles to build/test/rustctest.stageN. 3) There is a new custom test runner crate at src/test/compiletest that reproduces all the functionality for running the compile-fail, run-fail, run-pass and bench tests while integrating with Rust's test framework. It compiles to build/test/compiletest.stageN. 4) The build rules have been completely changed to use the new test runners, while also being less redundant, following the example of the recent stageN.mk rewrite. It adds two new features to the cfail/rfail/rpass/bench tests: 1) Tests can specify multiple 'error-pattern' directives which must be satisfied in order. 2) Tests can specify a 'compile-flags' directive which will make the test runner provide additional command line arguments to rustc. There are some downsides, the primary being that Rust has to be functioning pretty well just to run _any_ tests, which I imagine will be the source of some frustration when the entire test suite breaks. Will also cause some headaches during porting. Not having individual make rules, each rpass, etc test no longer remembers between runs whether it completed successfully. As a result, it's not possible to incrementally fix multiple tests by just running 'make check', fixing a test, and repeating without re-running all the tests contained in the test runner. Instead you can filter just the tests you want to run by using the TESTNAME environment variable. This also dispenses with the ability to run stage0 tests, but they tended to be broken more often than not anyway.
2011-07-12 19:01:09 -07:00
#[test]
fn test_grow() {
// Test on-stack grow().
2011-07-27 14:19:39 +02:00
let v = ~[];
2011-08-15 16:38:23 -07:00
vec::grow(v, 2u, 1);
assert (vec::len(v) == 2u);
assert (v.(0) == 1);
assert (v.(1) == 1);
// Test on-heap grow().
2011-08-15 16:38:23 -07:00
vec::grow(v, 3u, 2);
assert (vec::len(v) == 5u);
assert (v.(0) == 1);
assert (v.(1) == 1);
assert (v.(2) == 2);
assert (v.(3) == 2);
assert (v.(4) == 2);
}
The Big Test Suite Overhaul This replaces the make-based test runner with a set of Rust-based test runners. I believe that all existing functionality has been preserved. The primary objective is to dogfood the Rust test framework. A few main things happen here: 1) The run-pass/lib-* tests are all moved into src/test/stdtest. This is a standalone test crate intended for all standard library tests. It compiles to build/test/stdtest.stageN. 2) rustc now compiles into yet another build artifact, this one a test runner that runs any tests contained directly in the rustc crate. This allows much more fine-grained unit testing of the compiler. It compiles to build/test/rustctest.stageN. 3) There is a new custom test runner crate at src/test/compiletest that reproduces all the functionality for running the compile-fail, run-fail, run-pass and bench tests while integrating with Rust's test framework. It compiles to build/test/compiletest.stageN. 4) The build rules have been completely changed to use the new test runners, while also being less redundant, following the example of the recent stageN.mk rewrite. It adds two new features to the cfail/rfail/rpass/bench tests: 1) Tests can specify multiple 'error-pattern' directives which must be satisfied in order. 2) Tests can specify a 'compile-flags' directive which will make the test runner provide additional command line arguments to rustc. There are some downsides, the primary being that Rust has to be functioning pretty well just to run _any_ tests, which I imagine will be the source of some frustration when the entire test suite breaks. Will also cause some headaches during porting. Not having individual make rules, each rpass, etc test no longer remembers between runs whether it completed successfully. As a result, it's not possible to incrementally fix multiple tests by just running 'make check', fixing a test, and repeating without re-running all the tests contained in the test runner. Instead you can filter just the tests you want to run by using the TESTNAME environment variable. This also dispenses with the ability to run stage0 tests, but they tended to be broken more often than not anyway.
2011-07-12 19:01:09 -07:00
#[test]
fn test_grow_fn() {
2011-07-27 14:19:39 +02:00
let v = ~[];
2011-08-15 16:38:23 -07:00
vec::grow_fn(v, 3u, square);
assert (vec::len(v) == 3u);
assert (v.(0) == 0u);
assert (v.(1) == 1u);
assert (v.(2) == 4u);
}
The Big Test Suite Overhaul This replaces the make-based test runner with a set of Rust-based test runners. I believe that all existing functionality has been preserved. The primary objective is to dogfood the Rust test framework. A few main things happen here: 1) The run-pass/lib-* tests are all moved into src/test/stdtest. This is a standalone test crate intended for all standard library tests. It compiles to build/test/stdtest.stageN. 2) rustc now compiles into yet another build artifact, this one a test runner that runs any tests contained directly in the rustc crate. This allows much more fine-grained unit testing of the compiler. It compiles to build/test/rustctest.stageN. 3) There is a new custom test runner crate at src/test/compiletest that reproduces all the functionality for running the compile-fail, run-fail, run-pass and bench tests while integrating with Rust's test framework. It compiles to build/test/compiletest.stageN. 4) The build rules have been completely changed to use the new test runners, while also being less redundant, following the example of the recent stageN.mk rewrite. It adds two new features to the cfail/rfail/rpass/bench tests: 1) Tests can specify multiple 'error-pattern' directives which must be satisfied in order. 2) Tests can specify a 'compile-flags' directive which will make the test runner provide additional command line arguments to rustc. There are some downsides, the primary being that Rust has to be functioning pretty well just to run _any_ tests, which I imagine will be the source of some frustration when the entire test suite breaks. Will also cause some headaches during porting. Not having individual make rules, each rpass, etc test no longer remembers between runs whether it completed successfully. As a result, it's not possible to incrementally fix multiple tests by just running 'make check', fixing a test, and repeating without re-running all the tests contained in the test runner. Instead you can filter just the tests you want to run by using the TESTNAME environment variable. This also dispenses with the ability to run stage0 tests, but they tended to be broken more often than not anyway.
2011-07-12 19:01:09 -07:00
#[test]
2011-06-18 16:41:09 -07:00
fn test_grow_set() {
2011-07-27 14:19:39 +02:00
let v = ~[mutable 1, 2, 3];
2011-08-15 16:38:23 -07:00
vec::grow_set(v, 4u, 4, 5);
assert (vec::len(v) == 5u);
2011-06-18 16:41:09 -07:00
assert (v.(0) == 1);
assert (v.(1) == 2);
assert (v.(2) == 3);
assert (v.(3) == 4);
assert (v.(4) == 5);
}
The Big Test Suite Overhaul This replaces the make-based test runner with a set of Rust-based test runners. I believe that all existing functionality has been preserved. The primary objective is to dogfood the Rust test framework. A few main things happen here: 1) The run-pass/lib-* tests are all moved into src/test/stdtest. This is a standalone test crate intended for all standard library tests. It compiles to build/test/stdtest.stageN. 2) rustc now compiles into yet another build artifact, this one a test runner that runs any tests contained directly in the rustc crate. This allows much more fine-grained unit testing of the compiler. It compiles to build/test/rustctest.stageN. 3) There is a new custom test runner crate at src/test/compiletest that reproduces all the functionality for running the compile-fail, run-fail, run-pass and bench tests while integrating with Rust's test framework. It compiles to build/test/compiletest.stageN. 4) The build rules have been completely changed to use the new test runners, while also being less redundant, following the example of the recent stageN.mk rewrite. It adds two new features to the cfail/rfail/rpass/bench tests: 1) Tests can specify multiple 'error-pattern' directives which must be satisfied in order. 2) Tests can specify a 'compile-flags' directive which will make the test runner provide additional command line arguments to rustc. There are some downsides, the primary being that Rust has to be functioning pretty well just to run _any_ tests, which I imagine will be the source of some frustration when the entire test suite breaks. Will also cause some headaches during porting. Not having individual make rules, each rpass, etc test no longer remembers between runs whether it completed successfully. As a result, it's not possible to incrementally fix multiple tests by just running 'make check', fixing a test, and repeating without re-running all the tests contained in the test runner. Instead you can filter just the tests you want to run by using the TESTNAME environment variable. This also dispenses with the ability to run stage0 tests, but they tended to be broken more often than not anyway.
2011-07-12 19:01:09 -07:00
#[test]
2011-07-04 22:48:42 -07:00
fn test_map() {
// Test on-stack map.
2011-07-27 14:19:39 +02:00
let v = ~[1u, 2u, 3u];
2011-08-15 16:38:23 -07:00
let w = vec::map(square_alias, v);
assert (vec::len(w) == 3u);
2011-07-04 22:48:42 -07:00
assert (w.(0) == 1u);
assert (w.(1) == 4u);
assert (w.(2) == 9u);
// Test on-heap map.
2011-07-27 14:19:39 +02:00
v = ~[1u, 2u, 3u, 4u, 5u];
2011-08-15 16:38:23 -07:00
w = vec::map(square_alias, v);
assert (vec::len(w) == 5u);
2011-07-04 22:48:42 -07:00
assert (w.(0) == 1u);
assert (w.(1) == 4u);
assert (w.(2) == 9u);
assert (w.(3) == 16u);
assert (w.(4) == 25u);
}
#[test]
fn test_map2() {
fn times(x: &int, y: &int) -> int { ret x * y; }
let f = times;
let v0 = ~[1, 2, 3, 4, 5];
let v1 = ~[5, 4, 3, 2, 1];
let u = vec::map2::<int, int, int>(f, v0, v1);
let i = 0;
while i < 5 { assert (v0.(i) * v1.(i) == u.(i)); i += 1; }
}
The Big Test Suite Overhaul This replaces the make-based test runner with a set of Rust-based test runners. I believe that all existing functionality has been preserved. The primary objective is to dogfood the Rust test framework. A few main things happen here: 1) The run-pass/lib-* tests are all moved into src/test/stdtest. This is a standalone test crate intended for all standard library tests. It compiles to build/test/stdtest.stageN. 2) rustc now compiles into yet another build artifact, this one a test runner that runs any tests contained directly in the rustc crate. This allows much more fine-grained unit testing of the compiler. It compiles to build/test/rustctest.stageN. 3) There is a new custom test runner crate at src/test/compiletest that reproduces all the functionality for running the compile-fail, run-fail, run-pass and bench tests while integrating with Rust's test framework. It compiles to build/test/compiletest.stageN. 4) The build rules have been completely changed to use the new test runners, while also being less redundant, following the example of the recent stageN.mk rewrite. It adds two new features to the cfail/rfail/rpass/bench tests: 1) Tests can specify multiple 'error-pattern' directives which must be satisfied in order. 2) Tests can specify a 'compile-flags' directive which will make the test runner provide additional command line arguments to rustc. There are some downsides, the primary being that Rust has to be functioning pretty well just to run _any_ tests, which I imagine will be the source of some frustration when the entire test suite breaks. Will also cause some headaches during porting. Not having individual make rules, each rpass, etc test no longer remembers between runs whether it completed successfully. As a result, it's not possible to incrementally fix multiple tests by just running 'make check', fixing a test, and repeating without re-running all the tests contained in the test runner. Instead you can filter just the tests you want to run by using the TESTNAME environment variable. This also dispenses with the ability to run stage0 tests, but they tended to be broken more often than not anyway.
2011-07-12 19:01:09 -07:00
#[test]
2011-07-05 17:22:02 -07:00
fn test_filter_map() {
// Test on-stack filter-map.
2011-07-27 14:19:39 +02:00
let v = ~[1u, 2u, 3u];
2011-08-15 16:38:23 -07:00
let w = vec::filter_map(square_if_odd, v);
assert (vec::len(w) == 2u);
2011-07-05 17:22:02 -07:00
assert (w.(0) == 1u);
assert (w.(1) == 9u);
// Test on-heap filter-map.
2011-07-27 14:19:39 +02:00
v = ~[1u, 2u, 3u, 4u, 5u];
2011-08-15 16:38:23 -07:00
w = vec::filter_map(square_if_odd, v);
assert (vec::len(w) == 3u);
2011-07-05 17:22:02 -07:00
assert (w.(0) == 1u);
assert (w.(1) == 9u);
assert (w.(2) == 25u);
fn halve(i: &int) -> option::t<int> {
if i % 2 == 0 {
ret option::some::<int>(i / 2);
} else { ret option::none::<int>; }
}
fn halve_for_sure(i: &int) -> int { ret i / 2; }
let all_even: [int] = ~[0, 2, 8, 6];
let all_odd1: [int] = ~[1, 7, 3];
let all_odd2: [int] = ~[];
let mix: [int] = ~[9, 2, 6, 7, 1, 0, 0, 3];
let mix_dest: [int] = ~[1, 3, 0, 0];
assert (filter_map(halve, all_even) == map(halve_for_sure, all_even));
assert (filter_map(halve, all_odd1) == ~[]);
assert (filter_map(halve, all_odd2) == ~[]);
assert (filter_map(halve, mix) == mix_dest);
2011-07-05 17:22:02 -07:00
}
The Big Test Suite Overhaul This replaces the make-based test runner with a set of Rust-based test runners. I believe that all existing functionality has been preserved. The primary objective is to dogfood the Rust test framework. A few main things happen here: 1) The run-pass/lib-* tests are all moved into src/test/stdtest. This is a standalone test crate intended for all standard library tests. It compiles to build/test/stdtest.stageN. 2) rustc now compiles into yet another build artifact, this one a test runner that runs any tests contained directly in the rustc crate. This allows much more fine-grained unit testing of the compiler. It compiles to build/test/rustctest.stageN. 3) There is a new custom test runner crate at src/test/compiletest that reproduces all the functionality for running the compile-fail, run-fail, run-pass and bench tests while integrating with Rust's test framework. It compiles to build/test/compiletest.stageN. 4) The build rules have been completely changed to use the new test runners, while also being less redundant, following the example of the recent stageN.mk rewrite. It adds two new features to the cfail/rfail/rpass/bench tests: 1) Tests can specify multiple 'error-pattern' directives which must be satisfied in order. 2) Tests can specify a 'compile-flags' directive which will make the test runner provide additional command line arguments to rustc. There are some downsides, the primary being that Rust has to be functioning pretty well just to run _any_ tests, which I imagine will be the source of some frustration when the entire test suite breaks. Will also cause some headaches during porting. Not having individual make rules, each rpass, etc test no longer remembers between runs whether it completed successfully. As a result, it's not possible to incrementally fix multiple tests by just running 'make check', fixing a test, and repeating without re-running all the tests contained in the test runner. Instead you can filter just the tests you want to run by using the TESTNAME environment variable. This also dispenses with the ability to run stage0 tests, but they tended to be broken more often than not anyway.
2011-07-12 19:01:09 -07:00
#[test]
2011-07-05 18:29:18 -07:00
fn test_foldl() {
// Test on-stack fold.
2011-07-27 14:19:39 +02:00
let v = ~[1u, 2u, 3u];
2011-08-15 16:38:23 -07:00
let sum = vec::foldl(add, 0u, v);
2011-07-05 18:29:18 -07:00
assert (sum == 6u);
// Test on-heap fold.
2011-07-27 14:19:39 +02:00
v = ~[1u, 2u, 3u, 4u, 5u];
2011-08-15 16:38:23 -07:00
sum = vec::foldl(add, 0u, v);
2011-07-05 18:29:18 -07:00
assert (sum == 15u);
}
The Big Test Suite Overhaul This replaces the make-based test runner with a set of Rust-based test runners. I believe that all existing functionality has been preserved. The primary objective is to dogfood the Rust test framework. A few main things happen here: 1) The run-pass/lib-* tests are all moved into src/test/stdtest. This is a standalone test crate intended for all standard library tests. It compiles to build/test/stdtest.stageN. 2) rustc now compiles into yet another build artifact, this one a test runner that runs any tests contained directly in the rustc crate. This allows much more fine-grained unit testing of the compiler. It compiles to build/test/rustctest.stageN. 3) There is a new custom test runner crate at src/test/compiletest that reproduces all the functionality for running the compile-fail, run-fail, run-pass and bench tests while integrating with Rust's test framework. It compiles to build/test/compiletest.stageN. 4) The build rules have been completely changed to use the new test runners, while also being less redundant, following the example of the recent stageN.mk rewrite. It adds two new features to the cfail/rfail/rpass/bench tests: 1) Tests can specify multiple 'error-pattern' directives which must be satisfied in order. 2) Tests can specify a 'compile-flags' directive which will make the test runner provide additional command line arguments to rustc. There are some downsides, the primary being that Rust has to be functioning pretty well just to run _any_ tests, which I imagine will be the source of some frustration when the entire test suite breaks. Will also cause some headaches during porting. Not having individual make rules, each rpass, etc test no longer remembers between runs whether it completed successfully. As a result, it's not possible to incrementally fix multiple tests by just running 'make check', fixing a test, and repeating without re-running all the tests contained in the test runner. Instead you can filter just the tests you want to run by using the TESTNAME environment variable. This also dispenses with the ability to run stage0 tests, but they tended to be broken more often than not anyway.
2011-07-12 19:01:09 -07:00
#[test]
fn test_any_and_all() {
2011-08-15 16:38:23 -07:00
assert (vec::any(is_three, ~[1u, 2u, 3u]));
assert (!vec::any(is_three, ~[0u, 1u, 2u]));
assert (vec::any(is_three, ~[1u, 2u, 3u, 4u, 5u]));
assert (!vec::any(is_three, ~[1u, 2u, 4u, 5u, 6u]));
assert (vec::all(is_three, ~[3u, 3u, 3u]));
assert (!vec::all(is_three, ~[3u, 3u, 2u]));
assert (vec::all(is_three, ~[3u, 3u, 3u, 3u, 3u]));
assert (!vec::all(is_three, ~[3u, 3u, 0u, 1u, 2u]));
}
2011-07-16 17:35:20 -07:00
#[test]
fn test_zip_unzip() {
2011-07-27 14:19:39 +02:00
let v1 = ~[1, 2, 3];
let v2 = ~[4, 5, 6];
2011-08-15 16:38:23 -07:00
let z1 = vec::zip(v1, v2);
2011-07-16 17:35:20 -07:00
2011-08-15 14:32:58 +02:00
assert ((1, 4) == z1.(0));
assert ((2, 5) == z1.(1));
assert ((3, 6) == z1.(2));
2011-07-16 17:35:20 -07:00
2011-08-15 16:38:23 -07:00
let (left, right) = vec::unzip(z1);
2011-07-16 17:35:20 -07:00
2011-08-15 14:32:58 +02:00
assert ((1, 4) == (left.(0), right.(0)));
assert ((2, 5) == (left.(1), right.(1)));
assert ((3, 6) == (left.(2), right.(2)));
2011-07-16 17:35:20 -07:00
}
#[test]
fn test_position() {
let v1: [int] = ~[1, 2, 3, 3, 2, 5];
assert (position(1, v1) == option::some::<uint>(0u));
assert (position(2, v1) == option::some::<uint>(1u));
assert (position(5, v1) == option::some::<uint>(5u));
assert (position(4, v1) == option::none::<uint>);
}
#[test]
fn test_position_pred() {
fn less_than_three(i: &int) -> bool { ret i < 3; }
fn is_eighteen(i: &int) -> bool { ret i == 18; }
let v1: [int] = ~[5, 4, 3, 2, 1];
assert (position_pred(less_than_three, v1) == option::some::<uint>(3u));
assert (position_pred(is_eighteen, v1) == option::none::<uint>);
}
#[test]
fn reverse_and_reversed() {
let v: [mutable int] = ~[mutable 10, 20];
assert (v.(0) == 10);
assert (v.(1) == 20);
2011-08-15 16:38:23 -07:00
vec::reverse(v);
assert (v.(0) == 20);
assert (v.(1) == 10);
let v2 = vec::reversed::<int>(~[10, 20]);
assert (v2.(0) == 20);
assert (v2.(1) == 10);
v.(0) = 30;
assert (v2.(0) == 20);
// Make sure they work with 0-length vectors too.
let v4 = vec::reversed::<int>(~[]);
let v3: [mutable int] = ~[mutable];
vec::reverse::<int>(v3);
}
// Local Variables:
// mode: rust;
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
// End: