@@ -29,6 +29,23 @@ fn bad(lines: &str, expected_msg: &str) {
2929 test ( lines, "bad" , expected_msg, true ) ;
3030}
3131
32+ #[ track_caller]
33+ fn bless_test ( before : & str , after : & str ) {
34+ let tempfile = tempfile:: Builder :: new ( ) . tempfile ( ) . unwrap ( ) ;
35+ std:: fs:: write ( tempfile. path ( ) , before) . unwrap ( ) ;
36+
37+ let tidy_ctx = TidyCtx :: new ( Path :: new ( "/" ) , false , TidyFlags :: new ( & [ "--bless" . to_owned ( ) ] ) ) ;
38+
39+ let mut check = tidy_ctx. start_check ( "alphabetical-test" ) ;
40+ check_lines ( tempfile. path ( ) , before, & tidy_ctx, & mut check) ;
41+
42+ assert ! ( !check. is_bad( ) ) ;
43+ let new = std:: fs:: read_to_string ( tempfile. path ( ) ) . unwrap ( ) ;
44+ assert_eq ! ( new, after) ;
45+
46+ good ( & new) ;
47+ }
48+
3249#[ test]
3350fn test_no_markers ( ) {
3451 let lines = "\
@@ -396,3 +413,93 @@ fn multiline() {
396413 " ;
397414 good ( lines) ;
398415}
416+
417+ #[ test]
418+ fn bless_smoke ( ) {
419+ let before = "\
420+ tidy-alphabetical-start
421+ 08
422+ 1
423+ 11
424+ 03
425+ tidy-alphabetical-end
426+ " ;
427+ let after = "\
428+ tidy-alphabetical-start
429+ 1
430+ 03
431+ 08
432+ 11
433+ tidy-alphabetical-end
434+ " ;
435+
436+ bless_test ( before, after) ;
437+ }
438+
439+ #[ test]
440+ fn bless_multiline ( ) {
441+ let before = "\
442+ tidy-alphabetical-start
443+ 08 {
444+ z}
445+ 08 {
446+ x
447+ }
448+ 1
449+ 08 {y}
450+ 02
451+ 11 (
452+ 0
453+ )
454+ 03
455+ addition
456+ notaddition
457+ tidy-alphabetical-end
458+ " ;
459+ let after = "\
460+ tidy-alphabetical-start
461+ 1
462+ 02
463+ 03
464+ addition
465+ 08 {
466+ x
467+ }
468+ 08 {y}
469+ 08 {
470+ z}
471+ 11 (
472+ 0
473+ )
474+ notaddition
475+ tidy-alphabetical-end
476+ " ;
477+
478+ bless_test ( before, after) ;
479+ }
480+
481+ #[ test]
482+ fn bless_funny_numbers ( ) {
483+ // Because `2` is indented it gets merged into one entry with `1` and gets
484+ // interpreted by version sort as `12`, which is greater than `3`.
485+ //
486+ // This is neither a wanted nor an unwanted behavior, this test just checks
487+ // that it hasn't changed.
488+
489+ let before = "\
490+ tidy-alphabetical-start
491+ 1
492+ 2
493+ 3
494+ tidy-alphabetical-end
495+ " ;
496+ let after = "\
497+ tidy-alphabetical-start
498+ 3
499+ 1
500+ 2
501+ tidy-alphabetical-end
502+ " ;
503+
504+ bless_test ( before, after) ;
505+ }
0 commit comments