@@ -845,6 +845,54 @@ fn common_timespan_constructors_have_composable_machine_fixes() {
845845 . expect ( "applying every constructor migration fix should produce valid source" ) ;
846846}
847847
848+ #[ test]
849+ fn timespan_zero_migrates_to_the_duration_constructor ( ) {
850+ use splitscript:: FixApplicability ;
851+
852+ let source = r#"
853+ state "game.exe" {}
854+
855+ gameTime {
856+ return TimeSpan.Zero
857+ }
858+ "# ;
859+ let parsed = splitscript:: parse_recovering ( source) . unwrap ( ) ;
860+ assert_eq ! ( parsed. diagnostics( ) . len( ) , 1 ) ;
861+ let type_edit = & parsed. diagnostics ( ) [ 0 ] . fixes [ 0 ] . edits [ 0 ] ;
862+ assert_eq ! (
863+ & source[ type_edit. span. start..type_edit. span. end] ,
864+ "TimeSpan"
865+ ) ;
866+ assert_eq ! ( type_edit. replacement, "Duration" ) ;
867+
868+ let mut fixed = source. to_owned ( ) ;
869+ fixed. replace_range (
870+ type_edit. span . start ..type_edit. span . end ,
871+ & type_edit. replacement ,
872+ ) ;
873+ let diagnostics = splitscript:: compile ( & fixed)
874+ . expect_err ( "the C# static property still needs a constructor-call rewrite" ) ;
875+ assert_eq ! ( diagnostics. len( ) , 1 ) ;
876+ let diagnostic = & diagnostics[ 0 ] ;
877+ assert_eq ! (
878+ & fixed[ diagnostic. span. start..diagnostic. span. end] ,
879+ "Duration.Zero"
880+ ) ;
881+ assert_eq ! ( diagnostic. fixes. len( ) , 1 ) ;
882+ assert_eq ! (
883+ diagnostic. fixes[ 0 ] . applicability,
884+ FixApplicability :: MachineApplicable
885+ ) ;
886+ let value_edit = & diagnostic. fixes [ 0 ] . edits [ 0 ] ;
887+ assert_eq ! ( value_edit. replacement, "Duration.zero()" ) ;
888+ fixed. replace_range (
889+ value_edit. span . start ..value_edit. span . end ,
890+ & value_edit. replacement ,
891+ ) ;
892+
893+ splitscript:: compile ( & fixed) . expect ( "the fully migrated zero duration should compile" ) ;
894+ }
895+
848896#[ test]
849897fn legacy_process_identity_points_to_the_attached_process_api ( ) {
850898 use splitscript:: FixApplicability ;
0 commit comments