Skip to content

Commit

Permalink
Add tests for the --timezone flag
Browse files Browse the repository at this point in the history
Elected to add test for a specific timezone, rather than merely for "a timezone" -- seems like a better test.
  • Loading branch information
simonwiles committed Sep 18, 2023
1 parent 812d473 commit ba38604
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ mod tests {
use self::Op::*;
use self::Out::*;
use super::*;
use regex::Regex;
use std::io::{BufReader, Read};
use std::thread::sleep;
use std::time::Duration;
Expand All @@ -316,6 +317,8 @@ mod tests {
Line(&'static str),
Spacer,
RightSpacer,
SpacerWithLondonTimezone,
RightSpacerWithLondonTimezone,
}

struct TimedInput {
Expand Down Expand Up @@ -438,6 +441,34 @@ mod tests {
}
; "padding = 2"
)]
#[test_case(
vec![WriteLn("foo"), Sleep(300)],
vec![Line("foo"), SpacerWithLondonTimezone],
Args {
after: 0.1,
dash: '-',
padding: 0,
no_color: true,
force_color: false,
right: false,
timezone: Some("Europe/London".to_string()),
}
; "with timezone"
)]
#[test_case(
vec![WriteLn("foo"), Sleep(300)],
vec![Line("foo"), RightSpacerWithLondonTimezone],
Args {
after: 0.1,
dash: '-',
padding: 0,
no_color: true,
force_color: false,
right: true,
timezone: Some("Europe/London".to_string()),
}
; "right spacer with timezone"
)]
fn test_output(ops: Vec<Op>, out: Vec<Out>, args: Args) -> Result<()> {
let mut total_sleep_ms = 0;
for op in ops.iter() {
Expand Down Expand Up @@ -468,6 +499,16 @@ mod tests {
Line(expected) => assert_eq!(line, expected),
Spacer => assert!(line.ends_with("----")),
RightSpacer => assert!(line.starts_with("----")),
SpacerWithLondonTimezone => {
let re = Regex::new(r"GMT|BST").unwrap();
assert!(re.is_match(line));
assert!(line.ends_with("----"));
}
RightSpacerWithLondonTimezone => {
let re = Regex::new(r"GMT|BST").unwrap();
assert!(re.is_match(line));
assert!(line.starts_with("----"));
}
}
}

Expand Down

0 comments on commit ba38604

Please sign in to comment.