Changeset

12942:54756e3a54b9

util.table: Expand table.move() tests (thanks mutation testing)
author Matthew Wild <mwild1@gmail.com>
date Fri, 17 Mar 2023 17:06:05 +0000
parents 12941:e77c607e8da8
children 12943:297b4cfcc3d9
files spec/util_table_spec.lua
diffstat 1 files changed, 31 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/spec/util_table_spec.lua	Thu Mar 16 13:52:22 2023 +0100
+++ b/spec/util_table_spec.lua	Fri Mar 17 17:06:05 2023 +0000
@@ -22,6 +22,37 @@
 			u_table.move(t2, 1, 3, 3, t3);
 			assert.same({ "apple", "banana", "cat", "donkey", "elephant" }, t3);
 		end);
+		it("supports overlapping regions", function ()
+			do
+				local t1 = { "apple", "banana", "carrot", "date", "endive", "fig", "grapefruit" };
+				u_table.move(t1, 1, 3, 3);
+				assert.same({ "apple", "banana", "apple", "banana", "carrot", "fig", "grapefruit" }, t1);
+			end
+
+			do
+				local t1 = { "apple", "banana", "carrot", "date", "endive", "fig", "grapefruit" };
+				u_table.move(t1, 1, 3, 2);
+				assert.same({ "apple", "apple", "banana", "carrot", "endive", "fig", "grapefruit" }, t1);
+			end
+
+			do
+				local t1 = { "apple", "banana", "carrot", "date", "endive", "fig", "grapefruit" };
+				u_table.move(t1, 3, 5, 2);
+				assert.same({ "apple", "carrot", "date", "endive", "endive", "fig", "grapefruit" }, t1);
+			end
+
+			do
+				local t1 = { "apple", "banana", "carrot", "date", "endive", "fig", "grapefruit" };
+				u_table.move(t1, 3, 5, 6);
+				assert.same({ "apple", "banana", "carrot", "date", "endive", "carrot", "date", "endive" }, t1);
+			end
+
+			do
+				local t1 = { "apple", "banana", "carrot", "date", "endive", "fig", "grapefruit" };
+				u_table.move(t1, 3, 1, 3);
+				assert.same({ "apple", "banana", "carrot", "date", "endive", "fig", "grapefruit" }, t1);
+			end
+		end);
 	end);
 end);