Skip to content

Commit

Permalink
watch: move tests to the bottom of the file
Browse files Browse the repository at this point in the history
  • Loading branch information
cakebaker committed Apr 2, 2024
1 parent 94c8f17 commit ab25403
Showing 1 changed file with 55 additions and 55 deletions.
110 changes: 55 additions & 55 deletions src/uu/watch/src/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,61 +94,6 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
Ok(())
}

#[cfg(test)]
mod parse_interval_tests {
use super::*;

#[test]
fn test_comma_parse() {
let interval = parse_interval("1,5");
assert_eq!(Ok(Duration::from_millis(1500)), interval);
}

#[test]
fn test_different_nanos_length() {
let interval = parse_interval("1.12345");
assert_eq!(Ok(Duration::new(1, 123450000)), interval);
let interval = parse_interval("1.1234");
assert_eq!(Ok(Duration::new(1, 123400000)), interval);
}

#[test]
fn test_period_parse() {
let interval = parse_interval("1.5");
assert_eq!(Ok(Duration::from_millis(1500)), interval);
}

#[test]
fn test_empty_seconds_interval() {
let interval = parse_interval(".5");
assert_eq!(Ok(Duration::from_millis(500)), interval);
}

#[test]
fn test_seconds_only() {
let interval = parse_interval("7");
assert_eq!(Ok(Duration::from_secs(7)), interval);
}

#[test]
fn test_empty_nanoseconds_interval() {
let interval = parse_interval("1.");
assert_eq!(Ok(Duration::from_millis(1000)), interval);
}

#[test]
fn test_too_many_nanos() {
let interval = parse_interval("1.00000000009");
assert_eq!(Ok(Duration::from_secs(1)), interval);
}

#[test]
fn test_invalid_nano() {
let interval = parse_interval("1.00000000000a");
assert!(interval.is_err())
}
}

pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.version(crate_version!())
Expand Down Expand Up @@ -243,3 +188,58 @@ pub fn uu_app() -> Command {
.help("Pass command to exec instead of 'sh -c'"),
)
}

#[cfg(test)]
mod parse_interval_tests {
use super::*;

#[test]
fn test_comma_parse() {
let interval = parse_interval("1,5");
assert_eq!(Ok(Duration::from_millis(1500)), interval);
}

#[test]
fn test_different_nanos_length() {
let interval = parse_interval("1.12345");
assert_eq!(Ok(Duration::new(1, 123450000)), interval);
let interval = parse_interval("1.1234");
assert_eq!(Ok(Duration::new(1, 123400000)), interval);
}

#[test]
fn test_period_parse() {
let interval = parse_interval("1.5");
assert_eq!(Ok(Duration::from_millis(1500)), interval);
}

#[test]
fn test_empty_seconds_interval() {
let interval = parse_interval(".5");
assert_eq!(Ok(Duration::from_millis(500)), interval);
}

#[test]
fn test_seconds_only() {
let interval = parse_interval("7");
assert_eq!(Ok(Duration::from_secs(7)), interval);
}

#[test]
fn test_empty_nanoseconds_interval() {
let interval = parse_interval("1.");
assert_eq!(Ok(Duration::from_millis(1000)), interval);
}

#[test]
fn test_too_many_nanos() {
let interval = parse_interval("1.00000000009");
assert_eq!(Ok(Duration::from_secs(1)), interval);
}

#[test]
fn test_invalid_nano() {
let interval = parse_interval("1.00000000000a");
assert!(interval.is_err())
}
}

0 comments on commit ab25403

Please sign in to comment.