-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test the interaction of inferred and default type parameters
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use textwrap::{NoHyphenation, Options}; | ||
|
||
/// Cleaned up type name. | ||
fn type_name<T: ?Sized>(_val: &T) -> String { | ||
std::any::type_name::<T>() | ||
.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<textwrap::HyphenSplitter>" | ||
); | ||
|
||
// Explicitly making both parameters inferred. | ||
let options: Options<'_, _> = Options::new(10); | ||
assert_eq!( | ||
type_name(&options), | ||
"textwrap::Options<textwrap::HyphenSplitter>" | ||
); | ||
} | ||
|
||
#[test] | ||
fn box_static_nohyphenation() { | ||
// Inferred static type. | ||
let options = Options::new(10).splitter(Box::new(NoHyphenation)); | ||
assert_eq!( | ||
type_name(&options), | ||
"textwrap::Options<Box<textwrap::NoHyphenation>>" | ||
); | ||
} | ||
|
||
#[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<Box<dyn textwrap::WordSplitter>>" | ||
); | ||
} |