fix line/column calculation for JSON Errors.

+ start building a test for http://bugs.eressea.de/view.php?id=1692
This commit is contained in:
Enno Rehling 2014-07-02 21:17:31 -07:00
parent ee1d97df19
commit b5439a1279
4 changed files with 67 additions and 15 deletions

View file

@ -36,8 +36,9 @@ int config_parse(const char *json)
int line; int line;
char buffer[10]; char buffer[10];
const char *xp = json, *lp, *ep = cJSON_GetErrorPtr(); const char *xp = json, *lp, *ep = cJSON_GetErrorPtr();
for (line=0,lp=xp;xp && xp<ep;++line,lp=xp+1) { for (line=1,lp=xp;xp && xp<ep;++line,lp=xp+1) {
xp = strchr(lp, '\n'); xp = strchr(lp, '\n');
if (xp>=ep) break;
} }
xp = (ep > json + 10) ? ep - 10 : json; xp = (ep > json + 10) ? ep - 10 : json;
strncpy(buffer, xp, sizeof(buffer)); strncpy(buffer, xp, sizeof(buffer));

View file

@ -1170,7 +1170,10 @@ param_t findparam(const char *s, const struct locale * lang)
const void * match; const void * match;
void **tokens = get_translations(lang, UT_PARAMS); void **tokens = get_translations(lang, UT_PARAMS);
critbit_tree *cb = (critbit_tree *)*tokens; critbit_tree *cb = (critbit_tree *)*tokens;
if (cb_find_prefix(cb, str, strlen(str), &match, 1, 0)) { if (!cb) {
log_error_n("no parameters defined in locale %s", locale_name(lang));
}
else if (cb_find_prefix(cb, str, strlen(str), &match, 1, 0)) {
cb_get_kv(match, &i, sizeof(int)); cb_get_kv(match, &i, sizeof(int));
result = (param_t)i; result = (param_t)i;
} }

View file

@ -7,3 +7,4 @@ require "tests.ships"
require "tests.study" require "tests.study"
require "tests.movement" require "tests.movement"
require "tests.castles" require "tests.castles"
require "tests.spells"

47
tests/spells.lua Normal file
View file

@ -0,0 +1,47 @@
require "lunit"
module("tests.spells", package.seeall, lunit.testcase)
function setup()
eressea.game.reset()
eressea.settings.set("nmr.removenewbie", "0")
eressea.settings.set("nmr.timeout", "0")
conf = [[{
"races": {
"human" : {}
},
"terrains" : {
"plain": { "flags" : [ "land", "walk", "sail" ] }
},
"spells" : {
"resist_magic" : {
"index" : 97,
"parameters" : "u+"
}
},
"keywords" : {
"de" : {
"cast" : "ZAUBERE"
}
},
"strings" : {
"de" : {
"harbour" : "Hafen"
}
}
}]]
eressea.config.reset()
assert(eressea.config.parse(conf)==0)
end
function test_antimagic_visibility()
local r = region.create(0, 0, "plain")
local f1 = faction.create("test@example.com", "human", "de")
local mage = unit.create(f1, r, 1)
local target = unit.create(f1, r, 1)
mage:set_skill("magic", 10)
mage:add_spell("resist_magic")
mage:add_order("ZAUBERE Antimagie " .. target.id)
process_orders()
end