Skip to content

Commit

Permalink
Update for new Box syntax and use Rust nightlies for Travis.
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntSushi committed May 14, 2014
1 parent 0b37582 commit 0ffce0d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 67 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ bench-runner
doc
tags
examples/data/ss10pusa.csv
*.rlib
*.so
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
language: c
before_install:
- yes | sudo add-apt-repository ppa:hansjorg/rust
- sudo apt-get update
install:
- sudo apt-get install rust-nightly
- curl -O http:https://static.rust-lang.org/dist/rust-nightly-x86_64-unknown-linux-gnu.tar.gz
- tar xfz rust-nightly-x86_64-unknown-linux-gnu.tar.gz
- (cd rust-nightly-x86_64-unknown-linux-gnu/ && sudo ./install.sh)
script:
- git clone git:https://github.com/BurntSushi/quickcheck
&& rustc --crate-type lib ./quickcheck/src/lib.rs
&& rustc -L . --crate-type lib ./src/lib.rs
&& rustc ./quickcheck/src/lib.rs
&& make test

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test: test-runner
RUST_TEST_TASKS=1 RUST_LOG=quickcheck,csv ./test-runner

test-runner: src/lib.rs src/test.rs src/bench.rs
rustc --test src/lib.rs -o test-runner
rustc -L . --test src/lib.rs -o test-runner

test-examples:
(cd ./examples && ./test)
Expand Down
30 changes: 16 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![crate_id = "csv#0.1.0"]
#![crate_type = "lib"]
#![crate_type = "rlib"]
#![crate_type = "dylib"]
#![license = "UNLICENSE"]
#![doc(html_root_url = "http:https://burntsushi.net/rustdoc/csv")]

Expand Down Expand Up @@ -267,15 +268,16 @@
//!
//! Everything else should be supported, including new lines in quoted values.

// Dunno what this is, but apparently it's required for the 'log' crate.
#![feature(phase)]

#[phase(syntax, link)] extern crate log;
// extern crate quickcheck;
extern crate rand;
extern crate serialize;
extern crate stdtest = "test";

#[cfg(test)]
extern crate quickcheck;

use std::default::Default;
use std::fmt;
use std::from_str::FromStr;
Expand All @@ -288,6 +290,12 @@ use std::path::Path;
use std::str;
use serialize::{Encodable, Decodable};

#[cfg(test)]
mod bench;

#[cfg(test)]
mod test;

/// A convenience encoder for encoding CSV data to strings.
pub struct StrEncoder<'a> {
/// The underlying Encoder. Options like the separator, line endings and
Expand All @@ -299,14 +307,14 @@ pub struct StrEncoder<'a> {
/// isn't going to cause an IO error, but an error could be caused by
/// writing records of varying length if same length records are enforced.)
pub encoder: Encoder<'a>,
w: ~MemWriter,
w: Box<MemWriter>,
}

impl<'a> StrEncoder<'a> {
/// Creates a new CSV string encoder. At any time, `to_str` can be called
/// to retrieve the cumulative CSV data.
pub fn new() -> StrEncoder<'a> {
let mut w = ~MemWriter::new();
let mut w = box MemWriter::new();
let enc = Encoder::to_writer(&mut *w as &mut Writer);
StrEncoder {
encoder: enc,
Expand Down Expand Up @@ -353,7 +361,7 @@ impl<'a> Encoder<'a> {
/// before writing.
pub fn to_file(path: &Path) -> Encoder<'a> {
let file = File::create(path);
Encoder::to_writer(~file as ~Writer)
Encoder::to_writer(box file as Box<Writer>)
}

/// Creates an encoder that encodes CSV data with the `Writer` given.
Expand Down Expand Up @@ -862,7 +870,7 @@ impl<'a> Decoder<'a> {
/// Creates a new CSV decoder from a file using the file path given.
pub fn from_file(path: &Path) -> Decoder<'a> {
let file = File::open(path);
Decoder::from_reader(~file as ~Reader)
Decoder::from_reader(box file as Box<Reader>)
}

/// Creates a new CSV decoder that reads CSV data from the `Reader` given.
Expand All @@ -883,7 +891,7 @@ impl<'a> Decoder<'a> {
/// Creates a new CSV decoder that reads CSV data from the string given.
pub fn from_str(s: &str) -> Decoder<'a> {
let r = MemReader::new(Vec::from_slice(s.as_bytes()));
Decoder::from_reader(~r as ~Reader)
Decoder::from_reader(box r as Box<Reader>)
}

fn from_buffer(buf: BufferedReader<&'a mut Reader>) -> Decoder<'a> {
Expand Down Expand Up @@ -1289,9 +1297,3 @@ impl<'a> serialize::Decoder<Error> for Decoder<'a> {
fn to_lower(s: &str) -> ~str {
s.chars().map(|c| c.to_lowercase()).collect()
}

#[cfg(test)]
mod bench;

#[cfg(test)]
mod test;
67 changes: 21 additions & 46 deletions src/test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// use quickcheck::{TestResult, quickcheck};
use quickcheck::{TestResult, quickcheck};
use super::{StrEncoder, Decoder};

fn ordie<T, E: ::std::fmt::Show>(res: Result<T, E>) -> T {
Expand All @@ -8,51 +8,26 @@ fn ordie<T, E: ::std::fmt::Show>(res: Result<T, E>) -> T {
}
}

// #[test]
// fn same_record() {
// fn prop(input: Vec<~str>) -> TestResult {
// if input.len() == 0 {
// return TestResult::discard()
// }
// if input.iter().any(|s| s.len() == 0) {
// return TestResult::discard()
// }
//
// let mut senc = StrEncoder::new();
// senc.encode(input.as_slice());
//
// let mut dec = Decoder::from_str(senc.to_str());
// let output: Vec<~str> = ordie(dec.decode());
//
// TestResult::from_bool(input == output)
// }
// quickcheck(prop);
// }
//
// #[test]
// fn same_records() {
// fn prop(to_repeat: Vec<~str>, n: uint) -> TestResult {
// // Discard empty vectors or zero repetitions of that vector.
// // Also discard vectors with empty strings since they are written
// // just as empty lines, which are ignored by the decoder.
// if to_repeat.len() == 0 || n == 0 {
// return TestResult::discard()
// }
// // if to_repeat.iter().any(|s| s.len() == 0) {
// // return TestResult::discard()
// // }
//
// let input = Vec::from_fn(n, |_| to_repeat.clone());
// let mut senc = StrEncoder::new();
// senc.encode_all(input.as_slice());
//
// let mut dec = Decoder::from_str(senc.to_str());
// let output: Vec<Vec<~str>> = ordie(dec.decode_all());
//
// TestResult::from_bool(input == output)
// }
// quickcheck(prop);
// }
#[test]
fn same_record() {
fn prop(input: Vec<~str>) -> TestResult {
if input.len() == 0 {
return TestResult::discard()
}
if input.iter().any(|s| s.len() == 0) {
return TestResult::discard()
}

let mut senc = StrEncoder::new();
senc.encode(input.as_slice());

let mut dec = Decoder::from_str(senc.to_str());
let output: Vec<~str> = ordie(dec.decode());

TestResult::from_bool(input == output)
}
quickcheck(prop);
}

#[test]
fn encoder_simple() {
Expand Down

0 comments on commit 0ffce0d

Please sign in to comment.