7777 }
7878
7979 fn to_code_block_with_language < S : AsRef < str > > ( & self , language : S ) -> String {
80- format ! ( "```{}\n {}\n ```" , language. as_ref( ) , self . as_ref( ) )
80+ format ! (
81+ "```{}\n {}\n ```" ,
82+ language. as_ref( ) . to_lowercase( ) ,
83+ self . as_ref( )
84+ )
8185 }
8286}
8387
@@ -129,7 +133,7 @@ where
129133#[ cfg( test) ]
130134mod tests {
131135 use super :: { BlockQuote , Bold , Inline , Italic } ;
132- use crate :: transforms:: Strikethrough ;
136+ use crate :: { transforms:: Strikethrough , CodeBlock } ;
133137
134138 #[ test]
135139 fn test_block_quote_single_line ( ) {
@@ -151,35 +155,38 @@ mod tests {
151155 fn test_bold ( ) {
152156 let text = "text" ;
153157 assert_eq ! ( "**text**" , text. to_bold( ) ) ;
154-
155- let text = String :: from ( "text" ) ;
156- assert_eq ! ( String :: from( "**text**" ) , text. to_bold( ) ) ;
157158 }
158159
159160 #[ test]
160161 fn test_inline ( ) {
161162 let text = "text" ;
162163 assert_eq ! ( "`text`" , text. to_inline( ) ) ;
163-
164- let text = String :: from ( "text" ) ;
165- assert_eq ! ( String :: from( "`text`" ) , text. to_inline( ) ) ;
166164 }
167165
168166 #[ test]
169167 fn test_italic ( ) {
170168 let text = "text" ;
171169 assert_eq ! ( "*text*" , text. to_italic( ) ) ;
172-
173- let text = String :: from ( "text" ) ;
174- assert_eq ! ( String :: from( "*text*" ) , text. to_italic( ) ) ;
175170 }
176171
177172 #[ test]
178173 fn test_strikethrough ( ) {
179174 let text = "text" ;
180175 assert_eq ! ( "~~text~~" , text. to_strikethrough( ) ) ;
176+ }
181177
182- let text = String :: from ( "text" ) ;
183- assert_eq ! ( String :: from( "~~text~~" ) , text. to_strikethrough( ) )
178+ #[ test]
179+ fn test_code_block ( ) {
180+ let text = "println!(\" Hello world\" )" ;
181+ assert_eq ! ( "```\n println!(\" Hello world\" )\n ```" , text. to_code_block( ) ) ;
182+ }
183+
184+ #[ test]
185+ fn test_code_block_with_language ( ) {
186+ let text = "println!(\" Hello world\" )" ;
187+ assert_eq ! (
188+ "```rust\n println!(\" Hello world\" )\n ```" ,
189+ text. to_code_block_with_language( "Rust" )
190+ ) ;
184191 }
185192}
0 commit comments