@@ -57,3 +57,44 @@ impl From<&std::path::Path> for DataFormat {
5757 }
5858 }
5959}
60+
61+ #[ cfg( test) ]
62+ mod test {
63+ use super :: * ;
64+
65+ #[ test]
66+ fn combos ( ) {
67+ #[ cfg( feature = "json" ) ]
68+ let json = DataFormat :: Json ;
69+ #[ cfg( not( feature = "json" ) ) ]
70+ let json = DataFormat :: Text ;
71+ #[ cfg( feature = "json" ) ]
72+ let jsonl = DataFormat :: JsonLines ;
73+ #[ cfg( not( feature = "json" ) ) ]
74+ let jsonl = DataFormat :: Text ;
75+ #[ cfg( feature = "term-svg" ) ]
76+ let term_svg = DataFormat :: TermSvg ;
77+ #[ cfg( not( feature = "term-svg" ) ) ]
78+ let term_svg = DataFormat :: Text ;
79+ let cases = [
80+ ( "foo" , DataFormat :: Text ) ,
81+ ( ".foo" , DataFormat :: Text ) ,
82+ ( "foo.txt" , DataFormat :: Text ) ,
83+ ( ".foo.txt" , DataFormat :: Text ) ,
84+ ( "foo.stdout.txt" , DataFormat :: Text ) ,
85+ ( "foo.json" , json) ,
86+ ( "foo.stdout.json" , DataFormat :: Text ) ,
87+ ( ".foo.json" , DataFormat :: Text ) ,
88+ ( "foo.jsonl" , jsonl) ,
89+ ( "foo.stdout.jsonl" , DataFormat :: Text ) ,
90+ ( ".foo.jsonl" , DataFormat :: Text ) ,
91+ ( "foo.term.svg" , term_svg) ,
92+ ( "foo.stdout.term.svg" , DataFormat :: Text ) ,
93+ ( ".foo.term.svg" , DataFormat :: Text ) ,
94+ ] ;
95+ for ( input, output) in cases {
96+ let input = std:: path:: Path :: new ( input) ;
97+ assert_eq ! ( DataFormat :: from( input) , output, "for `{}`" , input. display( ) ) ;
98+ }
99+ }
100+ }
0 commit comments