for planes that have no name, do not print a comma after the coordinates (this has irritated me in E3).

also: add tests for this, and add a way to assert on content in reports.
This commit is contained in:
Enno Rehling 2010-11-05 21:21:49 -07:00
parent 33100abebb
commit 12828f0edd
3 changed files with 59 additions and 6 deletions

View File

@ -759,3 +759,60 @@ function test_walk_and_carry_the_cart()
process_orders() process_orders()
assert_equal(1, u.region.x) assert_equal(1, u.region.x)
end end
module( "report", package.seeall, lunit.testcase )
function setup()
free_game()
settings.set("nmr.removenewbie", "0")
settings.set("nmr.timeout", "0")
settings.set("rules.economy.food", "4")
end
local function assert_in_report(f, pattern)
write_report(f)
local filename = config.basepath .. "/reports/" .. get_turn() .. "-" .. itoa36(f.id) .. ".nr"
local report = io.open(filename, 'rt');
t = report:read("*all")
if string.find(t, pattern) == nil then
print(t, pattern)
end
assert_not_equal(nil, string.find(t, pattern))
report:close()
-- posix.unlink(filename)
end
function test_coordinates_no_plane()
local r = region.create(0, 0, "mountain")
local f = faction.create("noreply@eressea.de", "human", "de")
local u = unit.create(f, r, 1)
init_reports()
assert_in_report(f, r.name .. " %(0,0%), Berg")
end
function test_coordinates_named_plane()
local p = plane.create(0, -3, -3, 7, 7, "Hell")
local r = region.create(0, 0, "mountain")
local f = faction.create("noreply@eressea.de", "human", "de")
local u = unit.create(f, r, 1)
init_reports()
assert_in_report(f, r.name .. " %(0,0,Hell%), Berg")
end
function test_coordinates_unnamed_plane()
local p = plane.create(0, -3, -3, 7, 7)
local r = region.create(0, 0, "mountain")
local f = faction.create("noreply@eressea.de", "human", "de")
local u = unit.create(f, r, 1)
init_reports()
assert_in_report(f, r.name .. " %(0,0%), Berg")
end
function test_coordinates_noname_plane()
local p = plane.create(0, -3, -3, 7, 7, "")
local r = region.create(0, 0, "mountain")
local f = faction.create("noreply@eressea.de", "human", "de")
local u = unit.create(f, r, 1)
init_reports()
assert_in_report(f, r.name .. " %(0,0%), Berg")
end

View File

@ -53,8 +53,6 @@ int plane_height(const plane * pl)
return 0; return 0;
} }
static plane * home_plane = NULL;
plane * plane *
get_homeplane(void) get_homeplane(void)
{ {
@ -261,9 +259,6 @@ create_new_plane(int id, const char *name, int minx, int maxx, int miny, int max
pl->flags = flags; pl->flags = flags;
addlist(&planes, pl); addlist(&planes, pl);
if (id==0) {
home_plane = pl;
}
return pl; return pl;
} }

View File

@ -1615,11 +1615,12 @@ f_regionid(const region * r, const faction * f, char * buffer, size_t size)
plane * pl = rplane(r); plane * pl = rplane(r);
const char * name = pl?pl->name:0; const char * name = pl?pl->name:0;
int nx = r->x, ny = r->y; int nx = r->x, ny = r->y;
int named = (name && name[0]);
pnormalize(&nx, &ny, pl); pnormalize(&nx, &ny, pl);
adjust_coordinates(f, &nx, &ny, pl, r); adjust_coordinates(f, &nx, &ny, pl, r);
strncpy(buffer, rname(r, f->locale), size); strncpy(buffer, rname(r, f->locale), size);
buffer[size-1]=0; buffer[size-1]=0;
sprintf(buffer+strlen(buffer), " (%d,%d%s%s)", nx, ny, name?",":"", (name)?name:""); sprintf(buffer+strlen(buffer), " (%d,%d%s%s)", nx, ny, named?",":"", (named)?name:"");
} }
return strlen(buffer); return strlen(buffer);
} }