From c68a5a88578e99db539da28301bfef1c3247472e Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Wed, 14 Dec 2022 20:21:41 +0100 Subject: [PATCH] Move `thread` COB to test module Threads are only intended to be used as part of other COBs. Signed-off-by: Alexis Sellier --- radicle/src/cob/thread.rs | 66 +++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/radicle/src/cob/thread.rs b/radicle/src/cob/thread.rs index d91a7337..fcbe2495 100644 --- a/radicle/src/cob/thread.rs +++ b/radicle/src/cob/thread.rs @@ -1,16 +1,13 @@ use std::cmp::Ordering; use std::collections::BTreeMap; -use std::ops::{ControlFlow, Deref, DerefMut}; -use std::str::FromStr; +use std::ops::{Deref, DerefMut}; -use once_cell::sync::Lazy; use radicle_crdt as crdt; use serde::{Deserialize, Serialize}; use crate::cob; use crate::cob::common::{Reaction, Timestamp}; -use crate::cob::store; -use crate::cob::{ActorId, History, Op, OpId, TypeName}; +use crate::cob::{ActorId, Op, OpId}; use crate::crypto::Signer; use crdt::clock::Lamport; @@ -19,12 +16,6 @@ use crdt::lwwset::LWWSet; use crdt::redactable::Redactable; use crdt::Semilattice; -use super::op::Ops; - -/// Type name of a thread. -pub static TYPENAME: Lazy = - Lazy::new(|| FromStr::from_str("xyz.radicle.thread").expect("type name is valid")); - /// Identifies a comment. pub type CommentId = OpId; @@ -99,26 +90,6 @@ pub struct Thread { reactions: GMap>, } -impl store::FromHistory for Thread { - type Action = Action; - - fn type_name() -> &'static radicle_cob::TypeName { - &*TYPENAME - } - - fn from_history(history: &History) -> Result<(Self, Lamport), store::Error> { - let obj = history.traverse(Thread::default(), |mut acc, entry| { - if let Ok(Ops(ops)) = Ops::try_from(entry) { - acc.apply(ops); - ControlFlow::Continue(acc) - } else { - ControlFlow::Break(acc) - } - }); - Ok((obj, history.clock().into())) - } -} - impl Semilattice for Thread { fn merge(&mut self, other: Self) { self.comments.merge(other.comments); @@ -278,16 +249,45 @@ impl DerefMut for Actor { #[cfg(test)] mod tests { + use std::ops::ControlFlow; + use std::str::FromStr; use std::{array, iter}; - use crate::crypto::test::signer::MockSigner; + use cob::op::Ops; use nonempty::NonEmpty; + use once_cell::sync::Lazy; use pretty_assertions::assert_eq; use qcheck::{Arbitrary, TestResult}; + use crdt::test::{assert_laws, WeightedGenerator}; + use super::*; use crate as radicle; - use crdt::test::{assert_laws, WeightedGenerator}; + use crate::crypto::test::signer::MockSigner; + + /// Type name of a thread. + pub static TYPENAME: Lazy = + Lazy::new(|| FromStr::from_str("xyz.radicle.thread").expect("type name is valid")); + + impl cob::store::FromHistory for Thread { + type Action = Action; + + fn type_name() -> &'static radicle_cob::TypeName { + &*TYPENAME + } + + fn from_history(history: &cob::History) -> Result<(Self, Lamport), cob::store::Error> { + let obj = history.traverse(Thread::default(), |mut acc, entry| { + if let Ok(Ops(ops)) = Ops::try_from(entry) { + acc.apply(ops); + ControlFlow::Continue(acc) + } else { + ControlFlow::Break(acc) + } + }); + Ok((obj, history.clock().into())) + } + } #[derive(Clone)] struct Changes {