Implement pretty-printing of .. and update tests.

Update tests to change all `&expr[]` to `&expr[..]` to make sure pretty printing
passes.
This commit is contained in:
Ulrik Sverdrup 2015-02-05 17:58:30 +01:00
parent 75239142a8
commit 7d527fa96b
13 changed files with 23 additions and 28 deletions

View File

@ -1813,9 +1813,7 @@ impl<'a> State<'a> {
if let &Some(ref e) = start {
try!(self.print_expr(&**e));
}
if start.is_some() || end.is_some() {
try!(word(&mut self.s, ".."));
}
try!(word(&mut self.s, ".."));
if let &Some(ref e) = end {
try!(self.print_expr(&**e));
}

View File

@ -180,7 +180,7 @@ impl<'a, W: Writer> RandomFasta<'a, W> {
fn nextc(&mut self) -> u8 {
let r = self.rng(1.0);
for a in &self.lookup[] {
for a in &self.lookup[..] {
if a.p >= r {
return a.c;
}

View File

@ -32,6 +32,6 @@ fn main() {
let foo = Foo { bar: [1u8, 2, 3, 4, 5], baz: 10i32 };
unsafe {
let oof: Oof<[u8; 5], i32> = mem::transmute(foo);
println!("{:?} {:?}", &oof.rab[], oof.zab);
println!("{:?} {:?}", &oof.rab[..], oof.zab);
}
}

View File

@ -35,7 +35,7 @@ fn test_rbml<'a, 'b, A:
let mut rbml_w = EBwriter::Encoder::new(&mut wr);
a1.encode(&mut rbml_w);
let d: serialize::rbml::Doc<'a> = EBDoc::new(&wr[]);
let d: serialize::rbml::Doc<'a> = EBDoc::new(&wr);
let mut decoder: EBReader::Decoder<'a> = EBreader::Decoder::new(d);
let a2: A = Decodable::decode(&mut decoder);
assert!(*a1 == a2);

View File

@ -47,11 +47,11 @@ fn use_slice(_: &[u8]) {}
fn use_slice_mut(_: &mut [u8]) {}
fn use_vec(mut v: Vec<u8>) {
use_slice_mut(&mut v[]); // what you have to write today
use_slice_mut(&mut v); // what you'd be able to write
use_slice_mut(&mut v[..]); // what you have to write today
use_slice_mut(&mut v); // what you'd be able to write
use_slice_mut(&mut &mut &mut v);
use_slice(&v[]); // what you have to write today
use_slice(&v[..]); // what you have to write today
use_slice(&v); // what you'd be able to write
use_slice(&&&&&&v);
use_slice(&mut &&&&&v);
@ -59,7 +59,7 @@ fn use_vec(mut v: Vec<u8>) {
}
fn use_vec_ref(v: &Vec<u8>) {
use_slice(&v[]); // what you have to write today
use_slice(&v[..]); // what you have to write today
use_slice(v); // what you'd be able to write
use_slice(&&&&&&v);
use_slice(&mut &&&&&v);

View File

@ -59,7 +59,7 @@ fn roundtrip<'a, T: Rand + Eq + Encodable<Encoder<'a>> +
let mut w = Vec::new();
let mut e = Encoder::new(&mut w);
obj.encode(&mut e);
let doc = rbml::Doc::new(&w[]);
let doc = rbml::Doc::new(&w);
let mut dec = Decoder::new(doc);
let obj2 = Decodable::decode(&mut dec);
assert!(obj == obj2);

View File

@ -11,7 +11,7 @@
pub fn main() {
let x = [1; 100];
let mut y = 0;
for i in &x[] {
for i in &x[..] {
if y > 10 {
break;
}

View File

@ -13,8 +13,8 @@ pub fn main() {
let y = [2; 100];
let mut p = 0;
let mut q = 0;
for i in &x[] {
for j in &y[] {
for i in &x[..] {
for j in &y[..] {
p += *j;
}
q += *i + p;

View File

@ -11,7 +11,7 @@
pub fn main() {
let x = [1; 100];
let mut y = 0;
for i in &x[] {
for i in &x[..] {
y += *i
}
assert!(y == 100);

View File

@ -18,9 +18,9 @@ pub fn main() {
let x = [(), ()];
let slice = &x[..1];
assert_repr_eq(&abc[], "[1, 2, 3]".to_string());
assert_repr_eq(&tf[], "[true, false]".to_string());
assert_repr_eq(&x[], "[(), ()]".to_string());
assert_repr_eq(&abc[..], "[1, 2, 3]".to_string());
assert_repr_eq(&tf[..], "[true, false]".to_string());
assert_repr_eq(&x[..], "[(), ()]".to_string());
assert_repr_eq(slice, "[()]".to_string());
assert_repr_eq(&x[], "[(), ()]".to_string());
assert_repr_eq(&x[..], "[(), ()]".to_string());
}

View File

@ -13,9 +13,9 @@ pub fn main() {
let y = [ 0; 1 ];
print!("[");
for xi in &x[] {
print!("{:?}, ", &xi[]);
for xi in &x[..] {
print!("{:?}, ", &xi[..]);
}
println!("]");
println!("{:?}", &y[]);
println!("{:?}", &y[..]);
}

View File

@ -13,7 +13,6 @@
fn main() {
let x: &[int] = &[1, 2, 3, 4, 5];
let cmp: &[int] = &[1, 2, 3, 4, 5];
assert!(&x[] == cmp);
assert!(&x[..] == cmp);
let cmp: &[int] = &[3, 4, 5];
assert!(&x[2..] == cmp);
@ -24,7 +23,7 @@ fn main() {
let x: Vec<int> = vec![1, 2, 3, 4, 5];
let cmp: &[int] = &[1, 2, 3, 4, 5];
assert!(&x[] == cmp);
assert!(&x[..] == cmp);
let cmp: &[int] = &[3, 4, 5];
assert!(&x[2..] == cmp);
let cmp: &[int] = &[1, 2, 3];
@ -35,7 +34,6 @@ fn main() {
let x: &mut [int] = &mut [1, 2, 3, 4, 5];
{
let cmp: &mut [int] = &mut [1, 2, 3, 4, 5];
assert!(&mut x[] == cmp);
assert!(&mut x[..] == cmp);
}
{
@ -54,7 +52,6 @@ fn main() {
let mut x: Vec<int> = vec![1, 2, 3, 4, 5];
{
let cmp: &mut [int] = &mut [1, 2, 3, 4, 5];
assert!(&mut x[] == cmp);
assert!(&mut x[..] == cmp);
}
{

View File

@ -80,11 +80,11 @@ impl IndexMut<RangeFull> for Foo {
fn main() {
let mut x = Foo;
&x[];
&x[..];
&x[Foo..];
&x[..Foo];
&x[Foo..Foo];
&mut x[];
&mut x[..];
&mut x[Foo..];
&mut x[..Foo];
&mut x[Foo..Foo];