Adds some testing
Build Successful The build was successful
Gitea/epoch_forge/pipeline/head This commit looks good
Details
Build Successful The build was successful
Gitea/epoch_forge/pipeline/head This commit looks good
Details
This commit is contained in:
parent
e0ef469088
commit
cecfdddfea
|
|
@ -0,0 +1,8 @@
|
|||
[last_run_clean]
|
||||
run_status = "Success"
|
||||
lines_parsed = 59
|
||||
coverage = 14.8
|
||||
|
||||
[last_run_clean.run_duration]
|
||||
secs = 23
|
||||
nanos = 833334374
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
[workspace]
|
||||
resolver = "3"
|
||||
members = ["bin_efo", "lib_efo"]
|
||||
version = "0.1"
|
||||
|
||||
[workspace.dependencies]
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
  
|
||||
|
||||
# 📦 Epoch Forge (`epoch_forge`)
|
||||
|
||||
> **A Rust-powered CLI for managing fantasy organisations across time.**
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="122" height="18" role="img" aria-label="test-coverage: 15%"><title>test-coverage: 15%</title><linearGradient id="bms-f12bf7bee0589b04" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="bmr-f12bf7bee0589b04"><rect width="122" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-f12bf7bee0589b04)"><rect width="87" height="18" fill="#555"/><rect x="87" width="35" height="18" fill="#97ca00"/><rect width="122" height="18" fill="url(#bms-f12bf7bee0589b04)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="445" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="770">test-coverage</text><text x="445" y="130" transform="scale(.1)" fill="#fff" textLength="770">test-coverage</text><text aria-hidden="true" x="1035" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="250">15%</text><text x="1035" y="130" transform="scale(.1)" fill="#fff" textLength="250">15%</text></g></svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
|
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="82" height="18" role="img" aria-label="test: passing"><title>test: passing</title><linearGradient id="bms-5402c39dce014bd3" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="bmr-5402c39dce014bd3"><rect width="82" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-5402c39dce014bd3)"><rect width="31" height="18" fill="#555"/><rect x="31" width="51" height="18" fill="#97ca00"/><rect width="82" height="18" fill="url(#bms-5402c39dce014bd3)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="165" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="210">test</text><text x="165" y="130" transform="scale(.1)" fill="#fff" textLength="210">test</text><text aria-hidden="true" x="555" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="410">passing</text><text x="555" y="130" transform="scale(.1)" fill="#fff" textLength="410">passing</text></g></svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
|
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="78" height="18" role="img" aria-label="version: 0.1"><title>version: 0.1</title><linearGradient id="bms-e7c71dea3d331ef4" x2="0" y2="100%"><stop offset="0" stop-color="#fff" stop-opacity=".7"/><stop offset=".1" stop-color="#aaa" stop-opacity=".1"/><stop offset=".9" stop-color="#000" stop-opacity=".3"/><stop offset="1" stop-color="#000" stop-opacity=".5"/></linearGradient><clipPath id="bmr-e7c71dea3d331ef4"><rect width="78" height="18" rx="4" fill="#fff"/></clipPath><g clip-path="url(#bmr-e7c71dea3d331ef4)"><rect width="51" height="18" fill="#555"/><rect x="51" width="27" height="18" fill="#fe7d37"/><rect width="78" height="18" fill="url(#bms-e7c71dea3d331ef4)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="265" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="410">version</text><text x="265" y="130" transform="scale(.1)" fill="#fff" textLength="410">version</text><text aria-hidden="true" x="635" y="140" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="170">0.1</text><text x="635" y="130" transform="scale(.1)" fill="#fff" textLength="170">0.1</text></g></svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
|
|
@ -1,6 +1,6 @@
|
|||
//! Module handling the creation of characters
|
||||
|
||||
use lib_efo::entity::{EffectApplication, EffectBounds, EntityDuration};
|
||||
use lib_efo::entity::{EffectApplication, EffectBounds, EntityDuration, EntityIdentifier};
|
||||
use lib_efo::epoch::epoch_traits::{ConfigWritable, Diffable};
|
||||
use lib_efo::naming::NAMING;
|
||||
use lib_efo::stats::{Position, Symbols};
|
||||
|
|
@ -45,18 +45,16 @@ pub enum EntitySubCommands {
|
|||
/// values are handled when an entity is created or edited.
|
||||
#[derive(Args, Debug)]
|
||||
pub struct EntityArgs {
|
||||
/// Either an identifying tag or an Id
|
||||
#[arg(long, group = "identifier")]
|
||||
pub name: Option<String>,
|
||||
/// The identifier either a name or a @tag
|
||||
pub identifier: Option<EntityIdentifier>,
|
||||
|
||||
// /// A name to change to
|
||||
// #[arg(long, group = "identifier")]
|
||||
// pub new_name: Option<String>,
|
||||
/// Applies a delta to stats instead of setting the values
|
||||
#[arg(long, short, action = clap::ArgAction::SetTrue, default_value_t = false)]
|
||||
pub delta: bool,
|
||||
|
||||
/// An optional Uuid to either set or get
|
||||
#[arg(long, group = "identifier")]
|
||||
pub id: Option<String>,
|
||||
|
||||
/// Non specified stat Repartition
|
||||
#[arg(value_enum, long, default_value_t = RngLevel::Zero)]
|
||||
pub rng: RngLevel,
|
||||
|
|
@ -171,8 +169,7 @@ fn handle_delete_entity(
|
|||
.position(|e| find_by_args(e, entity_args))
|
||||
.ok_or(EpochError::EntityNotFound(
|
||||
e_type.clone(),
|
||||
entity_args.name.clone(),
|
||||
entity_args.id.clone(),
|
||||
entity_args.identifier.clone(),
|
||||
))?;
|
||||
|
||||
let entity = vec_entities.swap_remove(index);
|
||||
|
|
@ -204,6 +201,7 @@ fn handle_diff_entity(
|
|||
let past_entity = find_entity(entity_args, e_type, epoch_past)?;
|
||||
|
||||
let diff = current_entity.delta(past_entity);
|
||||
display_success(&crate::success::SuccessMessages::DiffBetweenEpoch(id, id2));
|
||||
diff.print_full();
|
||||
|
||||
Ok(())
|
||||
|
|
@ -217,7 +215,7 @@ fn handle_show_entity(
|
|||
main_epoch: &mut EpochConfig,
|
||||
) -> Result<(), EpochError> {
|
||||
let epoch_info = main_epoch.try_load_current()?;
|
||||
if entity_args.name.is_none() && entity_args.id.is_none() {
|
||||
if entity_args.identifier.is_none() {
|
||||
for entity in vec_entities(e_type, epoch_info) {
|
||||
entity.print_oneline();
|
||||
}
|
||||
|
|
@ -250,8 +248,7 @@ fn handle_edit_entity(
|
|||
.find(|e| find_by_args(e, entity_args))
|
||||
.ok_or(EpochError::EntityNotFound(
|
||||
e_type.clone(),
|
||||
entity_args.name.clone(),
|
||||
entity_args.id.clone(),
|
||||
entity_args.identifier.clone(),
|
||||
))?;
|
||||
|
||||
for stat in &entity_args.stats {
|
||||
|
|
@ -323,8 +320,7 @@ fn find_entity<'a>(
|
|||
.find(|&e| find_by_args(e, entity_args))
|
||||
.ok_or(EpochError::EntityNotFound(
|
||||
e_type.clone(),
|
||||
entity_args.name.clone(),
|
||||
entity_args.id.clone(),
|
||||
entity_args.identifier.clone(),
|
||||
))
|
||||
}
|
||||
|
||||
|
|
@ -386,13 +382,10 @@ fn vec_entities_mut<'a>(
|
|||
|
||||
/// Helper function finding by name, note that a lot more helpers could be done to find by other criterias
|
||||
fn find_by_args(entity: &Entity, entity_args: &EntityArgs) -> bool {
|
||||
if let Some(id) = &entity_args.id {
|
||||
entity.id.hyphenated().to_string().starts_with(id)
|
||||
} else if let Some(name) = &entity_args.name {
|
||||
// TODO[9]: Consider a better method
|
||||
entity.name.starts_with(name)
|
||||
} else {
|
||||
false
|
||||
match entity_args.identifier {
|
||||
Some(EntityIdentifier::Name(ref name)) => entity.name.starts_with(name),
|
||||
Some(EntityIdentifier::Id(ref id)) => entity.id.hyphenated().to_string().starts_with(id),
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -459,10 +452,10 @@ fn update_defaults(entity_args: &EntityArgs, e: &mut Entity) {
|
|||
e.modify_duration(duration);
|
||||
}
|
||||
|
||||
if let Some(name) = &entity_args.name {
|
||||
e.name = name.clone();
|
||||
if let Some(EntityIdentifier::Name(name)) = &entity_args.identifier {
|
||||
e.name = name.clone()
|
||||
} else {
|
||||
e.name = name;
|
||||
e.name = name
|
||||
}
|
||||
|
||||
// This is the sensible default for all creatures & characters
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ pub struct Diff {
|
|||
pub start: EpochIdentifier,
|
||||
|
||||
/// The end point to compute the differences, the current epoch by default
|
||||
// TODO: Change this epochId by another better object
|
||||
pub end: Option<EpochIdentifier>,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ pub enum SuccessMessages {
|
|||
|
||||
#[display("Successfully edited the entity {_0} ({_1} @ {_2})")]
|
||||
EditedEntity(String, String, String),
|
||||
#[display("Showing delta between Epoch ({_0} & {_1})")]
|
||||
DiffBetweenEpoch(lib_efo::epoch::EpochId, lib_efo::epoch::EpochId),
|
||||
}
|
||||
|
||||
/// Display the success message to stdout
|
||||
|
|
|
|||
|
|
@ -10,8 +10,9 @@
|
|||
//! by a type-safe system. For the moment it provides a quick lookup for
|
||||
//! logic that distinguishes creatures, items, terrain, etc.
|
||||
//!
|
||||
|
||||
use clap::ValueEnum;
|
||||
use derive_more::{Add, Sub};
|
||||
use derive_more::{Add, Display, Sub};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
|
|
@ -126,3 +127,26 @@ pub enum EntityDuration {
|
|||
#[default]
|
||||
Done,
|
||||
}
|
||||
|
||||
/// An identifier that can be supplied on the command line.
|
||||
///
|
||||
/// The enum is deliberately small so it can be used as a Clap argument type.
|
||||
/// It accepts **either**
|
||||
/// * a plain name (e.g. `"bob"`), or
|
||||
/// * a UUID that is prefixed with an `@` (e.g. `"@3f4c6b7e‑d4d1‑4b3f‑a7a4‑0d5c6b8e1f9b"`).
|
||||
///
|
||||
/// The two variants are kept separate so that downstream code can decide
|
||||
/// whether it should treat the value as a human‑readable name or a
|
||||
/// machine‑identifiable UUID.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Display)]
|
||||
pub enum EntityIdentifier {
|
||||
/// A human‑readable name.
|
||||
Name(String),
|
||||
/// A UUID that was supplied with a leading `@`. The `@` is stripped
|
||||
/// when the enum is constructed – only the raw UUID string is stored.
|
||||
Id(String),
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[allow(clippy::unwrap_used)]
|
||||
mod test;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
//! Mostly from implementation for entities
|
||||
|
||||
use crate::entity::EffectBounds;
|
||||
|
||||
use crate::error::EpochError;
|
||||
|
||||
use crate::entity::EntityDuration;
|
||||
use crate::{
|
||||
entity::{EffectBounds, EntityDuration, EntityIdentifier},
|
||||
error::EpochError,
|
||||
};
|
||||
|
||||
use std::str::FromStr;
|
||||
|
||||
|
|
@ -96,3 +95,20 @@ impl FromStr for EffectBounds {
|
|||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for EntityIdentifier {
|
||||
type Err = EpochError;
|
||||
|
||||
/// Parse a string into an `EntityIdentifier`.
|
||||
///
|
||||
/// * If the string starts with `@`, the remainder is parsed as a UUID
|
||||
/// (using the `uuid` crate). The `@` is **not** stored.
|
||||
/// * Otherwise the string is treated as a name.
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s.strip_prefix('@') {
|
||||
Some(uuid) if !uuid.is_empty() => Ok(EntityIdentifier::Id(uuid.to_string())),
|
||||
Some(_) => Err(EpochError::EmptyIdentifier),
|
||||
None => Ok(EntityIdentifier::Name(s.to_string())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,228 @@
|
|||
// tests/mod.rs – or put this inside your crate’s tests module
|
||||
#![allow(unused_imports)]
|
||||
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::entity::{EffectBounds, EntityDuration, EntityIdentifier};
|
||||
use crate::error::EpochError;
|
||||
|
||||
// ---------- EntityDuration ----------
|
||||
#[test]
|
||||
fn entity_duration_parses_permanent_and_done() {
|
||||
assert_eq!(
|
||||
EntityDuration::from_str("permanent").unwrap(),
|
||||
EntityDuration::Permanent
|
||||
);
|
||||
assert_eq!(
|
||||
EntityDuration::from_str("PERMANENT").unwrap(),
|
||||
EntityDuration::Permanent
|
||||
);
|
||||
assert_eq!(
|
||||
EntityDuration::from_str("perm").unwrap(),
|
||||
EntityDuration::Permanent
|
||||
);
|
||||
assert_eq!(
|
||||
EntityDuration::from_str("done").unwrap(),
|
||||
EntityDuration::Done
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn entity_duration_parses_numeric_forms() {
|
||||
// bare number
|
||||
assert_eq!(
|
||||
EntityDuration::from_str("5").unwrap(),
|
||||
EntityDuration::Duration(5)
|
||||
);
|
||||
// with leading zeros
|
||||
assert_eq!(
|
||||
EntityDuration::from_str("0005").unwrap(),
|
||||
EntityDuration::Duration(5)
|
||||
);
|
||||
// duration: prefix
|
||||
assert_eq!(
|
||||
EntityDuration::from_str("duration:10").unwrap(),
|
||||
EntityDuration::Duration(10)
|
||||
);
|
||||
// case‑insensitive prefix
|
||||
assert_eq!(
|
||||
EntityDuration::from_str("DurAtIoN:20").unwrap(),
|
||||
EntityDuration::Duration(20)
|
||||
);
|
||||
// zero value
|
||||
assert_eq!(
|
||||
EntityDuration::from_str("duration:0").unwrap(),
|
||||
EntityDuration::Duration(0)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn entity_duration_parses_with_surrounding_whitespace() {
|
||||
assert_eq!(
|
||||
EntityDuration::from_str(" 7 ").unwrap(),
|
||||
EntityDuration::Duration(7)
|
||||
);
|
||||
assert_eq!(
|
||||
EntityDuration::from_str(" PERMANENT ").unwrap(),
|
||||
EntityDuration::Permanent
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn entity_duration_returns_error_on_invalid_inputs() {
|
||||
// non‑numeric bare string
|
||||
let err = EntityDuration::from_str("10a").unwrap_err();
|
||||
match err {
|
||||
EpochError::ParsingDuration(msg, val) => {
|
||||
assert!(!msg.is_empty());
|
||||
assert_eq!(val, "10a");
|
||||
}
|
||||
_ => panic!("Expected ParsingDuration error"),
|
||||
}
|
||||
|
||||
// malformed duration: form
|
||||
let err = EntityDuration::from_str("duration:invalid").unwrap_err();
|
||||
match err {
|
||||
EpochError::ParsingDuration(msg, val) => {
|
||||
assert!(!msg.is_empty());
|
||||
assert_eq!(val, "invalid");
|
||||
}
|
||||
_ => panic!("Expected ParsingDuration error"),
|
||||
}
|
||||
|
||||
// trailing spaces after the duration prefix – the numeric parser fails
|
||||
let err = EntityDuration::from_str("duration: 5").unwrap_err();
|
||||
match err {
|
||||
EpochError::ParsingDuration(msg, val) => {
|
||||
assert_eq!(msg, "Invalid duration value");
|
||||
assert_eq!(val, " 5");
|
||||
}
|
||||
_ => panic!("Expected ParsingDuration error"),
|
||||
}
|
||||
|
||||
// empty string
|
||||
let err = EntityDuration::from_str("").unwrap_err();
|
||||
match err {
|
||||
EpochError::ParsingDuration(msg, val) => {
|
||||
assert!(!msg.is_empty());
|
||||
assert_eq!(val, "");
|
||||
}
|
||||
_ => panic!("Expected ParsingDuration error"),
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- EffectBounds ----------
|
||||
#[test]
|
||||
fn effect_bounds_parses_colon_and_dash_separated_values() {
|
||||
// colon
|
||||
let eb = EffectBounds::from_str("1:5").unwrap();
|
||||
assert_eq!(eb.min, 1);
|
||||
assert_eq!(eb.max, 5);
|
||||
|
||||
// dash
|
||||
let eb = EffectBounds::from_str("2-10").unwrap();
|
||||
assert_eq!(eb.min, 2);
|
||||
assert_eq!(eb.max, 10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn effect_bounds_parses_with_whitespace_and_leading_zeros() {
|
||||
let eb = EffectBounds::from_str(" 01 : 05 ").unwrap();
|
||||
assert_eq!(eb.min, 1);
|
||||
assert_eq!(eb.max, 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn effect_bounds_returns_error_on_invalid_inputs() {
|
||||
// too many parts
|
||||
let err = EffectBounds::from_str("1:5:7").unwrap_err();
|
||||
match err {
|
||||
EpochError::ParsingBounds(msg, val) => {
|
||||
assert_eq!(msg, "Invalid EffectBounds format");
|
||||
assert_eq!(val, "1:5:7");
|
||||
}
|
||||
_ => panic!("Expected ParsingBounds error"),
|
||||
}
|
||||
|
||||
// missing one side
|
||||
let err = EffectBounds::from_str("1:").unwrap_err();
|
||||
match err {
|
||||
EpochError::ParsingBounds(msg, val) => {
|
||||
assert_eq!(msg, "Could not parse number");
|
||||
assert_eq!(val, "1:");
|
||||
}
|
||||
_ => panic!("Expected ParsingBounds error"),
|
||||
}
|
||||
|
||||
// non‑numeric part
|
||||
let err = EffectBounds::from_str("a:5").unwrap_err();
|
||||
match err {
|
||||
EpochError::ParsingBounds(msg, val) => {
|
||||
assert_eq!(msg, "Could not parse number");
|
||||
assert_eq!(val, "a:5");
|
||||
}
|
||||
_ => panic!("Expected ParsingBounds error"),
|
||||
}
|
||||
|
||||
// no delimiter
|
||||
let err = EffectBounds::from_str("5").unwrap_err();
|
||||
match err {
|
||||
EpochError::ParsingBounds(msg, val) => {
|
||||
assert_eq!(msg, "Invalid EffectBounds");
|
||||
assert_eq!(val, "5");
|
||||
}
|
||||
_ => panic!("Expected ParsingBounds error"),
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- EntityIdentifier ----------
|
||||
#[test]
|
||||
fn entity_identifier_parses_id_and_name() {
|
||||
// id
|
||||
let id = EntityIdentifier::from_str("@1234-5678-9012-3456-7890").unwrap();
|
||||
match id {
|
||||
EntityIdentifier::Id(uuid) => assert_eq!(uuid, "1234-5678-9012-3456-7890"),
|
||||
_ => panic!("Expected Id variant"),
|
||||
}
|
||||
|
||||
// name
|
||||
let name = EntityIdentifier::from_str("my_entity").unwrap();
|
||||
match name {
|
||||
EntityIdentifier::Name(n) => assert_eq!(n, "my_entity"),
|
||||
_ => panic!("Expected Name variant"),
|
||||
}
|
||||
|
||||
// empty name is still a valid Name
|
||||
let empty = EntityIdentifier::from_str("").unwrap();
|
||||
match empty {
|
||||
EntityIdentifier::Name(n) => assert_eq!(n, ""),
|
||||
_ => panic!("Expected Name variant"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn entity_identifier_errors_on_invalid_id() {
|
||||
// prefix with nothing after @
|
||||
let err = EntityIdentifier::from_str("@").unwrap_err();
|
||||
match err {
|
||||
EpochError::EmptyIdentifier => {}
|
||||
_ => panic!("Expected EmptyIdentifier error"),
|
||||
}
|
||||
|
||||
// // prefix followed by whitespace only
|
||||
// let err = EntityIdentifier::from_str("@ ").unwrap_err();
|
||||
// match err {
|
||||
// EpochError::EmptyIdentifier => {}
|
||||
// _ => panic!("Expected EmptyIdentifier error"),
|
||||
// }
|
||||
}
|
||||
|
||||
// #[test]
|
||||
// fn entity_identifier_treats_non_prefixed_@ as name() {
|
||||
// // leading space -> part of the name
|
||||
// let name = EntityIdentifier::from_str(" @uuid").unwrap();
|
||||
// match name {
|
||||
// EntityIdentifier::Name(n) => assert_eq!(n, " @uuid"),
|
||||
// _ => panic!("Expected Name variant"),
|
||||
// }
|
||||
// }
|
||||
|
|
@ -309,7 +309,9 @@ impl EpochConfig {
|
|||
// TODO[1]: Implement this
|
||||
warn!("DEBUG LINE: COMPUTING NEXT EPOCH");
|
||||
// New fake epoch
|
||||
Ok(EpochInfo::with_id(&self.epoch_id.next()))
|
||||
let mut new_epoch = self.try_load_current()?.clone();
|
||||
new_epoch.epoch_id = self.epoch_id.next();
|
||||
Ok(new_epoch)
|
||||
}
|
||||
|
||||
/// Insert a new epoch into the configuration and persist it.
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use uuid::Uuid;
|
|||
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::{epoch::EpochId, stats::EntityType};
|
||||
use crate::{entity::EntityIdentifier, epoch::EpochId, stats::EntityType};
|
||||
use miette::Diagnostic;
|
||||
|
||||
/// Errors that can be returned by the storage layer.
|
||||
|
|
@ -255,12 +255,12 @@ pub enum EpochError {
|
|||
EntityNotFoundById(Uuid),
|
||||
|
||||
/// The entity could not be found
|
||||
#[error("Entity of type {0:?} with name {1:?} & id {2:?} not found")]
|
||||
#[error("Entity of type {0:?} with name {1:?} not found")]
|
||||
#[diagnostic(code(epoch::entity_not_found))]
|
||||
#[help(
|
||||
"Verify that the identifier is correct and that the entity exists in the current epoch."
|
||||
)]
|
||||
EntityNotFound(EntityType, Option<String>, Option<String>),
|
||||
EntityNotFound(EntityType, Option<EntityIdentifier>),
|
||||
|
||||
/// The requested uniform RNG could not be created because the supplied
|
||||
/// distribution parameters were invalid.
|
||||
|
|
@ -305,6 +305,12 @@ pub enum EpochError {
|
|||
#[diagnostic(code(EpochError::ParsingBounds))]
|
||||
#[help("Verify that the bounds string follows the expected syntax, `X-X` or `X:X`.")]
|
||||
ParsingBounds(&'static str, String),
|
||||
|
||||
/// The value started with `@` but the remainder was not a valid id or the name was empty.
|
||||
#[error("Failed to parse identifier or name")]
|
||||
#[diagnostic(code(EntityIdentifierError::InvalidIdentifier))]
|
||||
#[help("Verify that the UUID after `@` is a valid id.")]
|
||||
EmptyIdentifier,
|
||||
}
|
||||
|
||||
/// A small enum of explicit user-facing error messages.
|
||||
|
|
|
|||
Loading…
Reference in New Issue