Skip to content

Commit

Permalink
test remaining stop variants
Browse files Browse the repository at this point in the history
  • Loading branch information
dragazo committed Nov 15, 2023
1 parent 06b9ace commit 0da9094
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
Expand Down
3 changes: 3 additions & 0 deletions src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ impl<'gc, C: CustomTypes<S>, S: System<C>> 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
Expand Down
156 changes: 154 additions & 2 deletions src/test/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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::<C, StdSystem<C>> {
Expand Down
1 change: 1 addition & 0 deletions src/test/projects/stop-all.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<room name="untitled (2) (3)" app="NetsBlox 2.1.6, http://netsblox.org"><role name="myRole"><project collabStartIndex="112" name="myRole" app="NetsBlox 2.1.6, http://netsblox.org" version="2.1.6"><notes></notes><stage name="Stage" width="480" height="360" collabId="item_-1_1" costume="0" color="255,255,255,1" tempo="60" threadsafe="false" penlog="false" volume="100" pan="0" lines="round" ternary="false" hyperops="true" codify="false" inheritance="false" sublistIDs="false" scheduled="false" id="1"><costumes><list struct="atomic" id="2"></list></costumes><sounds><list struct="atomic" id="3"></list></sounds><variables></variables><blocks></blocks><messageTypes><messageType><name>message</name><fields><field>msg</field></fields></messageType></messageTypes><scripts></scripts><sprites><sprite name="Sprite" collabId="item_-1" idx="1" x="0" y="0" heading="90" scale="1" volume="100" pan="0" rotation="1" draggable="true" costume="0" color="80,80,80,1" pen="tip" id="10"><costumes><list struct="atomic" id="11"></list></costumes><sounds><list struct="atomic" id="12"></list></sounds><blocks></blocks><variables></variables><scripts><script x="14.285714285714286" y="14.285714285714286"><block collabId="item_32" s="doSetVar"><l>res</l><block collabId="item_34" s="reportNewList"><list></list></block></block></script><script x="14.285714285714286" y="49.714285714285694"><block collabId="item_21_2" s="receiveGo"></block><block collabId="item_24" s="doFor"><l>i</l><l>1</l><l>10</l><script><block collabId="item_76" s="doAddToList"><block collabId="item_74" s="reportNewList"><list><l>1</l><block collabId="item_75" var="i"/></list></block><block collabId="item_78" var="res"/></block><block collabId="item_39" s="doIf"><block collabId="item_45" s="reportEquals"><block collabId="item_46" var="i"/><l>7</l></block><script><block collabId="item_55" s="doStopThis"><l><option>all</option></l></block></script></block></script></block></script><script x="14.285714285714286" y="214.0714285714285"><block collabId="item_22" s="receiveGo"></block><block collabId="item_25" s="doFor"><l>i</l><l>1</l><l>10</l><script><block collabId="item_81" s="doAddToList"><block collabId="item_81_1" s="reportNewList"><list><l>2</l><block collabId="item_81_3" var="i"/></list></block><block collabId="item_81_2" var="res"/></block><block collabId="item_42" s="doIf"><block collabId="item_49" s="reportEquals"><block collabId="item_49_1" var="i"/><l>3</l></block><script><custom-block collabId="item_64" s="die"></custom-block></script></block></script></block></script><script x="14.285714285714286" y="374.3095238095238"><block collabId="item_23" s="receiveGo"></block><block collabId="item_27" s="doFor"><l>i</l><l>1</l><l>10</l><script><block collabId="item_83" s="doAddToList"><block collabId="item_83_1" s="reportNewList"><list><l>3</l><block collabId="item_83_3" var="i"/></list></block><block collabId="item_83_2" var="res"/></block><block collabId="item_44" s="doIf"><block collabId="item_51" s="reportEquals"><block collabId="item_51_1" var="i"/><l>6</l></block><script><block collabId="item_67" s="doRun"><block collabId="item_67_1" s="reifyScript"><script><block collabId="item_68" s="doStopThis"><l><option>all</option></l></block></script><list></list></block><list></list></block></script></block></script></block></script><script x="14.285714285714286" y="551.0952380952375"><block collabId="item_65" s="receiveGo"></block><block collabId="item_65_1" s="doFor"><l>i</l><l>1</l><l>10</l><script><block collabId="item_90" s="doAddToList"><block collabId="item_90_1" s="reportNewList"><list><l>4</l><block collabId="item_90_3" var="i"/></list></block><block collabId="item_90_2" var="res"/></block><block collabId="item_65_2" s="doIf"><block collabId="item_65_3" s="reportEquals"><block collabId="item_65_4" var="i"/><l>2</l></block><script><block collabId="item_71" s="doTellTo"><l>Stage</l><block collabId="item_71_1" s="reifyScript"><script><custom-block collabId="item_73" s="die"></custom-block></script><list></list></block><list></list></block></script></block></script></block></script></scripts><history></history></sprite><watcher var="res" style="normal" x="10" y="10" color="243,118,29" extX="112" extY="98.00000000000001"/><sprite name="Sprite(2)" collabId="item_95" idx="2" x="0" y="0" heading="90" scale="1" volume="100" pan="0" rotation="1" draggable="true" costume="0" color="80,80,80,1" pen="tip" id="136"><costumes><list struct="atomic" id="137"></list></costumes><sounds><list struct="atomic" id="138"></list></sounds><blocks></blocks><variables></variables><scripts><script x="14.285714285714286" y="14.285714285714286"><block collabId="item_95_96" s="doSetVar"><l>res</l><block collabId="item_95_94" s="reportNewList"><list></list></block></block></script><script x="14.285714285714286" y="49.714285714285694"><block collabId="item_95_91" s="receiveGo"></block><block collabId="item_95_90" s="doFor"><l>i</l><l>1</l><l>10</l><script><block collabId="item_95_85" s="doAddToList"><block collabId="item_95_84" s="reportNewList"><list><l>5</l><block collabId="item_95_81" var="i"/></list></block><block collabId="item_95_80" var="res"/></block><block collabId="item_95_79" s="doIf"><block collabId="item_95_78" s="reportEquals"><block collabId="item_95_77" var="i"/><l>6</l></block><script><block collabId="item_95_74" s="doStopThis"><l><option>all</option></l></block></script></block></script></block></script><script x="14.285714285714286" y="214.0714285714285"><block collabId="item_95_70" s="receiveGo"></block><block collabId="item_95_69" s="doFor"><l>i</l><l>1</l><l>10</l><script><block collabId="item_95_64" s="doAddToList"><block collabId="item_95_63" s="reportNewList"><list><l>6</l><block collabId="item_95_60" var="i"/></list></block><block collabId="item_95_59" var="res"/></block><block collabId="item_95_58" s="doIf"><block collabId="item_95_57" s="reportEquals"><block collabId="item_95_56" var="i"/><l>4</l></block><script><custom-block collabId="item_95_53" s="die"></custom-block></script></block></script></block></script><script x="14.285714285714286" y="374.3095238095238"><block collabId="item_95_51" s="receiveGo"></block><block collabId="item_95_50" s="doFor"><l>i</l><l>1</l><l>10</l><script><block collabId="item_95_45" s="doAddToList"><block collabId="item_95_44" s="reportNewList"><list><l>7</l><block collabId="item_95_41" var="i"/></list></block><block collabId="item_95_40" var="res"/></block><block collabId="item_95_39" s="doIf"><block collabId="item_95_38" s="reportEquals"><block collabId="item_95_37" var="i"/><l>8</l></block><script><block collabId="item_95_34" s="doRun"><block collabId="item_95_33" s="reifyScript"><script><block collabId="item_95_31" s="doStopThis"><l><option>all</option></l></block></script><list></list></block><list></list></block></script></block></script></block></script><script x="14.285714285714286" y="551.0952380952375"><block collabId="item_95_25" s="receiveGo"></block><block collabId="item_95_24" s="doFor"><l>i</l><l>1</l><l>10</l><script><block collabId="item_95_19" s="doAddToList"><block collabId="item_95_18" s="reportNewList"><list><l>8</l><block collabId="item_95_15" var="i"/></list></block><block collabId="item_95_14" var="res"/></block><block collabId="item_95_13" s="doIf"><block collabId="item_95_12" s="reportEquals"><block collabId="item_95_11" var="i"/><l>5</l></block><script><block collabId="item_95_8" s="doTellTo"><l>Stage</l><block collabId="item_95_6" s="reifyScript"><script><custom-block collabId="item_95_4" s="die"></custom-block></script><list></list></block><list></list></block></script></block></script></block></script></scripts><history></history></sprite></sprites></stage><hidden></hidden><headers></headers><code></code><blocks><block-definition collabId="item_60" s="die" type="command" category="custom"><header></header><code></code><translations></translations><inputs></inputs><script><custom-block collabId="item_62" s="die die"></custom-block></script></block-definition><block-definition collabId="item_61" s="die die" type="command" category="custom"><header></header><code></code><translations></translations><inputs></inputs><script><block collabId="item_63" s="doStopThis"><l><option>all</option></l></block></script></block-definition></blocks><variables><variable name="res"><list struct="atomic" id="270"></list></variable></variables><history></history><replay></replay></project><media name="myRole" app="NetsBlox 2.1.6, http://netsblox.org" version="2.1.6"></media></role></room>
File renamed without changes.
Loading

0 comments on commit 0da9094

Please sign in to comment.