aboutsummaryrefslogtreecommitdiff
path: root/tests/regex/testscript
blob: 137469d4815135142e7a1f0d8c8b7958de2854a7 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# file      : tests/regex/testscript
# license   : MIT; see accompanying LICENSE file

: replace-search
:
{
  $*      abcbd /b/x/ >axcxd : all
  $* -ffo abcbd /b/x/ >axcbd : first-only
  $* -fnc abcbd /b/x/ >xx    : no-copy

  : ecma-escape
  :
  {
    $* xay '/a/$b/'      >'x$by'  : none
    $* xay '/a/$/'       >'x$y'   : none-term
    $* xay '/a/$$/'      >'x$y'   : self
    $* xay '/a/b$&c/'    >'xbacy' : match
    $* xay '/a/b$`c/'    >'xbxcy' : match-precede
    $* xay "/a/b\\\$'c/" >'xbycy' : match-follow

    : capture
    :
    {
      $* abcdefghij '/(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)/$1$10/'  >aj : matched
      $* a          '/(a)|(b)/$1$2$3/'                        >a  : unmatched
    }
  }

  : perl-escape
  :
  {
    $* xay '/a/\b/' >'xby' : none
    $* xay '/a/\/'  >'xy'  : none-term
    $* xay '/a/\\/' >'x\y' : self

    : newline
    :
    $* xay '/a/\n/' >>EOO
      x
      y
      EOO

    : capture
    :
    {
      $* abcdefghij '/(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)/\1\10/'  >aa0 : matched
      $* a          '/(a)|(b)/\1\2\3/'                        >a   : unmatched
    }

    : upper
    :
    {
      $* xay '/a/\U/'        >xy   : none
      $* xay '/a/\Uvz/'      >xVZy : repl
      $* xay '/a/\Uv\Ez/'    >xVzy : end
      $* aa  '/a/v\Uz/'      >vZvZ : locality
      $* xay '/(a)/\U\1/'    >xAy  : capt
      $* x-y '/(a?)-/\U\1z/' >xZy  : capt-empty
      $* xay '/a/\uvz/'      >xVzy : once
    }

    : lower
    :
    $* xay '/a/\lVZ/' >xvZy
  }

  : empty-substring
  :
  : Note that the regex search-based replacement with the match_not_null flag
  : is broken for older versions of libstdc++ and libc++ (may ignore
  : match_not_null for the former and may hang for some string/pattern for the
  : latter).
  :
  if (($cxx.id != 'gcc'   || $cxx.version.major >= 7) && \
      ($cxx.id != 'clang' || $cxx.version.major >= 6))
  {
    $* '' '/.*/x/' >'x'      : empty
    $* a  '/a*/x/' >'x'      : match
    $* aa '/b*/x/'      == 1 : no-match
  }
}

: replace-match
:
{
  test.options += -m

  $* abc  '/a(b)c/x\1y/'  >xby : match
  $* abcd '/a(b)c/x\1yd/' == 1 : no-match

  : empty-substring
  :
  {
    $* '' '/.*/x/'          >'x' : empty
    $* a  '/a*/x/'          >'x' : match
    $* ab '/a(c*)(b)/\1\2/' >'b' : match-mid
  }
}

: invalid-regex-fmt
:
{
  test.arguments += '' # Note: we will fail before the matching.

  $* ''        2> 'no leading delimiter'           != 0 : no-leading-delim
  $* '/a'      2> 'no delimiter after regex'       != 0 : no-mid-delim
  $* '//'      2> 'empty regex'                    != 0 : no-regex
  $* '/a[b/c/' 2>~'/invalid regex.*/'              != 0 : regex
  $* '/a/b'    2> 'no delimiter after replacement' != 0 : no-trailing-delim
  $* '/a/b/s'  2> 'junk after trailing delimiter'  != 0 : junk
}