@@ -345,6 +345,86 @@ public class MyClass {
345345 failed ++ ;
346346 }
347347
348+ // Test 11: Comment indentation is preserved after sorting
349+ try {
350+ const source = `public class MyClass {
351+ // 静态方法
352+ public static void log(String msg) {
353+ System.out.println("LOG: " + msg);
354+ }
355+
356+ // 受保护方法
357+ protected void finalizeTask() {
358+ System.out.println("Finalize");
359+ }
360+ }` ;
361+ const options : SortingOptions = {
362+ sortingStrategy : 'depth-first' ,
363+ applyWorkingListHeuristics : false ,
364+ respectBeforeAfterRelation : false ,
365+ clusterOverloadedMethods : false ,
366+ clusterGetterSetter : false ,
367+ separateByAccessLevel : false ,
368+ separateConstructors : false ,
369+ applyLexicalOrdering : false
370+ } ;
371+ const sorter = new JavaMethodSorter ( options ) ;
372+ const sorted = sorter . sort ( source ) ;
373+
374+ // Comments should maintain their indentation (4 spaces before //)
375+ if ( sorted . includes ( ' // 静态方法' ) && sorted . includes ( ' // 受保护方法' ) ) {
376+ console . log ( '✓ Test 11 passed: Comment indentation is preserved' ) ;
377+ passed ++ ;
378+ } else {
379+ console . log ( '✗ Test 11 failed: Comment indentation not preserved' ) ;
380+ console . log ( 'Sorted output:' , sorted ) ;
381+ failed ++ ;
382+ }
383+ } catch ( e ) {
384+ console . log ( '✗ Test 11 failed with error:' , e ) ;
385+ failed ++ ;
386+ }
387+
388+ // Test 12: No double blank lines between methods after sorting
389+ try {
390+ const source = `public class MyClass {
391+ protected void methodA() {
392+ System.out.println("A");
393+ }
394+
395+ private void methodB() {
396+ System.out.println("B");
397+ }
398+ }` ;
399+ const options : SortingOptions = {
400+ sortingStrategy : 'depth-first' ,
401+ applyWorkingListHeuristics : false ,
402+ respectBeforeAfterRelation : false ,
403+ clusterOverloadedMethods : false ,
404+ clusterGetterSetter : false ,
405+ separateByAccessLevel : true ,
406+ separateConstructors : false ,
407+ applyLexicalOrdering : false
408+ } ;
409+ const sorter = new JavaMethodSorter ( options ) ;
410+ const sorted = sorter . sort ( source ) ;
411+
412+ // Should not have triple newlines (two blank lines) between methods
413+ // Check that closing braces are followed by at most one blank line
414+ const hasDoubleBlankLines = / \} \n \n \n / . test ( sorted ) ;
415+ if ( ! hasDoubleBlankLines ) {
416+ console . log ( '✓ Test 12 passed: No double blank lines between methods' ) ;
417+ passed ++ ;
418+ } else {
419+ console . log ( '✗ Test 12 failed: Found double blank lines between methods' ) ;
420+ console . log ( 'Sorted output:' , sorted ) ;
421+ failed ++ ;
422+ }
423+ } catch ( e ) {
424+ console . log ( '✗ Test 12 failed with error:' , e ) ;
425+ failed ++ ;
426+ }
427+
348428 console . log ( `\nResults: ${ passed } passed, ${ failed } failed` ) ;
349429}
350430
0 commit comments