File tree Expand file tree Collapse file tree
src/commands/fix_lock_files Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -715,4 +715,86 @@ version = "0.2.0"
715715 "Cargo.lock should not contain the corrupted version 0.99.99"
716716 ) ;
717717 }
718+
719+ #[ test]
720+ fn test_normalize_lockfile_sorts_patch_unused ( ) {
721+ let input = "\
722+ # This file is automatically @generated by Cargo.
723+ # It is not intended for manual editing.
724+ version = 4
725+
726+ [[package]]
727+ name = \" some-crate\"
728+ version = \" 1.0.0\"
729+
730+ [[patch.unused]]
731+ name = \" wgpu\"
732+ version = \" 24.0.5\"
733+ source = \" git+https://example.com#abc\"
734+
735+ [[patch.unused]]
736+ name = \" naga\"
737+ version = \" 24.0.0\"
738+ source = \" git+https://example.com#abc\"
739+
740+ [[patch.unused]]
741+ name = \" wgpu-types\"
742+ version = \" 24.0.0\"
743+ source = \" git+https://example.com#abc\"
744+ " ;
745+
746+ let expected = "\
747+ # This file is automatically @generated by Cargo.
748+ # It is not intended for manual editing.
749+ version = 4
750+
751+ [[package]]
752+ name = \" some-crate\"
753+ version = \" 1.0.0\"
754+
755+ [[patch.unused]]
756+ name = \" naga\"
757+ version = \" 24.0.0\"
758+ source = \" git+https://example.com#abc\"
759+
760+ [[patch.unused]]
761+ name = \" wgpu\"
762+ version = \" 24.0.5\"
763+ source = \" git+https://example.com#abc\"
764+
765+ [[patch.unused]]
766+ name = \" wgpu-types\"
767+ version = \" 24.0.0\"
768+ source = \" git+https://example.com#abc\"
769+ " ;
770+
771+ assert_eq ! ( normalize_lockfile( input) , expected) ;
772+ }
773+
774+ #[ test]
775+ fn test_normalize_lockfile_no_patch_unused ( ) {
776+ let input = "\
777+ # This file is automatically @generated by Cargo.
778+ version = 4
779+
780+ [[package]]
781+ name = \" test\"
782+ version = \" 0.1.0\"
783+ " ;
784+ assert_eq ! ( normalize_lockfile( input) , input) ;
785+ }
786+
787+ #[ test]
788+ fn test_normalize_lockfile_already_sorted ( ) {
789+ let input = "\
790+ [[patch.unused]]
791+ name = \" alpha\"
792+ version = \" 1.0.0\"
793+
794+ [[patch.unused]]
795+ name = \" beta\"
796+ version = \" 1.0.0\"
797+ " ;
798+ assert_eq ! ( normalize_lockfile( input) , input) ;
799+ }
718800}
You can’t perform that action at this time.
0 commit comments