From 0da90941ef9f9405ee4cf2d3794cba54453539ad Mon Sep 17 00:00:00 2001 From: Devin Jean Date: Wed, 15 Nov 2023 09:29:02 -0600 Subject: [PATCH] test remaining stop variants --- Cargo.toml | 2 +- src/bytecode.rs | 3 + src/project.rs | 2 +- src/test/project.rs | 156 +++++++++++++++++- src/test/projects/stop-all.xml | 1 + .../{stop-script.xml => stop-current.xml} | 0 src/test/projects/stop-my-others-context.xml | 1 + src/test/projects/stop-my-others.xml | 1 + src/test/projects/stop-others.xml | 1 + 9 files changed, 163 insertions(+), 4 deletions(-) create mode 100644 src/test/projects/stop-all.xml rename src/test/projects/{stop-script.xml => stop-current.xml} (100%) create mode 100644 src/test/projects/stop-my-others-context.xml create mode 100644 src/test/projects/stop-my-others.xml create mode 100644 src/test/projects/stop-others.xml diff --git a/Cargo.toml b/Cargo.toml index 85eee6f..39c631b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "netsblox-vm" -version = "0.2.20" +version = "0.2.21" edition = "2021" license = "MIT OR Apache-2.0" authors = ["Devin Jean "] diff --git a/src/bytecode.rs b/src/bytecode.rs index b57d2a4..c5c3ef0 100644 --- a/src/bytecode.rs +++ b/src/bytecode.rs @@ -1844,6 +1844,9 @@ impl<'a: 'b, 'b> ByteCodeBuilder<'a, 'b> { ast::StmtKind::NextCostume => self.ins.push(Instruction::NextCostume.into()), ast::StmtKind::PenClear => self.ins.push(Instruction::ClearDrawings.into()), ast::StmtKind::Stop { mode: ast::StopMode::ThisScript } => self.ins.push(Instruction::Abort { mode: AbortMode::Current }.into()), + ast::StmtKind::Stop { mode: ast::StopMode::All } => self.ins.push(Instruction::Abort { mode: AbortMode::All }.into()), + ast::StmtKind::Stop { mode: ast::StopMode::AllButThisScript } => self.ins.push(Instruction::Abort { mode: AbortMode::Others }.into()), + ast::StmtKind::Stop { mode: ast::StopMode::OtherScriptsInSprite } => self.ins.push(Instruction::Abort { mode: AbortMode::MyOthers }.into()), ast::StmtKind::Stop { mode: ast::StopMode::ThisBlock } => { self.ins.push(Instruction::PushString { value: "" }.into()); self.ins.push(Instruction::Return.into()); diff --git a/src/project.rs b/src/project.rs index 9a5ce7f..5de8b54 100644 --- a/src/project.rs +++ b/src/project.rs @@ -386,7 +386,7 @@ impl<'gc, C: CustomTypes, S: System> Project<'gc, C, S> { } AbortMode::MyOthers => { debug_assert!(proc.is_running()); - let entity = proc.get_call_stack().first().unwrap().entity; + let entity = proc.get_call_stack().last().unwrap().entity; self.state.processes.retain_mut(|k, v| k == proc_key || !Gc::ptr_eq(entity, v.get_call_stack().first().unwrap().entity)); self.state.process_queue.push_front(proc_key); // keep executing the calling process ProjectStep::Normal diff --git a/src/test/project.rs b/src/test/project.rs index a6f5bf2..c03803c 100644 --- a/src/test/project.rs +++ b/src/test/project.rs @@ -248,9 +248,9 @@ fn test_proj_watchers() { } #[test] -fn test_proj_stop_script() { +fn test_proj_stop_current() { let system = Rc::new(StdSystem::new_sync(BASE_URL.to_owned(), None, default_properties_config(), Arc::new(Clock::new(UtcOffset::UTC, None)))); - let proj = get_running_project(include_str!("projects/stop-script.xml"), system); + let proj = get_running_project(include_str!("projects/stop-current.xml"), system); proj.mutate(|mc, proj| { run_till_term(mc, &mut *proj.proj.borrow_mut(mc)).unwrap(); let global_context = proj.proj.borrow().get_global_context(); @@ -280,6 +280,158 @@ fn test_proj_stop_script() { }); } +#[test] +fn test_proj_stop_all() { + let system = Rc::new(StdSystem::new_sync(BASE_URL.to_owned(), None, default_properties_config(), Arc::new(Clock::new(UtcOffset::UTC, None)))); + let proj = get_running_project(include_str!("projects/stop-all.xml"), system); + proj.mutate(|mc, proj| { + run_till_term(mc, &mut *proj.proj.borrow_mut(mc)).unwrap(); + let global_context = proj.proj.borrow().get_global_context(); + let global_context = global_context.borrow(); + + let expected = Value::from_simple(mc, SimpleValue::from_json(json!([ + ["1", 1], + ["2", 1], + ["3", 1], + ["4", 1], + ["5", 1], + ["6", 1], + ["7", 1], + ["8", 1], + ["1", 2], + ["2", 2], + ["3", 2], + ["4", 2], + ])).unwrap()); + assert_values_eq(&global_context.globals.lookup("res").unwrap().get(), &expected, 1e-10, "res"); + }); +} + +#[test] +fn test_proj_stop_others() { + let system = Rc::new(StdSystem::new_sync(BASE_URL.to_owned(), None, default_properties_config(), Arc::new(Clock::new(UtcOffset::UTC, None)))); + let proj = get_running_project(include_str!("projects/stop-others.xml"), system); + proj.mutate(|mc, proj| { + run_till_term(mc, &mut *proj.proj.borrow_mut(mc)).unwrap(); + let global_context = proj.proj.borrow().get_global_context(); + let global_context = global_context.borrow(); + + let expected = Value::from_simple(mc, SimpleValue::from_json(json!([ + ["1", 1], + ["2", 1], + ["3", 1], + ["4", 1], + ["5", 1], + ["6", 1], + ["7", 1], + ["8", 1], + ["1", 2], + ["2", 2], + ["3", 2], + ["4", 2], + ["4", 3], + ["4", 4], + ["4", 5], + ["4", 6], + ["4", 7], + ["4", 8], + ["4", 9], + ["4", 10], + ])).unwrap()); + assert_values_eq(&global_context.globals.lookup("res").unwrap().get(), &expected, 1e-10, "res"); + }); +} + +#[test] +fn test_proj_stop_my_others() { + let system = Rc::new(StdSystem::new_sync(BASE_URL.to_owned(), None, default_properties_config(), Arc::new(Clock::new(UtcOffset::UTC, None)))); + let proj = get_running_project(include_str!("projects/stop-my-others.xml"), system); + proj.mutate(|mc, proj| { + run_till_term(mc, &mut *proj.proj.borrow_mut(mc)).unwrap(); + let global_context = proj.proj.borrow().get_global_context(); + let global_context = global_context.borrow(); + + let expected = Value::from_simple(mc, SimpleValue::from_json(json!([ + ["1", 1], + ["2", 1], + ["3", 1], + ["4", 1], + ["5", 1], + ["6", 1], + ["7", 1], + ["8", 1], + ["1", 2], + ["2", 2], + ["3", 2], + ["4", 2], + ["5", 2], + ["6", 2], + ["7", 2], + ["8", 2], + ["4", 3], + ["5", 3], + ["6", 3], + ["7", 3], + ["8", 3], + ["4", 4], + ["5", 4], + ["6", 4], + ["4", 5], + ["6", 5], + ["4", 6], + ["6", 6], + ["4", 7], + ["6", 7], + ["4", 8], + ["6", 8], + ["4", 9], + ["6", 9], + ["4", 10], + ["6", 10], + ])).unwrap()); + assert_values_eq(&global_context.globals.lookup("res").unwrap().get(), &expected, 1e-10, "res"); + }); +} + +#[test] +fn test_proj_stop_my_others_context() { + let system = Rc::new(StdSystem::new_sync(BASE_URL.to_owned(), None, default_properties_config(), Arc::new(Clock::new(UtcOffset::UTC, None)))); + let proj = get_running_project(include_str!("projects/stop-my-others-context.xml"), system); + proj.mutate(|mc, proj| { + run_till_term(mc, &mut *proj.proj.borrow_mut(mc)).unwrap(); + let global_context = proj.proj.borrow().get_global_context(); + let global_context = global_context.borrow(); + + let expected = Value::from_simple(mc, SimpleValue::from_json(json!([ + ["1", 1], + ["2", 1], + ["3", 1], + ["4", 1], + ["1", 2], + ["2", 2], + ["3", 2], + ["4", 2], + ["1", 3], + ["2", 3], + ["1", 4], + ["2", 4], + ["1", 5], + ["2", 5], + ["1", 6], + ["2", 6], + ["1", 7], + ["2", 7], + ["1", 8], + ["2", 8], + ["1", 9], + ["2", 9], + ["1", 10], + ["2", 10], + ])).unwrap()); + assert_values_eq(&global_context.globals.lookup("res").unwrap().get(), &expected, 1e-10, "res"); + }); +} + #[test] fn test_proj_costumes() { let config = Config::> { diff --git a/src/test/projects/stop-all.xml b/src/test/projects/stop-all.xml new file mode 100644 index 0000000..d63a748 --- /dev/null +++ b/src/test/projects/stop-all.xml @@ -0,0 +1 @@ +messagemsg
\ No newline at end of file diff --git a/src/test/projects/stop-script.xml b/src/test/projects/stop-current.xml similarity index 100% rename from src/test/projects/stop-script.xml rename to src/test/projects/stop-current.xml diff --git a/src/test/projects/stop-my-others-context.xml b/src/test/projects/stop-my-others-context.xml new file mode 100644 index 0000000..922176b --- /dev/null +++ b/src/test/projects/stop-my-others-context.xml @@ -0,0 +1 @@ +messagemsg \ No newline at end of file diff --git a/src/test/projects/stop-my-others.xml b/src/test/projects/stop-my-others.xml new file mode 100644 index 0000000..29a8a17 --- /dev/null +++ b/src/test/projects/stop-my-others.xml @@ -0,0 +1 @@ +messagemsg
\ No newline at end of file diff --git a/src/test/projects/stop-others.xml b/src/test/projects/stop-others.xml new file mode 100644 index 0000000..8b3a765 --- /dev/null +++ b/src/test/projects/stop-others.xml @@ -0,0 +1 @@ +messagemsg
\ No newline at end of file