Skip to content

Commit

Permalink
Cargo updates. And s/str/string/g
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntSushi committed Aug 31, 2014
1 parent f723498 commit c1aab7b
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 45 deletions.
12 changes: 1 addition & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
language: c
install:
- curl -O 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
&& mkdir -p ./build/
&& rustc ./quickcheck/src/lib.rs --out-dir ./build/
&& make test

language: rust
20 changes: 20 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ name = "csv"
version = "0.1.0"
authors = ["Andrew Gallant <[email protected]>"]

[[lib]]
[lib]
name = "csv"
path = "src/lib.rs"
crate_type = ["dylib", "rlib"]

# [dependencies.quickcheck]
# git = "git:https://github.com/BurntSushi/quickcheck"
[dependencies.quickcheck]
git = "git:https://github.com/BurntSushi/quickcheck"

3 changes: 2 additions & 1 deletion examples/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::comm::channel;
use std::io::{ChanReader, ChanWriter, Reader, Writer};
use std::io::timer::sleep;
use std::task::spawn;
use std::time::Duration;

use csv::{Decoder, Encoder};

Expand All @@ -17,7 +18,7 @@ fn main() {
Ok(_) => {},
Err(err) => fail!("Failed encoding: {}", err),
}
sleep(500);
sleep(Duration::milliseconds(500));
}
});

