Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda committed Aug 17, 2024
1 parent 60dfe75 commit aa4a735
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/system_time_success.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,11 @@ test! {
assert!(later >= earlier);
assert!(later.duration_since(earlier).unwrap() <= MAX_DIFF);
}

/// [`SystemTime::elapsed()`] failure.
async fn error() {
let time = SystemTime::now() + DIFF;
let error = time.elapsed().unwrap_err();
assert_eq!(error.to_string(), "second time provided was later than self");
}
}
38 changes: 38 additions & 0 deletions tests/web.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#![cfg(test)]
#![cfg(target_family = "wasm")]

use std::time;
use std::time::Duration;

use wasm_bindgen_test::wasm_bindgen_test;
use web_time::web::SystemTimeExt;

wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

#[wasm_bindgen_test]
fn to_std() {
assert_eq!(
web_time::SystemTime::UNIX_EPOCH.to_std(),
time::SystemTime::UNIX_EPOCH,
);

let duration = Duration::from_secs(60 * 60 * 24 * 365);
assert_eq!(
(web_time::SystemTime::UNIX_EPOCH + duration).to_std(),
time::SystemTime::UNIX_EPOCH + duration,
);
}

#[wasm_bindgen_test]
fn from_std() {
assert_eq!(
web_time::SystemTime::from_std(time::SystemTime::UNIX_EPOCH),
web_time::SystemTime::UNIX_EPOCH,
);

let duration = Duration::from_secs(60 * 60 * 24 * 365);
assert_eq!(
web_time::SystemTime::from_std(time::SystemTime::UNIX_EPOCH + duration),
web_time::SystemTime::UNIX_EPOCH + duration,
);
}

0 comments on commit aa4a735

Please sign in to comment.