11use gdscript_formatter:: FormatterConfig ;
2- use gdscript_formatter:: formatter:: { format_gdscript , format_gdscript_with_config} ;
2+ use gdscript_formatter:: formatter:: format_gdscript_with_config;
33use similar:: { ChangeTag , TextDiff } ;
44use std:: fs;
55use std:: path:: Path ;
@@ -39,29 +39,21 @@ fn assert_formatted_eq(result: &str, expected: &str, file_path: &Path) {
3939}
4040
4141fn test_file ( file_path : & Path ) {
42- let file_name = file_path. file_name ( ) . expect ( "path is not a file path" ) ;
43-
44- let input_path = file_path;
45- let expected_path = file_path
46- . parent ( )
47- . unwrap ( )
48- . parent ( )
49- . unwrap ( )
50- . join ( "expected/" )
51- . join ( file_name) ;
52-
53- let input_content =
54- fs:: read_to_string ( & input_path) . expect ( & format ! ( "Failed to read {}" , input_path. display( ) ) ) ;
55- let expected_content = fs:: read_to_string ( & expected_path)
56- . expect ( & format ! ( "Failed to read {}" , expected_path. display( ) ) ) ;
57-
58- let result = format_gdscript ( & input_content)
59- . expect ( & format ! ( "Failed to format {}" , input_path. display( ) ) ) ;
60-
61- assert_formatted_eq ( & result, & expected_content, & input_path) ;
42+ test_file_with_config ( file_path, & FormatterConfig :: default ( ) , true ) ;
6243}
6344
6445fn test_reorder_file ( file_path : & Path ) {
46+ test_file_with_config (
47+ file_path,
48+ & FormatterConfig {
49+ reorder_code : true ,
50+ ..Default :: default ( )
51+ } ,
52+ true ,
53+ ) ;
54+ }
55+
56+ fn test_file_with_config ( file_path : & Path , config : & FormatterConfig , check_idempotence : bool ) {
6557 let file_name = file_path. file_name ( ) . expect ( "path is not a file path" ) ;
6658
6759 let input_path = file_path;
@@ -78,14 +70,15 @@ fn test_reorder_file(file_path: &Path) {
7870 let expected_content = fs:: read_to_string ( & expected_path)
7971 . expect ( & format ! ( "Failed to read {}" , expected_path. display( ) ) ) ;
8072
81- let result = format_gdscript_with_config (
82- & input_content,
83- & FormatterConfig {
84- reorder_code : true ,
85- ..Default :: default ( )
86- } ,
87- )
88- . expect ( & format ! ( "Failed to format {}" , input_path. display( ) ) ) ;
73+ let result = format_gdscript_with_config ( & input_content, config)
74+ . expect ( & format ! ( "Failed to format {}" , input_path. display( ) ) ) ;
8975
9076 assert_formatted_eq ( & result, & expected_content, & input_path) ;
77+
78+ if check_idempotence {
79+ let second_result = format_gdscript_with_config ( & result, config)
80+ . expect ( & format ! ( "Failed to format {}" , input_path. display( ) ) ) ;
81+ eprintln ! ( "Checking idempotence: " ) ;
82+ assert_formatted_eq ( & second_result, & result, & input_path) ;
83+ }
9184}
0 commit comments