]> granicus.if.org Git - nethack/commitdiff
Add test for selection.iterate
authorPasi Kallinen <paxed@alt.org>
Mon, 13 Apr 2020 17:29:06 +0000 (20:29 +0300)
committerPasi Kallinen <paxed@alt.org>
Mon, 13 Apr 2020 17:29:06 +0000 (20:29 +0300)
test/test_sel.lua

index 91f4754f58526550903fd1bfe57f97339cba9f30..b2ad83753f1aa24e0dc9e4b7437f19d47353452c 100644 (file)
@@ -39,6 +39,18 @@ function sel_are_equal(sela, selb, msg)
    end
 end
 
+function is_map_at(x,y, mapch, lit)
+   local rm = nh.getmap(x + 1, y); -- + 1 == g.xstart
+   if rm.mapchr ~= mapch then
+      error("Terrain at (" .. x .. "," .. y .. ") is not \"" .. mapch .. "\", but \"" .. rm.mapchr .. "\"");
+   end
+   if lit ~= nil then
+      if rm.lit ~= lit then
+         error("light state at (" .. x .. "," .. y .. ") is not \"" .. lit .. "\", but \"" .. tostring(rm.lit) .. "\"");
+      end
+   end
+end
+
 -- test selection parameters
 function test_selection_params()
    local sel = selection.new();
@@ -401,6 +413,22 @@ function test_sel_match()
    sel_pt_ne(seld, 6,5, 1, __func__);
 end -- test_sel_match
 
+function test_sel_iterate()
+   local __func__ = "test_sel_iterate";
+   des.reset_level();
+   des.level_init({ style = "solidfill", fg = " " });
+
+   des.terrain(5,5, ".");
+   des.terrain(7,5, ".");
+   des.terrain(9,5, ".");
+
+   local sela = selection.match(".");
+   sela:iterate(function(x,y) des.terrain(x, y, "L"); end);
+   is_map_at(5,5, "L");
+   is_map_at(7,5, "L");
+   is_map_at(9,5, "L");
+end
+
 test_selection_params();
 test_sel_negate();
 test_sel_logical_and();
@@ -415,3 +443,4 @@ test_sel_grow();
 test_sel_filter_mapchar();
 test_sel_flood();
 test_sel_match();
+test_sel_iterate();