diff options
author | Shmuel Zeigerman <solomuz0@gmail.com> | 2014-08-04 23:44:56 +0300 |
---|---|---|
committer | Shmuel Zeigerman <solomuz0@gmail.com> | 2014-08-04 23:44:56 +0300 |
commit | c2cc10463b5265cf613961718a5a56578ddf094d (patch) | |
tree | 5eb38b9a740573c675a78fa7dc01f0246bcca020 | |
parent | 18bace7048eb7778447e25db9eeb14c3fc7adf0d (diff) | |
download | lrexlib-c2cc10463b5265cf613961718a5a56578ddf094d.tar.gz |
1. Fix issue #8
2. Adapt tests for dfa_exec to run with PCRE 8.34.
-rw-r--r-- | src/algo.h | 10 | ||||
-rw-r--r-- | test/pcre_sets.lua | 12 |
2 files changed, 16 insertions, 6 deletions
@@ -119,8 +119,13 @@ static void check_subject (lua_State *L, int pos, TArgExec *argE) int stype; argE->text = lua_tolstring (L, pos, &argE->textlen); stype = lua_type (L, pos); +#if LUA_VERSION_NUM == 501 + if (stype != LUA_TSTRING && stype != LUA_TUSERDATA) { + luaL_typerror (L, pos, "string or userdata"); +#else if (stype != LUA_TSTRING && stype != LUA_TTABLE && stype != LUA_TUSERDATA) { luaL_typerror (L, pos, "string, table or userdata"); +#endif } else if (argE->text == NULL) { int type; lua_getfield (L, pos, "topointer"); @@ -135,7 +140,10 @@ static void check_subject (lua_State *L, int pos, TArgExec *argE) argE->text = lua_touserdata (L, -1); lua_pop (L, 1); #if LUA_VERSION_NUM == 501 - lua_objlen (L, pos); + if (!luaL_getmetafield (L, pos, "__len") || lua_type (L, -1) != LUA_TFUNCTION) + luaL_argerror (L, pos, "the userdata has no valid __len metafield"); + lua_pushvalue (L, pos); + lua_call (L, 1, 1); #else lua_len (L, pos); #endif diff --git a/test/pcre_sets.lua b/test/pcre_sets.lua index e2db7a9..79721b5 100644 --- a/test/pcre_sets.lua +++ b/test/pcre_sets.lua @@ -136,15 +136,17 @@ local function set_m_tfind (lib, flg) end local function set_m_dfa_exec (lib, flg) + local ver = tonumber(lib.version():match("%d+%.%d+")) + local NAP = ver < 8.34 and "" or "(*NO_AUTO_POSSESS)" return { Name = "Method dfa_exec", Method = "dfa_exec", --{patt,cf,lo}, {subj,st,ef,os,ws} { results } - { {".+"}, {"abcd"}, {1,{4,3,2,1},4} }, -- [none] - { {".+"}, {"abcd",2}, {2,{4,3,2}, 3} }, -- positive st - { {".+"}, {"abcd",-2}, {3,{4,3}, 2} }, -- negative st + { {NAP..".+"}, {"abcd"}, {1,{4,3,2,1},4} }, -- [none] + { {NAP..".+"}, {"abcd",2}, {2,{4,3,2}, 3} }, -- positive st + { {NAP..".+"}, {"abcd",-2}, {3,{4,3}, 2} }, -- negative st { {".+"}, {"abcd",5}, {N } }, -- failing st - { {".*"}, {"abcd"}, {1,{4,3,2,1,0},5}}, -- [none] + { {NAP..".*"}, {"abcd"}, {1,{4,3,2,1,0},5}}, -- [none] { {".*?"}, {"abcd"}, {1,{4,3,2,1,0},5}}, -- non-greedy { {"aBC",flg.CASELESS}, {"abc"}, {1,{3},1} }, -- cf { {"aBC","i" }, {"abc"}, {1,{3},1} }, -- cf @@ -154,7 +156,7 @@ local function set_m_dfa_exec (lib, flg) { { "(.)b.(d)"}, {"abcd"}, {1,{4},1} }, --[captures] { {"abc"}, {"ab"}, {N } }, { {"abc"}, {"ab",N,flg.PARTIAL}, {1,{2},flg.ERROR_PARTIAL} }, - { {".+"}, {string.rep("a",50),N,N,50,50}, {1, fill(50,26), 0}},-- small ovecsize + { {NAP..".+"}, {string.rep("a",50),N,N,50,50}, {1, fill(50,26), 0}},-- small ovecsize } end |