use plexus_core::plexus::Activation;
struct SingleLineDocHub;
#[plexus_macros::activation(namespace = "single_line", version = "1.0.0", crate_path = "plexus_core")]
impl SingleLineDocHub {
#[plexus_macros::method]
async fn do_thing(&self) -> impl futures::stream::Stream<Item = String> + Send + 'static {
async_stream::stream! { yield "ok".into(); }
}
}
#[test]
fn single_line_doc_comment_becomes_activation_description() {
let hub = SingleLineDocHub;
assert_eq!(hub.description(), "Foo");
let schema = hub.plugin_schema();
assert_eq!(schema.description, "Foo");
}
#[test]
fn single_line_doc_comment_becomes_method_description() {
let schema = SingleLineDocHub.plugin_schema();
let methods = &schema.methods;
let do_thing = methods.iter().find(|m| m.name == "do_thing").expect("do_thing method");
assert_eq!(do_thing.description, "Foo");
}
struct MultiLineDocHub;
#[plexus_macros::activation(namespace = "multi_line", version = "1.0.0", crate_path = "plexus_core")]
impl MultiLineDocHub {
#[plexus_macros::method]
async fn do_thing(&self) -> impl futures::stream::Stream<Item = String> + Send + 'static {
async_stream::stream! { yield "ok".into(); }
}
}
#[test]
fn multi_line_doc_comments_join_with_newlines_on_activation() {
let hub = MultiLineDocHub;
assert_eq!(hub.description(), "Foo\nBar");
}
#[test]
fn multi_line_doc_comments_join_with_newlines_on_method() {
let schema = MultiLineDocHub.plugin_schema();
let do_thing = schema.methods.iter().find(|m| m.name == "do_thing").expect("do_thing method");
assert_eq!(do_thing.description, "Foo\nBar");
}
struct ExplicitWinsHub;
#[plexus_macros::activation(
namespace = "explicit",
version = "1.0.0",
description = "Bar",
crate_path = "plexus_core"
)]
impl ExplicitWinsHub {
#[plexus_macros::method(description = "Bar")]
async fn do_thing(&self) -> impl futures::stream::Stream<Item = String> + Send + 'static {
async_stream::stream! { yield "ok".into(); }
}
}
#[test]
fn explicit_description_wins_over_doc_comment_on_activation() {
let hub = ExplicitWinsHub;
assert_eq!(hub.description(), "Bar");
}
#[test]
fn explicit_description_wins_over_doc_comment_on_method() {
let schema = ExplicitWinsHub.plugin_schema();
let do_thing = schema.methods.iter().find(|m| m.name == "do_thing").expect("do_thing method");
assert_eq!(do_thing.description, "Bar");
}
struct EmptyHub;
#[plexus_macros::activation(namespace = "empty", version = "1.0.0", crate_path = "plexus_core")]
impl EmptyHub {
#[plexus_macros::method]
async fn do_thing(&self) -> impl futures::stream::Stream<Item = String> + Send + 'static {
async_stream::stream! { yield "ok".into(); }
}
}
#[test]
fn no_doc_and_no_explicit_description_is_empty_on_activation() {
let hub = EmptyHub;
assert_eq!(hub.description(), "");
}
#[test]
fn no_doc_and_no_explicit_description_is_empty_on_method() {
let schema = EmptyHub.plugin_schema();
let do_thing = schema.methods.iter().find(|m| m.name == "do_thing").expect("do_thing method");
assert_eq!(do_thing.description, "");
}