提交 491ed7f1 编写于 作者: E Erick Tryzelaar 提交者: Brian Anderson

Port the fuzzer and tests to ivec type [T] syntax.

上级 8b150452
use std;
import std::ivec;
fn ivec_equal[T](v: &T[], u: &T[], element_equality_test: fn(&T, &T) -> bool )
fn ivec_equal[T](v: &[T], u: &[T], element_equality_test: fn(&T, &T) -> bool )
-> bool {
let Lv = ivec::len(v);
if Lv != ivec::len(u) { ret false; }
......@@ -24,4 +24,4 @@ fn main() {
assert (ivec_equal(~[5, 5], ~[5, 5], builtin_equal));
log_err "Pass";
}
\ No newline at end of file
}
......@@ -38,7 +38,7 @@ fn contains(haystack: &str, needle: &str) -> bool {
str::find(haystack, needle) != -1
}
fn find_rust_files(files: &mutable str[], path: str) {
fn find_rust_files(files: &mutable [str], path: str) {
if str::ends_with(path, ".rs") {
if file_contains(path, "xfail-stage1") {
//log_err "Skipping " + path + " because it is marked as xfail-stage1";
......@@ -89,10 +89,10 @@ fn safe_to_steal(e: ast::expr_) -> bool {
}
}
fn steal_exprs(crate: &ast::crate) -> ast::expr[] {
let exprs: @mutable ast::expr[] = @mutable ~[];
fn steal_exprs(crate: &ast::crate) -> [ast::expr] {
let exprs: @mutable [ast::expr] = @mutable ~[];
// "Stash" is not type-parameterized because of the need for safe_to_steal
fn stash_expr(es: @mutable ast::expr[], e: &@ast::expr) {
fn stash_expr(es: @mutable [ast::expr], e: &@ast::expr) {
if safe_to_steal(e.node) {
*es += ~[*e];
} else {/* now my indices are wrong :( */ }
......@@ -316,7 +316,7 @@ fn check_roundtrip_convergence(code: &str, maxIters: uint) {
}
}
fn check_convergence(files: &str[]) {
fn check_convergence(files: &[str]) {
log_err #fmt("pp convergence tests: %u files", ivec::len(files));
for file in files {
if !file_is_confusing(file) {
......@@ -330,7 +330,7 @@ fn check_convergence(files: &str[]) {
}
}
fn check_variants(files: &str[]) {
fn check_variants(files: &[str]) {
for file in files {
if !file_is_confusing(file) {
let s = ioivec::read_whole_file_str(file);
......
......@@ -7,8 +7,8 @@
two functions, "return the number of possible edits" and "return edit #n"
It would be nice if this could be data-driven, so the two functions could share information:
type vec_modifier = rec(fn (&T[] v, uint i) -> T[] fun, uint lo, uint di);
const vec_modifier[] vec_modifiers = ~[rec(fun=vec_omit, 0u, 1u), ...];
type vec_modifier = rec(fn (&[T] v, uint i) -> [T] fun, uint lo, uint di);
const [vec_modifier] vec_modifiers = ~[rec(fun=vec_omit, 0u, 1u), ...];
But that gives me "error: internal compiler error unimplemented consts that's not a plain literal".
https://github.com/graydon/rust/issues/570
......@@ -26,24 +26,24 @@
import std::ivec::len;
import std::int;
//fn vec_reverse(&T[] v) -> T[] { ... }
//fn vec_reverse(&[T] v) -> [T] { ... }
fn vec_omit[T](v: &T[], i: uint) -> T[] {
fn vec_omit[T](v: &[T], i: uint) -> [T] {
slice(v, 0u, i) + slice(v, i + 1u, len(v))
}
fn vec_dup[T](v: &T[], i: uint) -> T[] {
fn vec_dup[T](v: &[T], i: uint) -> [T] {
slice(v, 0u, i) + ~[v.(i)] + slice(v, i, len(v))
}
fn vec_swadj[T](v: &T[], i: uint) -> T[] {
fn vec_swadj[T](v: &[T], i: uint) -> [T] {
slice(v, 0u, i) + ~[v.(i + 1u), v.(i)] + slice(v, i + 2u, len(v))
}
fn vec_prefix[T](v: &T[], i: uint) -> T[] { slice(v, 0u, i) }
fn vec_suffix[T](v: &T[], i: uint) -> T[] { slice(v, i, len(v)) }
fn vec_prefix[T](v: &[T], i: uint) -> [T] { slice(v, 0u, i) }
fn vec_suffix[T](v: &[T], i: uint) -> [T] { slice(v, i, len(v)) }
fn vec_poke[T](v: &T[], i: uint, x: &T) -> T[] {
fn vec_poke[T](v: &[T], i: uint, x: &T) -> [T] {
slice(v, 0u, i) + ~[x] + slice(v, i + 1u, len(v))
}
fn vec_insert[T](v: &T[], i: uint, x: &T) -> T[] {
fn vec_insert[T](v: &[T], i: uint, x: &T) -> [T] {
slice(v, 0u, i) + ~[x] + slice(v, i, len(v))
}
......@@ -54,8 +54,8 @@ fn vec_insert[T](v: &T[], i: uint, x: &T) -> T[] {
}
// Returns a bunch of modified versions of v, some of which introduce new elements (borrowed from xs).
fn vec_edits[T](v: &T[], xs: &T[]) -> T[][] {
let edits: T[][] = ~[];
fn vec_edits[T](v: &[T], xs: &[T]) -> [[T]] {
let edits: [[T]] = ~[];
let Lv: uint = len(v);
if Lv != 1u {
......@@ -85,7 +85,7 @@ fn vec_edits[T](v: &T[], xs: &T[]) -> T[][] {
}
// Would be nice if this were built in: https://github.com/graydon/rust/issues/424
fn vec_to_str(v: &int[]) -> str {
fn vec_to_str(v: &[int]) -> str {
let i = 0u;
let s = "[";
while i < len(v) {
......@@ -96,7 +96,7 @@ fn vec_to_str(v: &int[]) -> str {
ret s + "]";
}
fn show_edits(a: &int[], xs: &int[]) {
fn show_edits(a: &[int], xs: &[int]) {
log_err "=== Edits of " + vec_to_str(a) + " ===";
let b = vec_edits(a, xs);
for each i: uint in ix(0u, 1u, len(b)) { log_err vec_to_str(b.(i)); }
......@@ -111,4 +111,4 @@ fn demo_edits() {
show_edits(~[1, 2, 3, 4], xs);
}
fn main() { demo_edits(); }
\ No newline at end of file
fn main() { demo_edits(); }
......@@ -3,7 +3,3 @@
fn f1(x: [int]) { }
fn g1() { f1(~[1, 2, 3]); }
fn f2(x: [int]) { }
fn g2() { f2(~[1, 2, 3]); }
// pp-exact:ivec-type.pp
fn f1(x: int[]) { }
fn f1(x: [int]) { }
fn g1() { f1(~[1, 2, 3]); }
fn f2(x: [int]) { }
fn g2() { f2(~[1, 2, 3]); }
tag option[T] { some(T); none; }
type r[T] = {mutable v: (option[T])[]};
type r[T] = {mutable v: [option[T]]};
fn f[T]() -> [T] { ret ~[]; }
......
use std;
fn producer(c: chan[u8[]]) {
fn producer(c: chan[[u8]]) {
c <| ~[1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8,
8u8, 9u8, 10u8, 11u8, 12u8, 13u8 ];
}
fn main() {
let p: port[u8[]] = port();
let p: port[[u8]] = port();
let prod: task = spawn producer(chan(p));
let data: u8[];
let data: [u8];
p |> data;
}
......@@ -27,14 +27,14 @@ fn test_lefts() {
#[test]
fn test_lefts_none() {
let input: (t[int, int])[] = ~[right(10), right(10)];
let input: [t[int, int]] = ~[right(10), right(10)];
let result = lefts(input);
assert (len(result) == 0u);
}
#[test]
fn test_lefts_empty() {
let input: (t[int, int])[] = ~[];
let input: [t[int, int]] = ~[];
let result = lefts(input);
assert (len(result) == 0u);
}
......@@ -48,14 +48,14 @@ fn test_rights() {
#[test]
fn test_rights_none() {
let input: (t[int, int])[] = ~[left(10), left(10)];
let input: [t[int, int]] = ~[left(10), left(10)];
let result = rights(input);
assert (len(result) == 0u);
}
#[test]
fn test_rights_empty() {
let input: (t[int, int])[] = ~[];
let input: [t[int, int]] = ~[];
let result = rights(input);
assert (len(result) == 0u);
}
......@@ -73,7 +73,7 @@ fn test_partition() {
#[test]
fn test_partition_no_lefts() {
let input: (t[int, int])[] = ~[right(10), right(11)];
let input: [t[int, int]] = ~[right(10), right(11)];
let result = partition(input);
assert (len(result.lefts) == 0u);
assert (len(result.rights) == 2u);
......@@ -81,7 +81,7 @@ fn test_partition_no_lefts() {
#[test]
fn test_partition_no_rights() {
let input: (t[int, int])[] = ~[left(10), left(11)];
let input: [t[int, int]] = ~[left(10), left(11)];
let result = partition(input);
assert (len(result.lefts) == 2u);
assert (len(result.rights) == 0u);
......@@ -89,8 +89,8 @@ fn test_partition_no_rights() {
#[test]
fn test_partition_empty() {
let input: (t[int, int])[] = ~[];
let input: [t[int, int]] = ~[];
let result = partition(input);
assert (len(result.lefts) == 0u);
assert (len(result.rights) == 0u);
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册