1+ #![ allow( clippy:: inline_always, clippy:: unused_self) ]
12use std:: fmt:: { Display , Formatter , Write } ;
23
34use askama:: filters:: { Escaper as _, Html } ;
@@ -44,7 +45,12 @@ impl<'a> Span<'a> {
4445 }
4546}
4647
48+ #[ askama:: filter_fn]
4749pub fn mojang_colorize < T : Display > ( s : T , _: & dyn askama:: Values ) -> askama:: Result < String > {
50+ mojang_colorize_i ( s)
51+ }
52+
53+ pub fn mojang_colorize_i < T : Display > ( s : T ) -> askama:: Result < String > {
4854 let s = s. to_string ( ) ;
4955 let mut output = String :: new ( ) ;
5056 let mut last_was_section = false ;
@@ -94,8 +100,13 @@ pub fn mojang_colorize<T: Display>(s: T, _: &dyn askama::Values) -> askama::Resu
94100 Ok ( output)
95101}
96102
97- #[ allow ( clippy :: unnecessary_wraps ) ]
103+ #[ askama :: filter_fn ]
98104pub fn api_color < T : Display > ( s : T , _: & dyn askama:: Values ) -> askama:: Result < & ' static str > {
105+ api_color_i ( s)
106+ }
107+
108+ #[ allow( clippy:: unnecessary_wraps) ]
109+ pub fn api_color_i < T : Display > ( s : T ) -> askama:: Result < & ' static str > {
99110 Ok ( match s. to_string ( ) . as_str ( ) {
100111 "Operational" => "green" ,
101112 "PossibleProblems" => "yellow" ,
@@ -104,8 +115,13 @@ pub fn api_color<T: Display>(s: T, _: &dyn askama::Values) -> askama::Result<&'s
104115 } )
105116}
106117
107- #[ allow ( clippy :: unnecessary_wraps ) ]
118+ #[ askama :: filter_fn ]
108119pub fn api_words < T : Display > ( s : T , _: & dyn askama:: Values ) -> askama:: Result < & ' static str > {
120+ api_words_i ( s)
121+ }
122+
123+ #[ allow( clippy:: unnecessary_wraps) ]
124+ pub fn api_words_i < T : Display > ( s : T ) -> askama:: Result < & ' static str > {
109125 Ok ( match s. to_string ( ) . as_str ( ) {
110126 "Operational" => "OK" ,
111127 "PossibleProblems" => "Flaky" ,
@@ -116,23 +132,20 @@ pub fn api_words<T: Display>(s: T, _: &dyn askama::Values) -> askama::Result<&'s
116132
117133#[ cfg( test) ]
118134mod tests {
119-
120- use askama:: NO_VALUES ;
121-
122135 use super :: * ;
123136 #[ test]
124137 fn test_api_words ( ) {
125- assert_eq ! ( api_words ( "Operational" , NO_VALUES ) . unwrap( ) , "OK" ) ;
126- assert_eq ! ( api_words ( "PossibleProblems" , NO_VALUES ) . unwrap( ) , "Flaky" ) ;
127- assert_eq ! ( api_words ( "DefiniteProblems" , NO_VALUES ) . unwrap( ) , "Down" ) ;
128- assert_eq ! ( api_words ( "operational" , NO_VALUES ) . unwrap( ) , "Unknown" ) ;
138+ assert_eq ! ( api_words_i ( "Operational" ) . unwrap( ) , "OK" ) ;
139+ assert_eq ! ( api_words_i ( "PossibleProblems" ) . unwrap( ) , "Flaky" ) ;
140+ assert_eq ! ( api_words_i ( "DefiniteProblems" ) . unwrap( ) , "Down" ) ;
141+ assert_eq ! ( api_words_i ( "operational" ) . unwrap( ) , "Unknown" ) ;
129142 }
130143 #[ test]
131144 fn test_api_colors ( ) {
132- assert_eq ! ( api_color ( "Operational" , NO_VALUES ) . unwrap( ) , "green" ) ;
133- assert_eq ! ( api_color ( "PossibleProblems" , NO_VALUES ) . unwrap( ) , "yellow" ) ;
134- assert_eq ! ( api_color ( "DefiniteProblems" , NO_VALUES ) . unwrap( ) , "red" ) ;
135- assert_eq ! ( api_color ( "operational" , NO_VALUES ) . unwrap( ) , "blue" ) ;
145+ assert_eq ! ( api_color_i ( "Operational" ) . unwrap( ) , "green" ) ;
146+ assert_eq ! ( api_color_i ( "PossibleProblems" ) . unwrap( ) , "yellow" ) ;
147+ assert_eq ! ( api_color_i ( "DefiniteProblems" ) . unwrap( ) , "red" ) ;
148+ assert_eq ! ( api_color_i ( "operational" ) . unwrap( ) , "blue" ) ;
136149 }
137150 #[ test]
138151 fn test_span_no_color ( ) {
@@ -180,39 +193,39 @@ mod tests {
180193 fn test_colorize_none ( ) {
181194 let input = "No color codes" ;
182195 assert_eq ! (
183- mojang_colorize ( input, NO_VALUES ) . unwrap( ) ,
196+ mojang_colorize_i ( input) . unwrap( ) ,
184197 "<span class=\" \" >No color codes</span>"
185198 ) ;
186199 }
187200 #[ test]
188201 fn test_colorize_one_color ( ) {
189202 let input = "§acolor a" ;
190203 assert_eq ! (
191- mojang_colorize ( input, NO_VALUES ) . unwrap( ) ,
204+ mojang_colorize_i ( input) . unwrap( ) ,
192205 "<span class=\" motd-style-a \" >color a</span>"
193206 ) ;
194207 }
195208 #[ test]
196209 fn test_colorize_color_immediate_change ( ) {
197210 let input = "§a§bcolor b" ;
198211 assert_eq ! (
199- mojang_colorize ( input, NO_VALUES ) . unwrap( ) ,
212+ mojang_colorize_i ( input) . unwrap( ) ,
200213 "<span class=\" motd-style-b \" >color b</span>"
201214 ) ;
202215 }
203216 #[ test]
204217 fn test_colorize_color_reset ( ) {
205218 let input = "§acolor a§rblank§bcolor b" ;
206219 assert_eq ! (
207- mojang_colorize ( input, NO_VALUES ) . unwrap( ) ,
220+ mojang_colorize_i ( input) . unwrap( ) ,
208221 r#"<span class="motd-style-a ">color a</span><span class="">blank</span><span class="motd-style-b ">color b</span>"#
209222 ) ;
210223 }
211224 #[ test]
212225 fn test_colorize_additive ( ) {
213226 let input = "§a§nunderlined" ;
214227 assert_eq ! (
215- mojang_colorize ( input, NO_VALUES ) . unwrap( ) ,
228+ mojang_colorize_i ( input) . unwrap( ) ,
216229 r#"<span class="motd-style-a motd-style-n ">underlined</span>"#
217230 ) ;
218231 }
0 commit comments