File tree 1 file changed +29
-0
lines changed
1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -1648,6 +1648,7 @@ impl Interpreter {
1648
1648
. expect ( "time went backwards" )
1649
1649
. as_secs ( )
1650
1650
} ;
1651
+ stack. push_value ( self . rand_seed as f64 ) ?;
1651
1652
self . rand_seed = seed;
1652
1653
self . rng = SmallRng :: seed_from_u64 ( self . rand_seed ) ;
1653
1654
}
@@ -3625,4 +3626,32 @@ mod tests {
3625
3626
AwkValue :: field_ref( maybe_numeric_string( "1 2 3 4 " ) , 0 )
3626
3627
) ;
3627
3628
}
3629
+
3630
+ #[ test]
3631
+ fn test_srand_returns_the_previous_seed_value ( ) {
3632
+ let constants = vec ! [ Constant :: from( 42.0 ) ] ;
3633
+ let instructions = vec ! [
3634
+ OpCode :: PushConstant ( 0 ) ,
3635
+ OpCode :: CallBuiltin {
3636
+ function: BuiltinFunction :: Srand ,
3637
+ argc: 1 ,
3638
+ } ,
3639
+ ] ;
3640
+ let result = Test :: new ( instructions, constants. clone ( ) ) . run_correct ( ) ;
3641
+ assert_eq ! ( result. execution_result. unwrap_expr( ) , AwkValue :: from( 0.0 ) ) ;
3642
+
3643
+ let instructions = vec ! [
3644
+ OpCode :: PushConstant ( 0 ) ,
3645
+ OpCode :: CallBuiltin {
3646
+ function: BuiltinFunction :: Srand ,
3647
+ argc: 1 ,
3648
+ } ,
3649
+ OpCode :: CallBuiltin {
3650
+ function: BuiltinFunction :: Srand ,
3651
+ argc: 0 ,
3652
+ } ,
3653
+ ] ;
3654
+ let result = Test :: new ( instructions, constants) . run_correct ( ) ;
3655
+ assert_eq ! ( result. execution_result. unwrap_expr( ) , AwkValue :: from( 42.0 ) ) ;
3656
+ }
3628
3657
}
You can’t perform that action at this time.
0 commit comments