File: 20-testregexp.sql

package info (click to toggle)
sqlite3-pcre2 0.1.1~git20220105-e3e02a4a-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144 kB
  • sloc: sh: 193; ansic: 134; sql: 103; makefile: 58
file content (86 lines) | stat: -rw-r--r-- 2,852 bytes parent folder | download
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
DROP TABLE IF EXISTS testregexp;
CREATE TABLE testregexp (
    `id` INTEGER PRIMARY KEY,
    `pattern` TEXT NOT NULL,  -- SQL representation of the pattern
    `subject` TEXT NOT NULL,  -- SQL representation of the subject
    `match` TEXT,    -- SQL representation of the match value
    `failmessage` TEXT,  -- Pattern of the failmessage, when the match operation shall crash
    `description` TEXT,
    CONSTRAINT match_xor_failmessage CHECK (
        (`match` IS NULL AND `failmessage` IS NOT NULL)
        OR (`match` IS NOT NULL AND `failmessage` IS NULL)
    )
);


-- Insert testregexp for checking the match value based on the function input
INSERT INTO testregexp
(`pattern`, `subject`, `match`, `description`)
VALUES
    -- pattern      | `subject`     | match | `description`                    |
    ('''(?i)^A''',   '''asdf''',     1,      NULL),
    ('''(?i)^A''',   '''bsdf''',     0,      NULL),
    ('''^A''',       '''asdf''',     0,      NULL),
    ('NULL',         '''asdf''',     'NULL', 'NULL pattern shall return NULL'),
    ('''^A''',       'NULL',         'NULL', 'NULL subject shall return NULL'),
    ('''''',         '''asdf''',     1,      'Blank pattern shall match'),
    ('''^A''',       '''''',         0,      'Blank subject'),
    (
        '''B''',
        'x''00''||''B''',            1,      'NULL character in subject'),
    (
        'x''00''||''B''',
        '''a''||x''00''||''B''',     1,      'NULL character in pattern')
;


-- Insert testregexp for checking the error message when the function crash
INSERT INTO testregexp
(`pattern`, `subject`,
    `failmessage`,
    `description`
)
VALUES
    ('''^(A''',     '''asdf''',
        '%Cannot compile pattern % missing closing parenthesis%',
        'Non-compilable regexp'
    )
;


-- Write the testcase corresponding to the test data
DELETE FROM testcase WHERE src_table = 'testregexp';
INSERT INTO `testcase`
(`src_table`, `src_id`, `execute_sql`, `evaluate_sql`, `description`)
SELECT
    'testregexp' AS src_table,
    id AS src_id,
    (
        'SELECT '||`subject`||' REGEXP '||`pattern`||' AS `value`'
    ) AS `execute_sql`,
    (
        CASE WHEN `failmessage` IS NULL
        THEN
            '`report_value`'||' IS '||`match`
        ELSE '`stderr` LIKE '''  || REPLACE(`failmessage`, '%', '%%') || ''''
        END
    ) AS `evaluate_sql`,
    (
        CASE WHEN `failmessage` IS NULL
        THEN
            `pattern`
            || ' shall '
            || (CASE WHEN `match` THEN 'match' ELSE 'not match' END)
            || ' '
            || `match`
            || "."
        ELSE
            'The evaluation of `'
            || `subject` || ' REGEXP ' || `pattern`
            || '` shall crash with failmessage '
            || '''' || `failmessage` || ''''
            || '.'
        END
    ) AS `description`
FROM testregexp
;