Skip to content

Commit

Permalink
Test case for impl () for WhenceUniverse.
Browse files Browse the repository at this point in the history
  • Loading branch information
kpreid committed Jan 14, 2024
1 parent 63de067 commit 4be26e5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions all-is-cubes-wasm/Cargo.lock

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

1 change: 1 addition & 0 deletions all-is-cubes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ embedded-graphics = "0.8.0"
exhaust = { workspace = true, default-features = false }
flate2 = { version = "1.0.26", optional = true }
futures-core = { workspace = true }
futures-util = { workspace = true }
hashbrown = { workspace = true }
indoc = { workspace = true }
itertools = { workspace = true }
Expand Down
2 changes: 2 additions & 0 deletions all-is-cubes/src/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ pub trait WhenceUniverse: fmt::Debug + Send + Sync + downcast_rs::Downcast + 'st
downcast_rs::impl_downcast!(WhenceUniverse);

/// Implementation of [`WhenceUniverse`] used by [`Universe`]s freshly created.
//---
// Tests for this implementation may be found in `crate::universe::tests`.
impl WhenceUniverse for () {
fn document_name(&self) -> Option<String> {
None
Expand Down
30 changes: 29 additions & 1 deletion all-is-cubes/src/universe/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use alloc::sync::Arc;
use alloc::vec::Vec;
use core::any::TypeId;

use futures_util::FutureExt as _;
use indoc::indoc;

use crate::block::{Block, BlockDef, BlockDefTransaction, Resolution, TickAction, AIR};
Expand All @@ -17,7 +18,7 @@ use crate::universe::{
self, list_refs, InsertError, InsertErrorKind, Name, RefError, URef, Universe,
UniverseTransaction,
};
use crate::util::assert_conditional_send_sync;
use crate::util::{assert_conditional_send_sync, yield_progress_for_testing};
use crate::{behavior, time};

#[test]
Expand Down Expand Up @@ -83,6 +84,33 @@ fn universe_debug_elements() {
);
}

#[test]
fn universe_default_whence() {
let u = Universe::new();
let whence = &u.whence;
assert_eq!(whence.document_name(), None);
assert!(!whence.can_load());
assert!(!whence.can_save());
assert_eq!(
whence
.load(yield_progress_for_testing())
.now_or_never()
.unwrap()
.unwrap_err()
.to_string(),
"this universe cannot be reloaded because it has no source"
);
assert_eq!(
whence
.save(&u, yield_progress_for_testing())
.now_or_never()
.unwrap()
.unwrap_err()
.to_string(),
"this universe cannot be saved because a destination has not been specified"
);
}

#[test]
fn get_any() {
let mut u = Universe::new();
Expand Down

0 comments on commit 4be26e5

Please sign in to comment.