| 1024 | |
| 1025 | #[tokio::test] |
| 1026 | async fn test_exec_yields_on_backward_jump() { |
| 1027 | let compiler = Compiler::new(&HashMap::default(), &[]).unwrap(); |
| 1028 | let image = compiler.compile(&mut b"x = 0: DO: x = x + 1: LOOP".as_slice()).unwrap(); |
| 1029 | let mut vm = Vm::new(HashMap::default()); |
| 1030 | |
| 1031 | match vm.exec(&image) { |
| 1032 | StopReason::Yield => (), |
| 1033 | _ => panic!("Execution should yield in a loop"), |
| 1034 | } |
| 1035 | assert_eq!( |
| 1036 | Some(ConstantDatum::Integer(1)), |
| 1037 | vm.get_program(&image, &SymbolKey::from("x")).unwrap() |
| 1038 | ); |
| 1039 | |
| 1040 | match vm.exec(&image) { |
| 1041 | StopReason::Yield => (), |
| 1042 | _ => panic!("Execution should continue yielding in a loop"), |
| 1043 | } |
| 1044 | assert_eq!( |
| 1045 | Some(ConstantDatum::Integer(2)), |
| 1046 | vm.get_program(&image, &SymbolKey::from("x")).unwrap() |
| 1047 | ); |
| 1048 | |
| 1049 | vm.interrupt(&image); |
| 1050 | match vm.exec(&image) { |
| 1051 | StopReason::Eof => (), |
| 1052 | _ => panic!("Execution should stop at EOF after interrupt"), |
| 1053 | } |
| 1054 | } |
| 1055 | |
| 1056 | #[tokio::test] |
| 1057 | async fn test_exec_yields_after_gosub_return() { |