use super::ChannelOptions;
#[test]
fn a_bounded_spec_names_its_depth_and_an_unbounded_one_has_none() {
assert_eq!(ChannelOptions::Bounded(512).capacity(), Some(512));
assert!(ChannelOptions::Bounded(512).is_bounded());
assert_eq!(ChannelOptions::Unbounded.capacity(), None);
assert!(ChannelOptions::Unbounded.is_unbounded());
}
#[test]
fn a_spec_reads_back_as_the_word_an_author_writes() {
assert_eq!(ChannelOptions::Bounded(4).to_string(), "bounded(4)");
assert_eq!(ChannelOptions::Unbounded.to_string(), "unbounded");
}
#[test]
fn zero_is_a_rendezvous_and_not_a_refusal() {
assert_eq!(ChannelOptions::Bounded(0).capacity(), Some(0));
}
#[cfg(feature = "serde")]
mod wire {
use super::ChannelOptions;
fn read(document: &str) -> Result<ChannelOptions, serde_json::Error> {
serde_json::from_str(document)
}
#[test]
fn an_integer_is_a_capacity_and_the_word_is_the_other_kind() {
assert_eq!(
read("512").expect("an integer is a depth"),
ChannelOptions::Bounded(512)
);
assert_eq!(
read("0").expect("zero is a rendezvous"),
ChannelOptions::Bounded(0)
);
assert_eq!(
read(r#""unbounded""#).expect("the word is the other kind"),
ChannelOptions::Unbounded
);
}
#[test]
fn another_word_is_refused_naming_the_two_forms() {
let refusal = read(r#""bounded""#)
.expect_err("only one word is a channel")
.to_string();
assert!(refusal.contains("bounded"), "{refusal}");
assert!(refusal.contains("unbounded"), "{refusal}");
}
#[test]
fn a_negative_depth_is_refused_in_the_grammars_own_words() {
let refusal = read("-1")
.expect_err("a channel is not minus one deep")
.to_string();
assert!(refusal.contains("unbounded"), "{refusal}");
}
}