Skip to content

Commit

Permalink
Merge pull request #390 from hyperium/strptime
Browse files Browse the repository at this point in the history
Add tests for header::parsing::tm_from_str and run benchmarks on travis.
  • Loading branch information
reem committed Mar 23, 2015
2 parents 5d93a3b + 2647864 commit 89191cc
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sudo: false
script:
- cargo build
- cargo test
- cargo bench --no-run
- cargo bench

after_success: |
[ $TRAVIS_BRANCH = master ] &&
Expand Down
35 changes: 0 additions & 35 deletions benches/server.rs

This file was deleted.

43 changes: 41 additions & 2 deletions src/header/parsing.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//! Utility functions for Header implementations.

extern crate time;

use std::str;
use std::fmt;
use time;

/// Reads a single raw string when parsing a header
pub fn from_one_raw_str<T: str::FromStr>(raw: &[Vec<u8>]) -> Option<T> {
Expand Down Expand Up @@ -83,3 +82,43 @@ pub fn tm_from_str(s: &str) -> Option<time::Tm> {
time::strptime(s, "%c")
}).ok()
}

#[cfg(test)]
mod tests {
use time::Tm;
use super::tm_from_str;

const NOV_07: Tm = Tm {
tm_nsec: 0,
tm_sec: 37,
tm_min: 48,
tm_hour: 8,
tm_mday: 7,
tm_mon: 10,
tm_year: 94,
tm_wday: 0,
tm_isdst: 0,
tm_yday: 0,
tm_utcoff: 0,
};

#[test]
fn test_imf_fixdate() {
assert_eq!(tm_from_str("Sun, 07 Nov 1994 08:48:37 GMT"),
Some(NOV_07));
}

#[test]
fn test_rfc_850() {
assert_eq!(tm_from_str("Sunday, 07-Nov-94 08:48:37 GMT"),
Some(NOV_07));
}

#[test]
fn test_asctime() {
assert_eq!(tm_from_str("Sun Nov 7 08:48:37 1994"),
Some(NOV_07));
}


}
34 changes: 0 additions & 34 deletions src/header/shared/time.rs

This file was deleted.

0 comments on commit 89191cc

Please sign in to comment.