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
|
# This file describes the semantics for hard regex constants
# As much as possible it's executable code so that it can be used
# (or split into) test cases for development and regression testing.
function simple_tests( fbre, numresult, strresult)
{
# usable as case value
switch ("foobaaar") {
case @/fo+ba+r/:
print "switch-case: ok"
break
default:
print "switch-case: fail"
break
}
# usable with ~ and !~
if ("foobaaar" ~ @/fo+ba+r/)
print "match ~: ok"
else
print "match ~: fail"
if ("quasimoto" !~ @/fo+ba+r/)
print "match !~: ok"
else
print "match !~: fail"
# assign to variable, use in match
fbre = @/fo+ba+r/
if ("foobaaar" ~ fbre)
print "variable match ~: ok"
else
print "variable match ~: fail"
if ("quasimoto" !~ fbre)
print "variable match !~: ok"
else
print "variable match !~: fail"
# Use as numeric value, should be zero
numresult = fbre + 42
if (numresult == 42)
print "variable as numeric value: ok"
else
print "variable as numeric value: fail"
# Use as string value, should be string value of text
strresult = "<" fbre ">"
if (strresult == "<fo+ba+r>")
print "variable as string value: ok"
else
print "variable as string value: fail", strresult
# typeof should work
if (typeof(@/fo+ba+r/) == "regexp")
print "typeof constant: ok"
else
print "typeof constant: fail"
if (typeof(fbre) == "regexp")
print "typeof variable: ok"
else
print "typeof variable: fail"
# conversion to number, works. should it be fatal?
fbre++
if (fbre == 1)
print "conversion to number: ok"
else
print "conversion to number: fail"
if (typeof(fbre) == "scalar_n")
print "typeof variable after conversion: ok"
else
print "typeof variable after conversion: fail"
}
BEGIN {
simple_tests()
# use with match, constant
# use with match, variable
# use with sub, constant
# use with sub, variable
# use with gsub, constant
# use with gsub, variable
# use with gensub, constant
# use with gensub, variable
# use with split, constant
# use with split, variable
# use with patsplit, constant
# use with patsplit, variable
# indirect call tests...
}
|