use interthread::actor as life;
#[test]
fn actor_sync_unbound_default() {
pub struct Actor(i8);
#[life]
impl Actor {
pub fn new() -> Self{Self(0)}
pub fn input(&mut self, v:i8){self.0 = v}
pub fn output(&self)->i8{self.0}
pub fn in_out(&self,v:i8)->i8{v}
#[doc = r"Direct doc comment check"]
pub fn add(&mut self, v:i8) -> i8{self.0 += v;self.0}
}
let mut live = ActorLive::new();
live.input(3);
assert_eq!( live.output(), 3);
assert_eq!( live.in_out(4), 4);
assert_eq!( live.add(5), 8);
}
#[test]
fn actor_sync_unbounded_int() {
pub struct Actor(i8);
#[life(channel=0, name="MyActor")]
impl Actor {
pub fn new() -> Self{Self(0)}
pub fn input(&mut self, v:i8){self.0 = v}
pub fn output(&self)->i8{self.0}
pub fn in_out(&self,v:i8)->i8{v}
pub fn add(&mut self, v:i8) -> i8{self.0 += v;self.0}
}
let _live = MyActorLive::new();
}
#[test]
fn actor_sync_bounded() {
pub struct Actor(i8);
#[life(channel=3)]
impl Actor {
pub fn new() -> Self{Self(0)}
pub fn input(&mut self, v:i8){self.0 = v}
pub fn output(&self)->i8{self.0}
pub fn in_out(&self,v:i8)->i8{v}
pub fn add(&mut self, v:i8) -> i8{self.0 += v;self.0}
}
let mut live = ActorLive::new();
live.input(3);
assert_eq!( live.output(), 3);
assert_eq!( live.in_out(4), 4);
assert_eq!( live.add(5), 8);
}
#[test]
fn actor_tokio_bounded() {
pub struct Actor(i8);
#[life(channel=3,lib="tokio")]
impl Actor {
pub fn new() -> Self{Self(0)}
pub fn input(&mut self, v:i8){self.0 = v}
pub fn output(&self)->i8{self.0}
pub fn in_out(&self,v:i8)->i8{v}
pub fn add(&mut self, v:i8) -> i8{self.0 += v;self.0}
}
tokio::runtime::Runtime::new()
.unwrap()
.block_on(
async {
let mut live = ActorLive::new();
live.input(3).await;
assert_eq!( live.output().await, 3);
assert_eq!( live.in_out(4).await, 4);
assert_eq!( live.add(5).await, 8);
});
}
#[test]
fn actor_tokio_unbounded() {
pub struct Actor(i8);
#[life(lib="tokio")]
impl Actor {
pub fn new() -> Self{Self(0)}
pub fn input(&mut self, v:i8){self.0 = v}
pub fn output(&self)->i8{self.0}
pub fn in_out(&self,v:i8)->i8{v}
pub fn add(&mut self, v:i8) -> i8{self.0 += v;self.0}
}
tokio::runtime::Runtime::new()
.unwrap()
.block_on( async {
let mut live = ActorLive::new();
live.input(3).await;
assert_eq!( live.output().await, 3);
assert_eq!( live.in_out(4).await, 4);
assert_eq!( live.add(5).await, 8);
});
}
#[test]
fn actor_async_std_bounded() {
pub struct Actor(i8);
#[life(channel=3,lib="async_std")]
impl Actor {
pub fn new() -> Self{Self(0)}
pub fn input(&mut self, v:i8){self.0 = v}
pub fn output(&self)->i8{self.0}
pub fn in_out(&self,v:i8)->i8{v}
pub fn add(&mut self, v:i8) -> i8{self.0 += v;self.0}
}
async_std::task::block_on(async {
let mut live = ActorLive::new();
live.input(3).await;
assert_eq!( live.output().await, 3);
assert_eq!( live.in_out(4).await, 4);
assert_eq!( live.add(5).await, 8);
});
}
#[test]
fn actor_async_std_unbounded() {
pub struct Actor(i8);
#[life(lib="async_std")]
impl Actor {
pub fn new() -> Self{Self(0)}
pub fn input(&mut self, v:i8){self.0 = v}
pub fn output(&self)->i8{self.0}
pub fn in_out(&self,v:i8)->i8{v}
pub fn add(&mut self, v:i8) -> i8{self.0 += v;self.0}
}
async_std::task::block_on(async {
let mut live = ActorLive::new();
live.input(3).await;
assert_eq!( live.output().await, 3);
assert_eq!( live.in_out(4).await, 4);
assert_eq!( live.add(5).await, 8);
});
}
#[test]
fn actor_smol_bounded() {
pub struct Actor(i8);
#[life(channel=3,lib="smol")]
impl Actor {
pub fn new() -> Self{Self(0)}
pub fn input(&mut self, v:i8){self.0 = v}
pub fn output(&self)->i8{self.0}
pub fn in_out(&self,v:i8)->i8{v}
pub fn add(&mut self, v:i8) -> i8{self.0 += v;self.0}
}
async_std::task::block_on(async {
let mut live = ActorLive::new();
live.input(3).await;
assert_eq!( live.output().await, 3);
assert_eq!( live.in_out(4).await, 4);
assert_eq!( live.add(5).await, 8);
});
}
#[test]
fn actor_smol_unbounded() {
pub struct Actor(i8);
#[life(lib="smol")]
impl Actor {
pub fn new() -> Self{Self(0)}
pub fn input(&mut self, v:i8){self.0 = v}
pub fn output(&self)->i8{self.0}
pub fn in_out(&self,v:i8)->i8{v}
pub fn add(&mut self, v:i8) -> i8{self.0 += v;self.0}
}
async_std::task::block_on(async {
let mut live = ActorLive::new();
live.input(3).await;
assert_eq!( live.output().await, 3);
assert_eq!( live.in_out(4).await, 4);
assert_eq!( live.add(5).await, 8);
});
}
#[test]
fn self_word_in_arg_type() {
#[derive(Debug,Clone,PartialEq, Eq)]
pub struct ActorSelf(i8);
#[life(channel=3)]
impl ActorSelf {
pub fn new() -> Self{Self(0)}
pub fn input(&mut self, v:i8){self.0 = v}
pub fn output(&self)->i8{self.0}
pub fn in_out(&self,v:ActorSelf)->ActorSelf{v}
pub fn add(&mut self, v:i8) -> i8{self.0 += v;self.0}
}
let a = ActorSelf::new();
let mut live = ActorSelfLive::new();
live.input(3);
assert_eq!( live.output(), 3);
assert_eq!( live.in_out(a.clone()), a);
assert_eq!( live.add(5), 8);
}
#[test]
fn id_actor_sync_inter(){
pub struct Actor(i8);
#[life(debut)]
impl Actor {
pub fn new() -> Self{Self(0)}
pub fn input(&mut self, v:i8){self.0 = v}
pub fn output(&self)->i8{self.0}
pub fn in_out(&self,v:i8)->i8{v}
pub fn add(&mut self, v:i8) -> i8{self.0 += v;self.0}
}
let actor1 = ActorLive::new();
let actor2 = ActorLive::new();
let actor3 = ActorLive::new();
assert_eq!(actor1 == actor2, false);
assert_eq!(actor2 == actor3, false);
assert_eq!(actor1 != actor2, true);
assert_eq!(actor2 != actor3, true);
assert_eq!(actor1 < actor2, false);
assert_eq!(actor1 < actor3, false);
assert_eq!(actor2 < actor3, false);
assert_eq!(actor2 > actor1, false);
assert_eq!(actor3 > actor1, false);
assert_eq!(actor3 > actor2, false);
assert_eq!(actor2 <= actor1, true);
assert_eq!(actor3 <= actor1, true);
assert_eq!(actor3 <= actor2, true);
assert_eq!(actor1 >= actor2, true);
assert_eq!(actor1 >= actor3, true);
assert_eq!(actor2 >= actor3, true);
let actor3_c = actor3.clone();
let actor2_c = actor2.clone();
let actor1_c = actor1.clone();
assert_eq!(actor1 == actor1_c, true);
assert_eq!(actor2 == actor2_c, true);
assert_eq!(actor3 == actor3_c, true);
assert_eq!(actor1_c == actor2_c, false);
assert_eq!(actor2_c == actor3_c, false);
assert_eq!(actor1_c != actor2_c, true);
assert_eq!(actor2_c != actor3_c, true);
assert_eq!(actor2_c < actor1_c, true);
assert_eq!(actor3_c < actor1_c, true);
assert_eq!(actor3_c < actor2_c, true);
assert_eq!(actor1_c > actor2_c, true);
assert_eq!(actor1_c > actor3_c, true);
assert_eq!(actor2_c > actor3_c, true);
assert_eq!(actor1_c <= actor2_c, false);
assert_eq!(actor1_c <= actor3_c, false);
assert_eq!(actor2_c <= actor3_c, false);
assert_eq!(actor2_c >= actor1_c, false);
assert_eq!(actor3_c >= actor1_c, false);
assert_eq!(actor3_c >= actor2_c, false);
assert_eq!(actor1.debut < actor2.debut, !false);
assert_eq!(actor1.debut < actor3.debut, !false);
assert_eq!(actor2.debut < actor3.debut, !false);
assert_eq!(actor2.debut > actor1.debut, !false);
assert_eq!(actor3.debut > actor1.debut, !false);
assert_eq!(actor3.debut > actor2.debut, !false);
assert_eq!(actor2.debut <= actor1.debut, !true);
assert_eq!(actor3.debut <= actor1.debut, !true);
assert_eq!(actor3.debut <= actor2.debut, !true);
assert_eq!(actor1.debut >= actor2.debut, !true);
assert_eq!(actor1.debut >= actor3.debut, !true);
assert_eq!(actor2.debut >= actor3.debut, !true);
}
#[test]
fn id_actor_sync_bounded() {
pub struct Actor;
#[life(channel=3,debut)]
impl Actor {
pub fn new() -> Self{Self}
}
let actor1 = ActorLive::new();
let actor2 = ActorLive::new();
let actor3 = ActorLive::new();
assert_eq!(actor1 == actor2, false);
assert_eq!(actor2 == actor3, false);
assert_eq!(actor1 != actor2, true);
assert_eq!(actor2 != actor3, true);
assert_eq!(actor1 < actor2, false);
assert_eq!(actor1 < actor3, false);
assert_eq!(actor2 < actor3, false);
assert_eq!(actor2 > actor1, false);
assert_eq!(actor3 > actor1, false);
assert_eq!(actor3 > actor2, false);
assert_eq!(actor2 <= actor1, true);
assert_eq!(actor3 <= actor1, true);
assert_eq!(actor3 <= actor2, true);
assert_eq!(actor1 >= actor2, true);
assert_eq!(actor1 >= actor3, true);
assert_eq!(actor2 >= actor3, true);
let actor3_c = actor3.clone();
let actor2_c = actor2.clone();
let actor1_c = actor1.clone();
assert_eq!(actor1 == actor1_c, true);
assert_eq!(actor2 == actor2_c, true);
assert_eq!(actor3 == actor3_c, true);
assert_eq!(actor1_c == actor2_c, false);
assert_eq!(actor2_c == actor3_c, false);
assert_eq!(actor1_c != actor2_c, true);
assert_eq!(actor2_c != actor3_c, true);
assert_eq!(actor2_c < actor1_c, true);
assert_eq!(actor3_c < actor1_c, true);
assert_eq!(actor3_c < actor2_c, true);
assert_eq!(actor1_c > actor2_c, true);
assert_eq!(actor1_c > actor3_c, true);
assert_eq!(actor2_c > actor3_c, true);
assert_eq!(actor1_c <= actor2_c, false);
assert_eq!(actor1_c <= actor3_c, false);
assert_eq!(actor2_c <= actor3_c, false);
assert_eq!(actor2_c >= actor1_c, false);
assert_eq!(actor3_c >= actor1_c, false);
assert_eq!(actor3_c >= actor2_c, false);
assert_eq!(actor1.debut < actor2.debut, !false);
assert_eq!(actor1.debut < actor3.debut, !false);
assert_eq!(actor2.debut < actor3.debut, !false);
assert_eq!(actor2.debut > actor1.debut, !false);
assert_eq!(actor3.debut > actor1.debut, !false);
assert_eq!(actor3.debut > actor2.debut, !false);
assert_eq!(actor2.debut <= actor1.debut, !true);
assert_eq!(actor3.debut <= actor1.debut, !true);
assert_eq!(actor3.debut <= actor2.debut, !true);
assert_eq!(actor1.debut >= actor2.debut, !true);
assert_eq!(actor1.debut >= actor3.debut, !true);
assert_eq!(actor2.debut >= actor3.debut, !true);
}
#[test]
fn id_actor_tokio_bounded() {
pub struct Actor(i8);
#[life(channel=3,lib="tokio",debut)]
impl Actor {
pub fn new() -> Self{Self(0)}
pub fn input(&mut self, v:i8){self.0 = v}
pub fn output(&self)->i8{self.0}
pub fn in_out(&self,v:i8)->i8{v}
pub fn add(&mut self, v:i8) -> i8{self.0 += v;self.0}
}
tokio::runtime::Runtime::new()
.unwrap()
.block_on(
async {
let actor1 = ActorLive::new();
let actor2 = ActorLive::new();
let actor3 = ActorLive::new();
assert_eq!(actor1 == actor2, false);
assert_eq!(actor2 == actor3, false);
assert_eq!(actor1 != actor2, true);
assert_eq!(actor2 != actor3, true);
assert_eq!(actor1 < actor2, false);
assert_eq!(actor1 < actor3, false);
assert_eq!(actor2 < actor3, false);
assert_eq!(actor2 > actor1, false);
assert_eq!(actor3 > actor1, false);
assert_eq!(actor3 > actor2, false);
assert_eq!(actor2 <= actor1, true);
assert_eq!(actor3 <= actor1, true);
assert_eq!(actor3 <= actor2, true);
assert_eq!(actor1 >= actor2, true);
assert_eq!(actor1 >= actor3, true);
assert_eq!(actor2 >= actor3, true);
let actor3_c = actor3.clone();
let actor2_c = actor2.clone();
let actor1_c = actor1.clone();
assert_eq!(actor1 == actor1_c, true);
assert_eq!(actor2 == actor2_c, true);
assert_eq!(actor3 == actor3_c, true);
assert_eq!(actor1_c == actor2_c, false);
assert_eq!(actor2_c == actor3_c, false);
assert_eq!(actor1_c != actor2_c, true);
assert_eq!(actor2_c != actor3_c, true);
assert_eq!(actor2_c < actor1_c, true);
assert_eq!(actor3_c < actor1_c, true);
assert_eq!(actor3_c < actor2_c, true);
assert_eq!(actor1_c > actor2_c, true);
assert_eq!(actor1_c > actor3_c, true);
assert_eq!(actor2_c > actor3_c, true);
assert_eq!(actor1_c <= actor2_c, false);
assert_eq!(actor1_c <= actor3_c, false);
assert_eq!(actor2_c <= actor3_c, false);
assert_eq!(actor2_c >= actor1_c, false);
assert_eq!(actor3_c >= actor1_c, false);
assert_eq!(actor3_c >= actor2_c, false);
assert_eq!(actor1.debut < actor2.debut, !false);
assert_eq!(actor1.debut < actor3.debut, !false);
assert_eq!(actor2.debut < actor3.debut, !false);
assert_eq!(actor2.debut > actor1.debut, !false);
assert_eq!(actor3.debut > actor1.debut, !false);
assert_eq!(actor3.debut > actor2.debut, !false);
assert_eq!(actor2.debut <= actor1.debut, !true);
assert_eq!(actor3.debut <= actor1.debut, !true);
assert_eq!(actor3.debut <= actor2.debut, !true);
assert_eq!(actor1.debut >= actor2.debut, !true);
assert_eq!(actor1.debut >= actor3.debut, !true);
assert_eq!(actor2.debut >= actor3.debut, !true);
});
}