@@ -9,6 +9,7 @@ use proptest::sample::select;
99use proptest:: strategy:: ValueTree ;
1010use proptest:: test_runner:: TestRunner ;
1111use proptest_derive:: Arbitrary ;
12+ use quote:: { quote, ToTokens } ;
1213
1314#[ derive( Debug , Arbitrary , Display , Clone ) ]
1415#[ allow( non_camel_case_types) ]
@@ -106,40 +107,39 @@ impl Display for FormatArgument {
106107}
107108
108109fn test (
109- value : impl Display ,
110- converter : impl Display ,
110+ value : impl ToTokens ,
111+ converter : impl ToTokens ,
111112 strategy : impl Strategy < Value = FormatArgument > ,
112113) {
113114 let mut runner = TestRunner :: deterministic ( ) ;
114- let values: Vec < _ > = iter:: repeat_with ( || strategy. new_tree ( & mut runner) )
115- . take ( 100 )
116- . map ( |s| s. unwrap ( ) . current ( ) )
117- . map ( |format_arg| {
118- let format_arg = format_arg. to_string ( ) ;
119- let format_arg = format_arg. escape_default ( ) ;
120- format ! ( r#"
121- assert_eq!(
122- format("{format_arg}", [("ident", Formattable::{converter}(&{value}))].into_iter().collect()).unwrap(),
123- format!("{format_arg}", ident = {value}),
124- "{{}}", "{format_arg}"
125- );"# )
126- } )
127- . collect ( ) ;
128- let values = values. join ( "\n " ) ;
115+ let format_args = iter:: repeat_with ( || strategy. new_tree ( & mut runner) )
116+ . take ( 1000 )
117+ . map ( |s| s. unwrap ( ) . current ( ) . to_string ( ) ) ;
129118 let t = trybuild2:: TestCases :: new ( ) ;
130- t. pass_inline ( & converter. to_string ( ) , & format ! { r#"
131- use template::{{format, Formattable}};
132- fn main() {{
133- {values}
134- }}
135- "# } ) ;
119+ t. pass_inline (
120+ & converter. to_token_stream ( ) . to_string ( ) ,
121+ & quote ! {
122+ use template:: { { format, Formattable } } ;
123+ use std:: thread;
124+ fn main( ) {
125+ thread:: spawn( move ||{
126+ let value = & [ ( "ident" , Formattable :: #converter( & #value) ) ] . into_iter( ) . collect( ) ;
127+ #( assert!(
128+ format( #format_args, value) . unwrap( ) == format!( #format_args, ident = #value) ,
129+ "{}" , #format_args
130+ ) ; ) *
131+ } ) . join( ) . unwrap( ) ;
132+ }
133+ }
134+ . to_string ( ) ,
135+ ) ;
136136}
137137
138138#[ test]
139139fn string ( ) {
140140 test (
141141 "\" test\" " ,
142- " debug_display" ,
142+ quote ! ( debug_display) ,
143143 FormatArgument :: arbitrary_with ( & [
144144 Trait :: Display ,
145145 Trait :: Question ,
@@ -153,7 +153,7 @@ fn string() {
153153fn integer ( ) {
154154 test (
155155 42 ,
156- " integer" ,
156+ quote ! ( integer) ,
157157 FormatArgument :: arbitrary_with ( & [
158158 Trait :: Display ,
159159 Trait :: Question ,
@@ -172,7 +172,7 @@ fn integer() {
172172fn float ( ) {
173173 test (
174174 PI ,
175- " float" ,
175+ quote ! ( float) ,
176176 FormatArgument :: arbitrary_with ( & [
177177 Trait :: Display ,
178178 Trait :: Question ,
@@ -186,8 +186,8 @@ fn float() {
186186#[ test]
187187fn pointer ( ) {
188188 test (
189- " &42" ,
190- " pointer" ,
189+ quote ! ( & 42 ) ,
190+ quote ! ( pointer) ,
191191 FormatArgument :: arbitrary_with ( & [ Trait :: p] ) ,
192192 ) ;
193193}
0 commit comments