fix a quoting bug in the order parser,
add a very basic test to make sure order parsing works.
This commit is contained in:
Enno Rehling 2010-11-05 22:54:29 -07:00
parent 12828f0edd
commit e7ce28a258
3 changed files with 60 additions and 8 deletions

View File

@ -769,17 +769,24 @@ function setup()
settings.set("rules.economy.food", "4")
end
local function assert_in_report(f, pattern)
local function find_in_report(f, pattern, extension)
extension = extension or "nr"
write_report(f)
local filename = config.basepath .. "/reports/" .. get_turn() .. "-" .. itoa36(f.id) .. ".nr"
local filename = config.basepath .. "/reports/" .. get_turn() .. "-" .. itoa36(f.id) .. "." .. extension
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()
local start, _ = string.find(t, pattern)
-- posix.unlink(filename)
return start~=nil
end
local function assert_in_report(f, pattern, extension)
assert_not_equal(nil, find_in_report(f, pattern, extension))
end
local function assert_not_in_report(f, pattern, extension)
assert_equal(nil, find_in_report(f, pattern, extension))
end
function test_coordinates_no_plane()
@ -816,3 +823,46 @@ function test_coordinates_noname_plane()
init_reports()
assert_in_report(f, r.name .. " %(0,0%), Berg")
end
module( "parser", package.seeall, lunit.testcase )
function setup()
free_game()
end
function test_parser()
local r = region.create(0, 0, "mountain")
local f = faction.create("noreply@eressea.de", "human", "de")
local u = unit.create(f, r, 1)
local filename = "1814.txt"
local file = io.open(filename, "w+")
file:write('ERESSEA ' .. itoa36(f.id) .. ' "' .. f.password .. '"\n')
file:write('EINHEIT ' .. itoa36(u.id) .. "\n")
file:write("LERNEN Hiebwaffen\n")
file:close()
read_orders(filename)
process_orders()
assert_not_equal(0, u:get_skill("melee"))
end
function test_bug_1814()
-- see http://bugs.eressea.de/view.php?id=1814
local r = region.create(0, 0, "mountain")
local f = faction.create("noreply@eressea.de", "human", "de")
local u = unit.create(f, r, 1)
local filename = "1814.txt"
local file = io.open(filename, "w+")
file:write('ERESSEA ' .. itoa36(f.id) .. ' "' .. f.password .. '"\n')
file:write('EINHEIT ' .. itoa36(u.id) .. "\n")
file:write("; parse error follows: '\n")
file:write("; ARBEITE\n")
file:close()
read_orders(filename)
process_orders()
init_reports()
assert_false(find_in_report(f, "Der Befehl wurde nicht erkannt", "cr"))
end

View File

@ -443,7 +443,7 @@ readorders(const char *filename)
}
fclose(F);
puts("\n");
if (verbosity>=1) puts("\n");
log_printf(" %d Befehlsdateien gelesen\n", nfactions);
return 0;
}

View File

@ -57,6 +57,7 @@ getbuf_latin1(FILE * F)
while (*bp && isxspace(*(unsigned char*)bp)) ++bp; /* eatwhite */
comment = (boolean)(comment && cont);
quote = (boolean)(quote && cont);
if (tail[1]==0) {
/* we read he maximum number of bytes! */
@ -189,9 +190,10 @@ getbuf_utf8(FILE * F)
bp += white;
comment = (boolean)(comment && cont);
quote = (boolean)(quote && cont);
if (tail[1]==0) {
/* we read he maximum number of bytes! */
/* we read the maximum number of bytes! */
if (tail[0]!='\n') {
/* it wasn't enough space to finish the line, eat the rest */
for (;;) {