diff options
author | Reuben Thomas <rrt@sc3d.org> | 2012-09-29 17:43:50 +0100 |
---|---|---|
committer | Reuben Thomas <rrt@sc3d.org> | 2012-09-29 17:43:50 +0100 |
commit | 2cdbe1c4460249a5d2d865d4406fc06a64dcd560 (patch) | |
tree | 03c7eb891b8c1f89c5aaf7f0d4ae8f6dec6d5cb9 /test | |
parent | b551acf755e894c9db15d17d24754793a5773612 (diff) | |
download | lrexlib-2cdbe1c4460249a5d2d865d4406fc06a64dcd560.tar.gz |
Add the ability to use raw memory blocks as subjects.
The implementation is in algo.h, in the new check_subject function.
Usage is documented in manual.txt.
Optional tests have been added, using alien buffers.
Diffstat (limited to 'test')
-rw-r--r-- | test/luatest.lua | 17 | ||||
-rw-r--r-- | test/onig_sets.lua | 8 | ||||
-rw-r--r-- | test/pcre_sets.lua | 8 | ||||
-rw-r--r-- | test/runtest.lua | 15 |
4 files changed, 40 insertions, 8 deletions
diff --git a/test/luatest.lua b/test/luatest.lua index 5ea7ba8..3949d90 100644 --- a/test/luatest.lua +++ b/test/luatest.lua @@ -73,6 +73,22 @@ local function test_function (test, func) if t[1] then table.remove (t, 1) res = t + if alien then + local subject = test[1][1] + local buf = alien.buffer (#subject) + if #subject > 0 then + alien.memmove (buf:topointer (), subject, #subject) + end + test[1][1] = buf + local t = packNT (pcall (func, unpackNT (test[1]))) + if t[1] then + table.remove (t, 1) + res = t + else + print "alien test failed" + res = t[2] --> error_message + end + end else res = t[2] --> error_message end @@ -87,6 +103,7 @@ end -- 3) test results table or error_message local function test_method (test, constructor, name) local res1, res2 + local subject = test[2][1] local ok, r = pcall (constructor, unpackNT (test[1])) if ok then local t = packNT (pcall (r[name], r, unpackNT (test[2]))) diff --git a/test/onig_sets.lua b/test/onig_sets.lua index 83555a6..dd226ec 100644 --- a/test/onig_sets.lua +++ b/test/onig_sets.lua @@ -14,14 +14,14 @@ end local function set_named_subpatterns (lib, flg) return { Name = "Named Subpatterns", - Func = function (methodname, subj, patt, name1, name2) + Func = function (subj, methodname, patt, name1, name2) local r = lib.new (patt) local _,_,caps = r[methodname] (r, subj) return norm(caps[name1]), norm(caps[name2]) end, - --{} - { {"tfind", "abcd", "(?<dog>.)b.(?<cat>d)", "dog", "cat"}, {"a","d"} }, - { {"exec", "abcd", "(?<dog>.)b.(?<cat>d)", "dog", "cat"}, {"a","d"} }, + --{} N.B. subject is always first element + { {"abcd", "tfind", "(?<dog>.)b.(?<cat>d)", "dog", "cat"}, {"a","d"} }, + { {"abcd", "exec", "(?<dog>.)b.(?<cat>d)", "dog", "cat"}, {"a","d"} }, } end diff --git a/test/pcre_sets.lua b/test/pcre_sets.lua index 9c19bbe..e2db7a9 100644 --- a/test/pcre_sets.lua +++ b/test/pcre_sets.lua @@ -14,14 +14,14 @@ end local function set_named_subpatterns (lib, flg) return { Name = "Named Subpatterns", - Func = function (methodname, subj, patt, name1, name2) + Func = function (subj, methodname, patt, name1, name2) local r = lib.new (patt) local _,_,caps = r[methodname] (r, subj) return norm(caps[name1]), norm(caps[name2]) end, - --{} - { {"tfind", "abcd", "(?P<dog>.)b.(?P<cat>d)", "dog", "cat"}, {"a","d"} }, - { {"exec", "abcd", "(?P<dog>.)b.(?P<cat>d)", "dog", "cat"}, {"a","d"} }, + --{} N.B. subject is always first element + { {"abcd", "tfind", "(?P<dog>.)b.(?P<cat>d)", "dog", "cat"}, {"a","d"} }, + { {"abcd", "exec", "(?P<dog>.)b.(?P<cat>d)", "dog", "cat"}, {"a","d"} }, } end diff --git a/test/runtest.lua b/test/runtest.lua index 3c79970..d0d1435 100644 --- a/test/runtest.lua +++ b/test/runtest.lua @@ -1,5 +1,12 @@ -- See Copyright Notice in the file LICENSE +-- See if we have alien, so we can do tests with buffer subjects +local ok +ok, alien = pcall (require, "alien") +if not ok then + io.stderr:write ("Warning: alien not found, so cannot run tests with buffer subjects\n") +end + do local path = "./?.lua;" if package.path:sub(1, #path) ~= path then @@ -16,6 +23,13 @@ local function test_library (libname, setfile, verbose) local lib = require (libname) local f = require (setfile) local sets = f (libname) + + local realalien = alien + if libname == "rex_posix" and not lib.flags ().STARTEND and alien then + alien = nil + io.stderr:write ("Cannot run posix tests with alien without REG_STARTEND\n") + end + local n = 0 -- number of failures for _, set in ipairs (sets) do if verbose then @@ -33,6 +47,7 @@ local function test_library (libname, setfile, verbose) if verbose then print "" end + alien = realalien return n end |