From 4be26e54d6fc82d231d494c6cdcbcfd19bc3ccb8 Mon Sep 17 00:00:00 2001 From: Kevin Reid Date: Sun, 14 Jan 2024 11:46:59 -0800 Subject: [PATCH] Test case for `impl () for WhenceUniverse`. --- Cargo.lock | 1 + all-is-cubes-wasm/Cargo.lock | 1 + all-is-cubes/Cargo.toml | 1 + all-is-cubes/src/save.rs | 2 ++ all-is-cubes/src/universe/tests.rs | 30 +++++++++++++++++++++++++++++- 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index aaefc5c54..854f1edfc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -58,6 +58,7 @@ dependencies = [ "exhaust", "flate2", "futures-core", + "futures-util", "hashbrown 0.14.3", "indoc", "itertools 0.12.0", diff --git a/all-is-cubes-wasm/Cargo.lock b/all-is-cubes-wasm/Cargo.lock index aa95f1c80..c293d7971 100644 --- a/all-is-cubes-wasm/Cargo.lock +++ b/all-is-cubes-wasm/Cargo.lock @@ -46,6 +46,7 @@ dependencies = [ "exhaust", "flate2", "futures-core", + "futures-util", "hashbrown 0.14.3", "indoc", "itertools 0.12.0", diff --git a/all-is-cubes/Cargo.toml b/all-is-cubes/Cargo.toml index 8a59d49b2..b3f8658cc 100644 --- a/all-is-cubes/Cargo.toml +++ b/all-is-cubes/Cargo.toml @@ -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 } diff --git a/all-is-cubes/src/save.rs b/all-is-cubes/src/save.rs index 257dc4db7..7624548cd 100644 --- a/all-is-cubes/src/save.rs +++ b/all-is-cubes/src/save.rs @@ -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 { None diff --git a/all-is-cubes/src/universe/tests.rs b/all-is-cubes/src/universe/tests.rs index a93dca113..caadd446a 100644 --- a/all-is-cubes/src/universe/tests.rs +++ b/all-is-cubes/src/universe/tests.rs @@ -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}; @@ -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] @@ -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();