@@ -117,6 +117,34 @@ fn test_fun_to_str() {
117
117
assert fun_to_str( decl, "a" , [ ] ) == "fn a()" ;
118
118
}
119
119
120
+ fn res_to_str ( decl : ast:: fn_decl , name : ast:: ident ,
121
+ params : [ ast:: ty_param ] ) -> str {
122
+ let buffer = io:: mk_mem_buffer ( ) ;
123
+ let s = rust_printer ( io:: mem_buffer_writer ( buffer) ) ;
124
+ print_res ( s, decl, name, params) ;
125
+ end ( s) ; // Close the head box
126
+ end ( s) ; // Close the outer box
127
+ eof ( s. s ) ;
128
+ io:: mem_buffer_str ( buffer)
129
+ }
130
+
131
+ #[ test]
132
+ fn test_res_to_str ( ) {
133
+ let decl: ast:: fn_decl = {
134
+ inputs: [ {
135
+ mode: ast:: by_val,
136
+ ty: @ast_util:: respan ( ast_util:: dummy_sp ( ) , ast:: ty_bool) ,
137
+ ident: "b" ,
138
+ id: 0
139
+ } ] ,
140
+ output: @ast_util:: respan ( ast_util:: dummy_sp ( ) , ast:: ty_nil) ,
141
+ purity: ast:: impure_fn,
142
+ cf: ast:: return_val,
143
+ constraints: [ ]
144
+ } ;
145
+ assert res_to_str( decl, "a" , [ ] ) == "resource a(b: bool)" ;
146
+ }
147
+
120
148
fn block_to_str ( blk : ast:: blk ) -> str {
121
149
let buffer = io:: mk_mem_buffer ( ) ;
122
150
let s = rust_printer ( io:: mem_buffer_writer ( buffer) ) ;
@@ -498,20 +526,25 @@ fn print_item(s: ps, &&item: @ast::item) {
498
526
bclose ( s, item. span ) ;
499
527
}
500
528
ast:: item_res ( decl, tps, body, dt_id, ct_id) {
501
- head ( s, "resource" ) ;
502
- word ( s. s , item. ident ) ;
503
- print_type_params ( s, tps) ;
504
- popen ( s) ;
505
- word_space ( s, decl. inputs [ 0 ] . ident + ":" ) ;
506
- print_type ( s, decl. inputs [ 0 ] . ty ) ;
507
- pclose ( s) ;
508
- space ( s. s ) ;
529
+ print_res ( s, decl, item. ident , tps) ;
509
530
print_block ( s, body) ;
510
531
}
511
532
}
512
533
s. ann . post ( ann_node) ;
513
534
}
514
535
536
+ fn print_res ( s : ps , decl : ast:: fn_decl , name : ast:: ident ,
537
+ typarams : [ ast:: ty_param ] ) {
538
+ head ( s, "resource" ) ;
539
+ word ( s. s , name) ;
540
+ print_type_params ( s, typarams) ;
541
+ popen ( s) ;
542
+ word_space ( s, decl. inputs [ 0 ] . ident + ":" ) ;
543
+ print_type ( s, decl. inputs [ 0 ] . ty ) ;
544
+ pclose ( s) ;
545
+ space ( s. s ) ;
546
+ }
547
+
515
548
fn print_variant ( s : ps , v : ast:: variant ) {
516
549
word ( s. s , v. node . name ) ;
517
550
if vec:: len ( v. node . args ) > 0 u {
0 commit comments