This repository was archived by the owner on Oct 17, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +27
-22
lines changed Expand file tree Collapse file tree 2 files changed +27
-22
lines changed Original file line number Diff line number Diff line change @@ -61,19 +61,23 @@ impl Tables {
61
61
}
62
62
next. push ( String :: new ( ) ) ;
63
63
for ( name, next_name) in zip ( order. iter ( ) , next. iter ( ) ) {
64
- let mut entries = self . get ( name) . unwrap ( ) . borrow ( ) . clone ( ) ;
65
- if entries. is_empty ( ) {
66
- continue ;
67
- }
68
- entry_count += entries. len ( ) ;
69
- let last = entries. last ( ) . unwrap ( ) ;
70
- if name. is_empty ( ) && last. kind ( ) == SyntaxKind :: NEWLINE && entries. len ( ) == 1 {
71
- continue ;
72
- }
73
- if last. kind ( ) == SyntaxKind :: NEWLINE && get_key ( name) != get_key ( next_name) {
74
- entries. splice ( entries. len ( ) - 1 ..entries. len ( ) , [ make_empty_newline ( ) ] ) ;
64
+ let entries = self . get ( name) . unwrap ( ) . borrow ( ) ;
65
+ if !entries. is_empty ( ) {
66
+ entry_count += entries. len ( ) ;
67
+ let last = entries. last ( ) . unwrap ( ) ;
68
+ if name. is_empty ( ) && last. kind ( ) == SyntaxKind :: NEWLINE && entries. len ( ) == 1 {
69
+ continue ;
70
+ }
71
+ let mut add = entries. clone ( ) ;
72
+ if get_key ( name) != get_key ( next_name) {
73
+ if last. kind ( ) == SyntaxKind :: NEWLINE {
74
+ // replace existing newline to ensure single newline
75
+ add. pop ( ) ;
76
+ }
77
+ add. push ( make_empty_newline ( ) ) ;
78
+ }
79
+ to_insert. extend ( add) ;
75
80
}
76
- to_insert. extend ( entries) ;
77
81
}
78
82
root_ast. splice_children ( 0 ..entry_count, to_insert) ;
79
83
}
Original file line number Diff line number Diff line change @@ -195,6 +195,7 @@ mod tests {
195
195
"Programming Language :: Python :: 3 :: Only",
196
196
"Programming Language :: Python :: 3.8",
197
197
]
198
+
198
199
[tool.coverage]
199
200
a = 0
200
201
[tool.coverage.report]
@@ -215,16 +216,16 @@ mod tests {
215
216
#[ case] keep_full_version : bool ,
216
217
#[ case] max_supported_python : ( u8 , u8 ) ,
217
218
) {
218
- let got = format_toml (
219
- start,
220
- & Settings {
221
- column_width : 1 ,
222
- indent,
223
- keep_full_version,
224
- max_supported_python,
225
- min_supported_python : ( 3 , 8 ) ,
226
- } ,
227
- ) ;
219
+ let settings = Settings {
220
+ column_width : 1 ,
221
+ indent,
222
+ keep_full_version,
223
+ max_supported_python,
224
+ min_supported_python : ( 3 , 8 ) ,
225
+ } ;
226
+ let got = format_toml ( start, & settings) ;
228
227
assert_eq ! ( got, expected) ;
228
+ let second = format_toml ( got. as_str ( ) , & settings) ;
229
+ assert_eq ! ( got, second) ;
229
230
}
230
231
}
You can’t perform that action at this time.
0 commit comments