Expand Down
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
//! An iterator is provided to repeat this for all records in the CSV data:
//!
//! ```rust
//! ```
//! let mut rdr = csv::Decoder::from_str("andrew,1987\nkait,1989");
//! for (name, birth) in rdr.decode_iter::<(String, uint)>() {
//! println!("Name: {}, Born: {}", name, birth);
Expand Down Expand Up @@ -166,13 +165,13 @@
//! decoder:
//!
//! ```
//! let mut enc = csv::Encoder::str_encoder();
//! let mut enc = csv::Encoder::string_encoder();
//! enc.encode(("andrew", 1987u)).unwrap();
//! enc.encode(("kait", 1989u)).unwrap();
//! assert_eq!(enc.to_string(), "andrew,1987\nkait,1989\n");
//! ```
//!
//! Note that `Encoder::str_encoder` creates a convenience encoder for
//! Note that `Encoder::string_encoder` creates a convenience encoder for
//! strings. You can encode to any `Writer` (with `to_writer`) or to a file:
//!
//! ```no_run
Expand Down Expand Up @@ -205,6 +204,7 @@
//! use std::io::{ChanReader, ChanWriter, Reader, Writer};
//! use std::io::timer::sleep;
//! use std::task::spawn;
//! use std::time::Duration;
//!
//! use csv::{Decoder, Encoder};
//!
Expand All @@ -218,7 +218,7 @@
//! Ok(_) => {},
//! Err(err) => fail!("Failed encoding: {}", err),
//! }
//! sleep(1000);
//! sleep(Duration::seconds(1));
//! }
//! });
//!
Expand Down Expand Up @@ -305,12 +305,12 @@ pub struct Encoder<W> {
impl Encoder<MemWriter> {
/// Creates a new CSV string encoder. At any time, `to_str` can be called
/// to retrieve the cumulative CSV data.
pub fn str_encoder() -> Encoder<MemWriter> {
pub fn string_encoder() -> Encoder<MemWriter> {
Encoder::to_writer(MemWriter::new())
}

/// Returns the encoded CSV data as a string.
pub fn to_str<'r>(&'r self) -> &'r str {
pub fn to_string<'r>(&'r self) -> &'r str {
str::from_utf8(self.buf.get_ref()).unwrap()
}
}
Expand Down Expand Up @@ -987,7 +987,7 @@ impl<R: Reader> Decoder<R> {

/// An iterator that yields records as plain vectors of strings. This
/// completely avoids the decoding machinery.
pub struct Records<'a, R> {
pub struct Records<'a, R: 'a> {
dec: &'a mut Decoder<R>
}

Expand All @@ -1009,7 +1009,7 @@ impl<'a, R: Reader> Iterator<Vec<String>> for Records<'a, R> {
}

/// An iterator that yields decoded items.
pub struct DecodedItems<'a, R, D> {
pub struct DecodedItems<'a, R: 'a, D> {
dec: &'a mut Decoder<R>
}

Expand Down
44 changes: 22 additions & 22 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ fn same_record() {
return TestResult::discard()
}

let mut senc = Encoder::str_encoder();
let mut senc = Encoder::string_encoder();
ordie(senc.encode(input.as_slice()));

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

TestResult::from_bool(input == output)
Expand All @@ -31,30 +31,30 @@ fn same_record() {

#[test]
fn encoder_simple() {
let mut senc = Encoder::str_encoder();
let mut senc = Encoder::string_encoder();
ordie(senc.encode(("springsteen", 's', 1i, 0.14f64, false)));
assert_eq!("springsteen,s,1,0.14,false\n", senc.to_str());
assert_eq!("springsteen,s,1,0.14,false\n", senc.to_string());
}

#[test]
fn encoder_simple_crlf() {
let mut senc = Encoder::str_encoder();
let mut senc = Encoder::string_encoder();
senc.crlf(true);
ordie(senc.encode(("springsteen", 's', 1i, 0.14f64, false)));
assert_eq!("springsteen,s,1,0.14,false\r\n", senc.to_str());
assert_eq!("springsteen,s,1,0.14,false\r\n", senc.to_string());
}

#[test]
fn encoder_simple_tabbed() {
let mut senc = Encoder::str_encoder();
let mut senc = Encoder::string_encoder();
senc.separator('\t');
ordie(senc.encode(("springsteen", 's', 1i, 0.14f64, false)));
assert_eq!("springsteen\ts\t1\t0.14\tfalse\n", senc.to_str());
assert_eq!("springsteen\ts\t1\t0.14\tfalse\n", senc.to_string());
}

#[test]
fn encoder_same_length_records() {
let mut senc = Encoder::str_encoder();
let mut senc = Encoder::string_encoder();
senc.enforce_same_length(true);
ordie(senc.encode(vec!('a')));
match senc.encode(vec!('a', 'b')) {
Expand All @@ -67,29 +67,29 @@ fn encoder_same_length_records() {

#[test]
fn encoder_quoted_quotes() {
let mut senc = Encoder::str_encoder();
let mut senc = Encoder::string_encoder();
ordie(senc.encode(vec!("sprin\"g\"steen")));
assert_eq!("\"sprin\"\"g\"\"steen\"\n", senc.to_str());
assert_eq!("\"sprin\"\"g\"\"steen\"\n", senc.to_string());
}

#[test]
fn encoder_quoted_sep() {
let mut senc = Encoder::str_encoder();
let mut senc = Encoder::string_encoder();
senc.separator(',');
ordie(senc.encode(vec!("spring,steen")));
assert_eq!("\"spring,steen\"\n", senc.to_str());
assert_eq!("\"spring,steen\"\n", senc.to_string());
}

#[test]
fn encoder_quoted_newlines() {
let mut senc = Encoder::str_encoder();
let mut senc = Encoder::string_encoder();
ordie(senc.encode(vec!("spring\nsteen")));
assert_eq!("\"spring\nsteen\"\n", senc.to_str());
assert_eq!("\"spring\nsteen\"\n", senc.to_string());
}

#[test]
fn encoder_zero() {
let mut senc = Encoder::str_encoder();
let mut senc = Encoder::string_encoder();
match senc.encode::<Vec<int>>(vec!()) {
Ok(_) => fail!("Encoder should report an error when trying to \
encode records of length 0."),
Expand Down Expand Up @@ -249,25 +249,25 @@ fn decoder_option() {
#[test]
fn encoder_enum() {
let r = (Red,);
let mut senc = Encoder::str_encoder();
let mut senc = Encoder::string_encoder();
ordie(senc.encode(r));
assert_eq!("Red\n", senc.to_str());
assert_eq!("Red\n", senc.to_string());
}

#[test]
fn encoder_enum_arg() {
let r = (Bool(false), Signed(-5), Unsigned(5));
let mut senc = Encoder::str_encoder();
let mut senc = Encoder::string_encoder();
ordie(senc.encode(r));
assert_eq!("false,-5,5\n", senc.to_str());
assert_eq!("false,-5,5\n", senc.to_string());
}

#[test]
fn encoder_option() {
let r: (Option<bool>, uint) = (None, 1);
let mut senc = Encoder::str_encoder();
let mut senc = Encoder::string_encoder();
ordie(senc.encode(r));
assert_eq!(",1\n", senc.to_str());
assert_eq!(",1\n", senc.to_string());
}

#[test]
Expand Down

0 comments on commit c1aab7b

Please sign in to comment.