diff options
author | shmuz <shmuz> | 2007-04-19 07:02:33 +0000 |
---|---|---|
committer | shmuz <shmuz> | 2007-04-19 07:02:33 +0000 |
commit | 0ff6b1ed54f366b76dc74be466ead118c94e3ab4 (patch) | |
tree | 9a2338a7a7dea8b259ce8a447b293aa7d317c065 /test | |
parent | 63cdc5a4fa6b6f11f782c40995779a2a3af6db98 (diff) | |
download | lrexlib-0ff6b1ed54f366b76dc74be466ead118c94e3ab4.tar.gz |
many changes -- see Changelog
Diffstat (limited to 'test')
-rwxr-xr-x | test/common_sets.lua | 9 | ||||
-rwxr-xr-x | test/pcre_sets.lua | 54 | ||||
-rwxr-xr-x | test/pcre_sets2.lua | 9 | ||||
-rwxr-xr-x | test/runtest.lua | 12 |
4 files changed, 78 insertions, 6 deletions
diff --git a/test/common_sets.lua b/test/common_sets.lua index 8104f60..614b15d 100755 --- a/test/common_sets.lua +++ b/test/common_sets.lua @@ -53,15 +53,18 @@ local function set_f_split (lib, flg) Func = test_split, --{ subj patt results } { {"ab", ","}, {{"ab",N,N}, } }, - { {",", ","}, {{"",",",N}, } }, - { {",,", ","}, {{"",",",N}, {"",",",N}, } }, + { {",", ","}, {{"",",",N}, {"", N, N}, } }, + { {",,", ","}, {{"",",",N}, {"",",",N}, {"",N,N} } }, { {"a,b", ","}, {{"a",",",N}, {"b",N,N}, } }, { {",a,b", ","}, {{"",",",N}, {"a",",",N}, {"b",N,N}} }, - { {"a,b,", ","}, {{"a",",",N}, {"b",",",N}, } }, + { {"a,b,", ","}, {{"a",",",N}, {"b",",",N}, {"",N,N} } }, { {"a,,b", ","}, {{"a",",",N}, {"",",",N}, {"b",N,N}} }, { {"ab<78>c", "<(.)(.)>"}, {{"ab","7","8"}, {"c",N,N}, } }, { {"a,\0,c", ","}, {{"a",",",N},{"\0",",",N},{"c",N,N}, } },--nuls in subj { {"abc", "^."}, {{"", "a",N}, {"bc",N,N}, } },--anchored pattern + { {"abc", "^"}, {{"", "", N}, {"abc",N,N}, } }, +-- { {"abc", "$"}, {{"abc","",N}, {"",N,N}, } }, +-- { {"abc", "^|$"}, {{"", "", N}, {"abc","",N},{"",N,N},} }, } end diff --git a/test/pcre_sets.lua b/test/pcre_sets.lua index 1897398..0538d1c 100755 --- a/test/pcre_sets.lua +++ b/test/pcre_sets.lua @@ -26,6 +26,9 @@ local function set_named_subpatterns (lib, flg) end local function set_f_find (lib, flg) + local cp1251 = + "ÀÁÂÃÄŨÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÜÛÚÝÞßàáâãäå¸æçèéêëìíîïðñòóôõö÷øùüûúýþÿ" + local loc = "Russian_Russia.1251" return { Name = "Function find", Func = lib.find, @@ -35,6 +38,8 @@ local function set_f_find (lib, flg) { {"abc", "aBC", N,flg.CASELESS}, { 1,3 } }, -- cf { {"abc", "bc", N,N,flg.ANCHORED}, { N } }, -- cf { {"abc", "bc", N,N,flg.ANCHORED}, { N } }, -- ef + { {cp1251, "[[:upper:]]+", N,N,N, loc}, { 1,33} }, -- locale + { {cp1251, "[[:lower:]]+", N,N,N, loc}, {34,66} }, -- locale } end @@ -51,6 +56,53 @@ local function set_f_match (lib, flg) } end +local function set_f_gmatch (lib, flg) + -- gmatch (s, p, [cf], [ef]) + local pCSV = "(^[^,]*)|,([^,]*)" + local F = false + local function test_gmatch (subj, patt) + local out, guard = {}, 10 + for a, b in lib.gmatch (subj, patt) do + table.insert (out, { norm(a), norm(b) }) + guard = guard - 1 + if guard == 0 then break end + end + return unpack (out) + end + return { + Name = "Function gmatch", + Func = test_gmatch, + --{ subj patt results } + { {"", pCSV}, {{"",F}} }, + { {"12", pCSV}, {{"12",F}} }, + { {",", pCSV}, {{"", F},{F,""}} }, + { {"12,,45", pCSV}, {{"12",F},{F,""},{F,"45"}} }, + { {",,12,45,,ab,", pCSV}, {{"",F},{F,""},{F,"12"},{F,"45"},{F,""},{F,"ab"},{F,""}} }, + } +end + +local function set_f_split (lib, flg) + -- split (s, p, [cf], [ef]) + local function test_split (subj, patt) + local out, guard = {}, 10 + for a, b, c in lib.split (subj, patt) do + table.insert (out, { norm(a), norm(b), norm(c) }) + guard = guard - 1 + if guard == 0 then break end + end + return unpack (out) + end + return { + Name = "Function split", + Func = test_split, + --{ subj patt results } + { {"ab", "$"}, {{"ab","",N}, {"",N,N}, } }, + { {"ab", "^|$"}, {{"", "", N}, {"ab","",N}, {"",N,N}, } }, + { {"ab45ab","(?<=ab).*?"}, {{"ab","",N}, {"45ab","",N},{"",N,N}, } }, + { {"ab", "\\b"}, {{"", "", N}, {"ab","",N}, {"",N,N}, } }, + } +end + local function set_m_exec (lib, flg) return { Name = "Method exec", @@ -105,6 +157,8 @@ return function (libname) local sets = { set_f_match (lib, flags), set_f_find (lib, flags), + set_f_gmatch (lib, flags), + set_f_split (lib, flags), set_m_exec (lib, flags), set_m_tfind (lib, flags), } diff --git a/test/pcre_sets2.lua b/test/pcre_sets2.lua index 8bdb3a3..92d0a44 100755 --- a/test/pcre_sets2.lua +++ b/test/pcre_sets2.lua @@ -10,12 +10,14 @@ local function get_gsub (lib) end local function set_f_gsub4 (lib, flg) + local pCSV = "(^[^,]*)|,([^,]*)" + local fCSV = function (a,b) return "["..(a or b).."]" end local set = { Name = "Function gsub, set4", Func = get_gsub (lib), --{ s, p, f, n, res1, res2, res3 }, { {"/* */ */", "%/%*(.*)%*%/", "#" }, {"#", 1, 1} }, - { {"a2c3", ".-", "#" }, {"#a#2#c#3#", 5, 5} }, -- test .- + { {"a2c3", ".-", "#" }, {"#########", 9, 9} }, -- test .- { {"/**/", "%/%*(.-)%*%/", "#" }, {"#", 1, 1} }, { {"/* */ */", "%/%*(.-)%*%/", "#" }, {"# */", 1, 1} }, { {"a2c3", "%d", "#" }, {"a#c#", 2, 2} }, -- test %d @@ -23,6 +25,11 @@ local function set_f_gsub4 (lib, flg) { {"a \t\nb", "%s", "#" }, {"a###b", 3, 3} }, -- test %s { {"a \t\nb", "%S", "#" }, {"# \t\n#", 2, 2} }, -- test %S { {"abcd", "\\b", "%1"}, {"abcd", 2, 2} }, + { {"", pCSV,fCSV}, {"[]", 1, 1} }, + { {"123", pCSV,fCSV}, {"[123]", 1, 1} }, + { {",", pCSV,fCSV}, {"[][]", 2, 2} }, + { {"123,,456", pCSV,fCSV}, {"[123][][456]", 3, 3}}, + { {",,123,456,,abc,789,", pCSV,fCSV}, {"[][][123][456][][abc][789][]", 8, 8}}, } -- convert patterns: lua -> pcre for _, test in ipairs (set) do diff --git a/test/runtest.lua b/test/runtest.lua index 25d414e..283b4df 100755 --- a/test/runtest.lua +++ b/test/runtest.lua @@ -31,8 +31,16 @@ local function test_library (libname, setfile, verbose) end local avail_tests = { - posix = { lib = "rex_posix", "common_sets", "posix_sets", }, - pcre = { lib = "rex_pcre", "common_sets", "pcre_sets", "pcre_sets2", }, + posix = { lib = "rex_posix", "common_sets", "posix_sets", }, + spencer = { lib = "rex_spencer", "common_sets", "posix_sets", "spencer_sets" }, + posix1 = { lib = "rex_spencer", "common_sets", "posix_sets", "spencer_sets" }, + tre = { lib = "rex_tre", "common_sets", "posix_sets", "spencer_sets" }, + lord = { lib = "rex_lord", "common_sets", "posix_sets" }, + maddock = { lib = "rex_maddock", "common_sets", "posix_sets", }, + pcreposix = { lib = "rex_pcreposix","common_sets", "posix_sets", }, + pcre = { lib = "rex_pcre", "common_sets", "pcre_sets", "pcre_sets2", }, + pcre_nr = { lib = "rex_pcre_nr", "common_sets", "pcre_sets", "pcre_sets2", }, + pcre45 = { lib = "rex_pcre45", "common_sets", "pcre_sets", "pcre_sets2", }, } do |