diff --git a/tests/traits.rs b/tests/traits.rs new file mode 100644 index 00000000..e2ef46a5 --- /dev/null +++ b/tests/traits.rs @@ -0,0 +1,45 @@ +use textwrap::{NoHyphenation, Options}; + +/// Cleaned up type name. +fn type_name(_val: &T) -> String { + std::any::type_name::() + .replace("alloc::boxed::Box", "Box") + .replace("textwrap::splitting", "textwrap") +} + +#[test] +fn static_hyphensplitter() { + // Inferring the full type. + let options = Options::new(10); + assert_eq!( + type_name(&options), + "textwrap::Options" + ); + + // Explicitly making both parameters inferred. + let options: Options<'_, _> = Options::new(10); + assert_eq!( + type_name(&options), + "textwrap::Options" + ); +} + +#[test] +fn box_static_nohyphenation() { + // Inferred static type. + let options = Options::new(10).splitter(Box::new(NoHyphenation)); + assert_eq!( + type_name(&options), + "textwrap::Options>" + ); +} + +#[test] +fn box_dyn_wordsplitter() { + // Inferred dynamic type due to default type parameter. + let options: Options = Options::new(10).splitter(Box::new(NoHyphenation)); + assert_eq!( + type_name(&options), + "textwrap::Options>" + ); +}