summaryrefslogtreecommitdiff
path: root/test/posix_sets.lua
blob: b50c6135b5d5899e8077f1e695cc79d7ed3f2dcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
-- See Copyright Notice in the file LICENSE

local luatest = require "luatest"
local N = luatest.NT

local function set_f_find (lib, flg)
return {
  Name = "Function find",
  Func = lib.find,
  --{subj,   patt,      st,cf,ef},           { results }
  { {"abcd", ".+",      5},                  { N }     }, -- failing st
  { {"abc",  "aBC",     N, flg.ICASE},       { 1,3 }   }, -- cf
  { {"abc",  "^abc"},                        { 1,3 }   }, -- anchor
  { {"^abc", "^abc",    N,N,flg.NOTBOL},     { N }     }, -- anchor + ef
}
end

local function set_f_match (lib, flg)
return {
  Name = "Function match",
  Func = lib.match,
  --{subj,   patt,      st,cf,ef},           { results }
  { {"abcd", ".+",      5},                  { N }    }, -- failing st
  { {"abc",  "aBC",     N, flg.ICASE},       {"abc" } }, -- cf
  { {"abc",  "^abc"},                        {"abc" } }, -- anchor
  { {"^abc", "^abc",    N,N,flg.NOTBOL},     { N }    }, -- anchor + ef
}
end

local function set_m_exec (lib, flg)
return {
  Name = "Method exec",
  Method = "exec",
--  {patt,cf},         {subj,st,ef}           { results }
  { {".+"},            {"abcd",5},            { N }    }, -- failing st
  { {"aBC",flg.ICASE}, {"abc"},               {1,3,{}} }, -- cf
  { {"^abc"},          {"abc"},               {1,3,{}} }, -- anchor
  { {"^abc"},          {"^abc",N,flg.NOTBOL}, { N }    }, -- anchor + ef
}
end

local function set_m_tfind (lib, flg)
return {
  Name = "Method tfind",
  Method = "tfind",
--  {patt,cf},         {subj,st,ef}           { results }
  { {".+"},            {"abcd",5},            { N }    }, -- failing st
  { {"aBC",flg.ICASE}, {"abc"},               {1,3,{}} }, -- cf
  { {"^abc"},          {"abc"},               {1,3,{}} }, -- anchor
  { {"^abc"},          {"abc",N,flg.NOTBOL},  { N }    }, -- anchor + ef
}
end

return function (libname)
  local lib = require (libname)
  local flags = lib.flags ()
  return {
    set_f_match  (lib, flags),
    set_f_find   (lib, flags),
    set_m_exec   (lib, flags),
    set_m_tfind  (lib, flags),
  }
end