Move `thread` COB to test module

Threads are only intended to be used as part of other COBs.

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
Alexis Sellier 2022-12-14 20:21:41 +01:00
parent f26674a5a9
commit c68a5a8857
No known key found for this signature in database
1 changed files with 33 additions and 33 deletions

View File

@ -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<TypeName> =
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<CommentId, LWWSet<(ActorId, Reaction), Lamport>>,
}
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<G> DerefMut for Actor<G> {
#[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<cob::TypeName> =
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<const N: usize> {