Skip to content

Commit a630f6b

Browse files
committed
feat: copy marks
apply one task plan marks to another
1 parent b8d47e6 commit a630f6b

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

lib/roby/plan.rb

+9
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,15 @@ def finalize_event(event, timestamp = nil)
16091609
event.finalized!(timestamp)
16101610
end
16111611

1612+
# Apply to +to+ the marks (permanent, mission) of +from+
1613+
#
1614+
# It does not remove any marks from +from+
1615+
def copy_task_marks(to:, from:)
1616+
add_permanent_task(to) if permanent_task?(from)
1617+
1618+
add_mission_task(to) if mission_task?(from)
1619+
end
1620+
16121621
def remove_task(task, timestamp = Time.now)
16131622
verify_plan_object_finalization_sanity(task)
16141623
remove_task!(task, timestamp)

test/test_plan.rb

+32
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,38 @@ def prepare_mappings(mappings)
885885
end
886886
end
887887

888+
describe "#copy_task_marks" do
889+
attr_reader :task_1, :task_2
890+
891+
before do
892+
plan.add(@task_1 = Roby::Task.new)
893+
plan.add(@task_2 = Roby::Task.new)
894+
end
895+
896+
it "copies mission mark from one task to the other" do
897+
plan.add_mission_task(task_1)
898+
899+
plan.copy_task_marks(from: task_1, to: task_2)
900+
assert_equal plan.mission_task?(task_1), plan.mission_task?(task_2)
901+
end
902+
903+
it "copies permanent mark from one task to the other" do
904+
plan.add_permanent_task(task_1)
905+
906+
plan.copy_task_marks(from: task_1, to: task_2)
907+
assert_equal plan.permanent_task?(task_1), plan.permanent_task?(task_2)
908+
end
909+
910+
it "does not unmark +to+ task" do
911+
plan.add_mission_task(task_2)
912+
913+
plan.copy_task_marks(from: task_1, to: task_2)
914+
915+
refute plan.permanent_task?(task_2)
916+
assert plan.mission_task?(task_2)
917+
end
918+
end
919+
888920
describe "#remove_task" do
889921
before do
890922
plan.add(@task = Roby::Task.new)

0 commit comments

Comments
 (0)