use enshwick::Entity;
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, enshwick::Shape)]
#[shape(values(BUY, SELL))]
pub struct Deal(pub u32);
impl Deal {
pub const BUY: Self = Self(0);
pub const SELL: Self = Self(1);
}
#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, enshwick::Shape)]
pub enum Stall {
Food = 1,
Tools = 2,
}
#[enshwick::call(name = "you.stalls:rent", output = u64, version = 2)]
#[derive(Clone, Copy, Debug)]
pub struct Rent {
pub character: Entity,
pub deal: Deal,
pub own: bool,
pub stall: Stall,
pub place: u16,
}
#[enshwick::call(name = "you.stalls:fee", output = u64, version = 1)]
#[derive(Clone, Copy, Debug)]
pub struct Fee {
pub character: Entity,
pub days: u32,
pub place: u16,
pub own: bool,
pub row: u8,
}
#[path = "../../cargo-enshwick/tests/fixtures/stalls_rent.rs"]
pub mod generated;
#[cfg(test)]
mod tests {
use enshwick::services::Call;
use super::{Deal, Fee, Rent, Stall, generated};
#[test]
fn the_schema_is_the_one_cargo_enshwick_is_tested_with() {
let manifest = enshwick::manifest!(id: "you.stalls", side: SERVER, version: "1.2.0", calls: [Rent, Fee]);
let text = unsafe { manifest.points.as_str() }.unwrap_or_default();
assert_eq!(
text,
include_str!("../../cargo-enshwick/tests/fixtures/stalls.calls.toml")
);
}
#[test]
fn the_written_declaration_matches_the_server_s_call() {
let server = <Rent as Call>::LAYOUT.iter().map(|f| f.hash);
let written = <generated::Rent as Call>::LAYOUT.iter().map(|f| f.hash);
assert!(server.eq(written));
assert_eq!(<generated::Rent as Call>::NAME, <Rent as Call>::NAME);
assert_eq!(<generated::Rent as Call>::MAJOR, 2);
assert_eq!(
<generated::Rent as Call>::OUTPUT[0].hash,
<Rent as Call>::OUTPUT[0].hash
);
assert_eq!(generated::Deal::SELL.0, Deal::SELL.0);
assert_eq!(generated::Stall::Tools as u8, Stall::Tools as u8);
}
}