10
10
11
11
extern crate assert_cli;
12
12
13
+ use syntax;
14
+
13
15
use std:: collections:: { HashMap , HashSet } ;
14
16
use std:: env;
15
17
use std:: fs;
@@ -143,7 +145,7 @@ fn modified_test() {
143
145
let filename = "tests/writemode/source/modified.rs" ;
144
146
let result = get_modified_lines ( Input :: File ( filename. into ( ) ) , & Config :: default ( ) ) . unwrap ( ) ;
145
147
assert_eq ! (
146
- result. modified_lines ,
148
+ result,
147
149
ModifiedLines {
148
150
chunks: vec![
149
151
ModifiedChunk {
@@ -240,19 +242,13 @@ fn self_tests() {
240
242
#[ test]
241
243
fn stdin_formatting_smoke_test ( ) {
242
244
let input = Input :: Text ( "fn main () {}" . to_owned ( ) ) ;
243
- let config = Config :: default ( ) ;
244
- let ( error_summary, file_map, _report) =
245
- format_input :: < io:: Stdout > ( input, & config, None ) . unwrap ( ) ;
245
+ let mut config = Config :: default ( ) ;
246
+ config. set ( ) . write_mode ( WriteMode :: Display ) ;
247
+ let mut buf: Vec < u8 > = vec ! [ ] ;
248
+ let error_summary = format_input ( input, & config, Some ( & mut buf) ) . unwrap ( ) ;
246
249
assert ! ( error_summary. has_no_errors( ) ) ;
247
- for & ( ref file_name, ref text) in & file_map {
248
- if let FileName :: Custom ( ref file_name) = * file_name {
249
- if file_name == "stdin" {
250
- assert_eq ! ( text. to_string( ) , "fn main() {}\n " ) ;
251
- return ;
252
- }
253
- }
254
- }
255
- panic ! ( "no stdin" ) ;
250
+ //eprintln!("{:?}", );
251
+ assert_eq ! ( buf, "fn main() {}\n " . as_bytes( ) ) ;
256
252
}
257
253
258
254
// FIXME(#1990) restore this test
@@ -284,8 +280,7 @@ fn format_lines_errors_are_reported() {
284
280
let input = Input :: Text ( format ! ( "fn {}() {{}}" , long_identifier) ) ;
285
281
let mut config = Config :: default ( ) ;
286
282
config. set ( ) . error_on_line_overflow ( true ) ;
287
- let ( error_summary, _file_map, _report) =
288
- format_input :: < io:: Stdout > ( input, & config, None ) . unwrap ( ) ;
283
+ let error_summary = format_input :: < io:: Stdout > ( input, & config, None ) . unwrap ( ) ;
289
284
assert ! ( error_summary. has_formatting_errors( ) ) ;
290
285
}
291
286
@@ -296,8 +291,7 @@ fn format_lines_errors_are_reported_with_tabs() {
296
291
let mut config = Config :: default ( ) ;
297
292
config. set ( ) . error_on_line_overflow ( true ) ;
298
293
config. set ( ) . hard_tabs ( true ) ;
299
- let ( error_summary, _file_map, _report) =
300
- format_input :: < io:: Stdout > ( input, & config, None ) . unwrap ( ) ;
294
+ let error_summary = format_input :: < io:: Stdout > ( input, & config, None ) . unwrap ( ) ;
301
295
assert ! ( error_summary. has_formatting_errors( ) ) ;
302
296
}
303
297
@@ -382,7 +376,8 @@ fn read_config(filename: &Path) -> Config {
382
376
fn format_file < P : Into < PathBuf > > ( filepath : P , config : & Config ) -> ( Summary , FileMap , FormatReport ) {
383
377
let filepath = filepath. into ( ) ;
384
378
let input = Input :: File ( filepath) ;
385
- format_input :: < io:: Stdout > ( input, config, None ) . unwrap ( )
379
+ //format_input::<io::Stdout>(input, config, None).unwrap()
380
+ syntax:: with_globals ( || format_input_inner :: < io:: Stdout > ( input, config, None ) ) . unwrap ( )
386
381
}
387
382
388
383
pub enum IdempotentCheckError {
@@ -757,8 +752,7 @@ impl ConfigCodeBlock {
757
752
} ) ;
758
753
}
759
754
760
- fn formatted_has_diff ( & self , file_map : & FileMap ) -> bool {
761
- let & ( ref _file_name, ref text) = file_map. first ( ) . unwrap ( ) ;
755
+ fn formatted_has_diff ( & self , text : & str ) -> bool {
762
756
let compare = make_diff ( self . code_block . as_ref ( ) . unwrap ( ) , text, DIFF_CONTEXT_SIZE ) ;
763
757
if !compare. is_empty ( ) {
764
758
self . print_diff ( compare) ;
@@ -778,12 +772,14 @@ impl ConfigCodeBlock {
778
772
}
779
773
780
774
let input = Input :: Text ( self . code_block . as_ref ( ) . unwrap ( ) . to_owned ( ) ) ;
781
- let config = self . get_block_config ( ) ;
775
+ let mut config = self . get_block_config ( ) ;
776
+ config. set ( ) . write_mode ( WriteMode :: Display ) ;
777
+ let mut buf: Vec < u8 > = vec ! [ ] ;
782
778
783
- let ( error_summary, file_map, _report) =
784
- format_input :: < io:: Stdout > ( input, & config, None ) . unwrap ( ) ;
779
+ let error_summary = format_input ( input, & config, Some ( & mut buf) ) . unwrap ( ) ;
785
780
786
- !self . has_parsing_errors ( error_summary) && !self . formatted_has_diff ( & file_map)
781
+ !self . has_parsing_errors ( error_summary)
782
+ && !self . formatted_has_diff ( & String :: from_utf8 ( buf) . unwrap ( ) )
787
783
}
788
784
789
785
// Extract a code block from the iterator. Behavior:
0 commit comments